Understand the idea
A convergence warning means the stopping criterion was not reached within the budget. Internal early stopping, outer CV and final test have separate roles. sklearn’s internal stopping score need not equal the outer selection metric. Production disables early stopping for chronological MLP regression.
Illustrative data
| Column | Values |
|---|---|
| Fit · same | (-1, -1); (-1.2, -0.8); (-0.8, -1.2); (1, 1); (1.2, 0.8); (0.8, 1.2) |
| Fit · opposite | (-1, 1); (-1.2, 0.8); (-0.8, 1.2); (1, -1); (1.2, -0.8); (0.8, -1.2) |
| Validation | (-0.9, -0.9); (0.9, 0.9); (-0.9, 0.9); (0.9, -0.9) · labels: same, same, opposite, opposite |
Click the highlighted code to change the result.
scaler = StandardScaler().fit(example_X_train)
example_network = MLPClassifier(hidden_layer_sizes=(8,), max_iter=, random_state=42)
example_network.fit(scaler.transform(example_X_train), example_y_train)
loss = example_network.loss_curve_
validation_predictions = example_network.predict(scaler.transform(example_X_validation))
validation_f1 = f1_score(example_y_validation, validation_predictions, average="macro")Budget 100: loss 0.539; validation macro F1 0.733.
What the syntax does
network.n_iter_- The number of iterations actually performed during this fit.
Supplied for this practice
These objects are prepared afresh before your editor runs.
X_train/X_test/y_train/y_test- Training feature rows from the declared split. Final-test feature rows from the declared split. Training targets, aligned with
X_train. Final-test targets, aligned withX_test.X_train, X_test, y_train, y_test = train_test_split(df[['length', 'width']], df['label'], test_size=0.2, random_state=42, stratify=df['label']) model- Already fitted on
X_train,y_train. Fitted estimator or pipeline for the requested model family. Fitted onX_train,y_train; reuse without refitting. network- Already fitted on
X_train,y_train. Supplied network; its definition below specifies the values and role. Fitted onX_train,y_train; reuse without refitting.
Outputs you create
iterations_used- Requested result described in the task and deliverables.
iteration_limit- Requested result described in the task and deliverables.
length | width | label |
|---|---|---|
| 236.033 | -0.805568 | A |
| 581.297 | 0.728558 | A |
| -1511.27 | -1.00866 | A |
| 99.0248 | -0.24496 | A |
| -13.0141 | -0.660765 | A |
| 681.179 | 0.602475 | A |
| 51.1472 | 0.873157 | A |
| 362.131 | -0.665605 | A |
- Store the fitted iteration count in
iterations_usedand the configured upper limit initeration_limit.
iterations_usediteration_limitHints
Think: Distinguish n_iter_ (observed iterations) from max_iter (the configured upper limit).
Tools: Use network.n_iter_, network.max_iter, network.early_stopping. Read the visible syntax meanings before editing.
Approach: Store the fitted iteration count in iterations_used and the configured upper limit in iteration_limit. Keep the supplied row order and inspect the named output after running.
Explained solution
iterations_used = network.n_iter_
iteration_limit = network.max_iter
Reaching the iteration limit calls for inspecting warnings and loss. Stopping earlier may reflect the stopping rule; it does not establish useful performance. Internal early stopping remains inside each training fit and cannot replace the outer validation comparison.