Understand the idea
Width increases representational capacity. Alpha controls weight regularisation. Use controlled training/validation evidence to reason about both; production’s small width grid does not explore every possible network.
What the syntax does
hidden_layer_sizes=(16, 8)- Requests two hidden layers, with 16 units and then 8 units.
hidden_layer_sizes:(24,),(16, 8)
alpha=0.01- Sets the L2 weight penalty; its useful value needs validation evidence.
alpha:0.0001,0.01
model.set_params- Changes estimator settings.
- Refit before evaluating the changed model.
Outputs you create
layers- Requested result described in the task and deliverables.
alpha- Requested result described in the task and deliverables.
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 a network with one 24-unit hidden layer and
alpha=0.0001. - Change its hidden
layersto (16, 8) andalphato 0.01. - Store the resulting settings in
layersandalpha.
layersalphaHints
Think: Use set_params(), tuples and a float to describe capacity and regularisation before fitting.
Tools: Use hidden_layer_sizes=(16, 8), alpha=0.01, model.set_params. Read the visible syntax meanings before editing.
Approach: Create a network with one 24-unit hidden layer and alpha=0.0001. Change its hidden layers to (16, 8) and alpha to 0.01. Store the resulting settings in layers and alpha. 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,), alpha=0.0001, random_state=42)
model.set_params(hidden_layer_sizes=(16, 8), alpha=0.01)
layers = model.hidden_layer_sizes
alpha = model.alpha
The new tuple changes the network capacity and alpha changes the penalty on large weights. These are candidate settings, not automatic improvements. Compare candidates on the same training folds and consider convergence and cost.