Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Supervised Workflow lessonsQUESTIONS · MODELS · EVIDENCE
Validate and compare · ML-W10 · 12–18 MIN

Settings, learned values and fit quality

Separate hyperparameters, learned parameters and generalisation evidence.

Exercises within this concept

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeReason about the Python
  3. TransferExplain the Python result

Understand the idea

Settings control fitting; learned parameters are estimated from examples. Supplied curves illustrate underfitting and overfitting without requiring an untaught model family.

Separate hyperparameters, learned parameters and generalisation evidence.Before fit: settingsAfter fit: learned valuesget_params()coef_, intercept_Choose settings; fitting estimates parameters from data.
Schematic · Separate hyperparameters, learned parameters and generalisation evidence.Scroll the diagram horizontally if needed.

Python skill: Read a dictionary setting with get_params() and a learned attribute with a trailing underscore.

Meet the syntax

model.get_params()
['fit_intercept']
model.coef_[0]
model.get_params()
Returns constructor settings chosen before fitting; these are not learned coefficients.
['fit_intercept']
Looks up the named setting in that dictionary.
model.coef_[0]
Reads the first learned coefficient. The trailing underscore identifies fitted state.

Follow the code

Use the numbered comments to connect each Python block to the workflow above.

fit_intercept = model.get_params()['fit_intercept']
distance_coefficient = float(model.coef_[0])

This practice: Read and run the Python. Next: Change · Settings, learned values and fit quality.

Given data · LINE24

24 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.

LINE24 · first 8 prepared 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

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.

Input schema
ColumnStored type
distancefloat64
durationfloat64
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.linear_model import LinearRegression
model = LinearRegression().fit(df[['distance']], df['duration'])

Your task · Follow

From the supplied fitted line, store the fit_intercept setting in fit_intercept and the learned distance coefficient in distance_coefficient.

Hint 1 — Think

Read a dictionary setting with get_params() and a learned attribute with a trailing underscore.

Hint 2 — Tools

Use model.get_params(), ['fit_intercept'], model.coef_[0]. Read the visible syntax meanings before editing.

Hint 3 — Approach

From the supplied fitted line, store the fit_intercept setting in fit_intercept and the learned distance coefficient in distance_coefficient. Keep the supplied row order and inspect the named output after running.

Explained solution
fit_intercept = model.get_params()['fit_intercept']
distance_coefficient = float(model.coef_[0])

fit_intercept is a setting, while coef_ is estimated from training examples. Choosing a setting, learning coefficients and evaluating fit quality are separate actions. A fitted attribute proves a fit happened, not that predictions generalise.

Helpful prior knowledge: Read cross-validation evidence 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.

Your task · Follow

From the supplied fitted line, store the fit_intercept setting in fit_intercept and the learned distance coefficient in distance_coefficient.

fit_interceptdistance_coefficient

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.