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.
What the syntax does
MLPClassifier(hidden_layer_sizes=(24,), max_iter=500, random_state=42)- Creates a neural network model.
random_state:42,Nonemax_iter:100,500,1000hidden_layer_sizes:(24,),(16, 8)
- The one-item tuple (24,) means one layer of 24 units; (16, 8) means two layers.
max_itercaps 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- The requested result, with the values, labels and row order described by this task.
distance | duration |
|---|---|
| 1 | 5.30501 |
| 1.47826 | 11.2361 |
| 1.95652 | 11.8488 |
| 2.43478 | 14.809 |
| 2.91304 | 10.7589 |
| 3.3913 | 19.4972 |
| 3.86957 | 17.89 |
| 4.34783 | 15.531 |
- Create an unfitted
MLPClassifiernamedmodelwith one hidden layer of 24 units. - Store its
hidden_layer_sizessetting inanswer.
answerHints
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.