Understand the idea
Training adjusts weights to reduce an objective. Comparable feature scales help optimisation. Different initialisations can produce different learning trajectories. Training loss is not validation performance.
Python skill: Turn loss_curve_ into an indexed Series to inspect how optimisation changed training loss.
Meet the syntax
network.loss_curve_
pd.Series(network.loss_curve_, name='training_loss')network.loss_curve_- The training objective after each optimisation iteration; these values are not final-test errors.
pd.Series(network.loss_curve_, name='training_loss')- Labels the recorded sequence so its meaning is clear in the output.
Follow the code
Use the numbered comments to connect each Python block to the workflow above.
answer = pd.Series(network.loss_curve_, name='training_loss')
answer.index = answer.index + 1
answer.index.name = 'iteration'
This practice: Read and run the Python. Next: Change · Learning weights by reducing loss.
Given data · CLASS180
180 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| 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 |
Column meanings and units
Column names describe the supplied features and target. Keep the stated units and row identities when making comparisons.
Synthetic data are deliberately small and reproducible. Their patterns illustrate an idea; they are not evidence about a real population.
| Column | Stored type |
|---|---|
| length | float64 |
| width | float64 |
| label | str |
Supplied setup · available if you need to inspect it
This code runs before your editor on every Run. These are the objects your exercise uses.
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split
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 = Pipeline([('scale', StandardScaler()), ('model', MLPClassifier(hidden_layer_sizes=(8,), max_iter=150, early_stopping=True, random_state=42))])
model.fit(X_train, y_train)
network = model.named_steps['model']
Your task · Follow
Convert the fitted network’s loss history to a Series named answer, with its index called iteration.
Hint 1 — Think
Turn loss_curve_ into an indexed Series to inspect how optimisation changed training loss.
Hint 2 — Tools
Use network.loss_curve_, pd.Series(network.loss_curve_, name='training_loss'). Read the visible syntax meanings before editing.
Hint 3 — Approach
Convert the fitted network’s loss history to a Series named answer, with its index called iteration. Keep the supplied row order and inspect the named output after running.
Explained solution
answer = pd.Series(network.loss_curve_, name='training_loss')
answer.index = answer.index + 1
answer.index.name = 'iteration'
Each loss value describes the training objective at one iteration. Reducing this objective guides weight updates. Falling training loss does not prove good predictions on new rows; validation evidence answers that separate question.
Helpful prior knowledge: From inputs to network outputs These links are guidance, not locks.
Sources and API context
Examples run with this Playground’s scikit-learn 1.4.2 / Pyodide 0.26.4 runtime.