Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Neural Networks lessons
Shared network concepts · ML-N01 · 12–18 MIN

From inputs to network outputs

Understand layers, units and task-shaped outputs.

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeCompute and inspect the evidence
  3. TransferCompute and inspect the evidence

Understand the idea

A network combines weighted inputs, activations and learned layers. Hidden width counts units within a layer; a tuple describes successive hidden layers. Task-specific outputs come after the shared representation.

Understand layers, units and task-shaped outputs.InputsHidden unitsOutputs
Understand layers, units and task-shaped outputs.Scroll the diagram horizontally if needed.

What the syntax does

MLPClassifier(hidden_layer_sizes=(24,), max_iter=500, random_state=42)
  • Creates a neural network model.
  • random_state: 42, None
  • max_iter: 100, 500, 1000
  • hidden_layer_sizes: (24,), (16, 8)
  • The one-item tuple (24,) means one layer of 24 units; (16, 8) means two layers. max_iter caps optimisation. alpha is a nonnegative weight penalty; convergence and validation evidence both matter.
  • Classification and regression share architecture notation but use different outputs and metrics.
model.get_params()['hidden_layer_sizes']
  • Reads the architecture setting without fitting a network.
  • hidden_layer_sizes: (24,), (16, 8)

Outputs you create

answer
  1. The requested result, with the values, labels and row order described by this task.
LINE24 · first 8 rows
distanceduration
15.30501
1.4782611.2361
1.9565211.8488
2.4347814.809
2.9130410.7589
3.391319.4972
3.8695717.89
4.3478315.531
Your task
  1. Create an unfitted MLPClassifier named model with one hidden layer of 24 units.
  2. Store its hidden_layer_sizes setting in answer.
answer
Hints

Think: Use a one-item tuple and keyword arguments to describe a neural-network architecture.

Tools: Use (24,), MLPClassifier, model.get_params()['hidden_layer_sizes']. Read the visible syntax meanings before editing.

Approach: Create an unfitted MLPClassifier named model with one hidden layer of 24 units. Store its hidden_layer_sizes setting in answer. Keep the supplied row order and inspect the named output after running.

Explained solution
from sklearn.neural_network import MLPClassifier
model = MLPClassifier(hidden_layer_sizes=(24,), max_iter=500, random_state=42)
answer = model.get_params()['hidden_layer_sizes']

The tuple (24,) means one hidden layer, not 24 layers. Constructing the estimator does not train weights or produce predictions. Regression uses MLPRegressor but shares this architecture notation.

Ctrl/⌘+Enter: Run · Tab: indent · Esc then Tab: leave editor

Python loads when you run. Code and results stay in this activity only.

Run your code to inspect its output. Check uses that same run.