Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Neural Networks lessonsQUESTIONS · MODELS · EVIDENCE
Shared network concepts · ML-N01 · 12–18 MIN

From inputs to network outputs

Understand layers, units and task-shaped outputs.

Exercises within this concept

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

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.

Understand layers, units and task-shaped outputs.InputsHidden unitsOutputs
Schematic · Understand layers, units and task-shaped outputs.Scroll the diagram horizontally if needed.

Python skill: Use a one-item tuple and keyword arguments to describe a neural-network architecture.

Meet the syntax

(24,)
MLPClassifier
model.get_params()['hidden_layer_sizes']
(24,)
A tuple with one item: one hidden layer containing 24 units. The comma makes it a tuple.
MLPClassifier
Constructs a classifier; weights are learned only when fit is called.
model.get_params()['hidden_layer_sizes']
Reads the architecture setting without fitting a network.

Follow the code

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

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']

This practice: Read and run the Python. Next: Change · From inputs to network outputs.

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

Your task · Follow

Create an unfitted network with one hidden layer of 24 units. Store the hidden_layer_sizes setting in answer.

Hint 1 — Think

Use a one-item tuple and keyword arguments to describe a neural-network architecture.

Hint 2 — Tools

Use (24,), MLPClassifier, model.get_params()['hidden_layer_sizes']. Read the visible syntax meanings before editing.

Hint 3 — Approach

Create an unfitted network with one hidden layer of 24 units. Store the 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.

Helpful prior knowledge: Supervised Workflow checkpoint 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

Create an unfitted network with one hidden layer of 24 units. Store the hidden_layer_sizes setting in answer.

answer

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.