bhylu.com

Advertisements

Multiple Regression

Multiple regression uses several input features to predict one numeric target. Each feature must represent information available when the prediction will be made.

Understand the idea

Feature columns need a stable order and compatible meaning across fit and predict. Correlated features can make individual coefficients unstable even when predictions seem reasonable. A coefficient is conditional on the other supplied features and is not automatically a causal effect. The constructed example only demonstrates a two-column API.

Where to try it

Run locally with scikit-learn and NumPy installed in your virtual environment (py -m pip install scikit-learn numpy). These examples are executed during course review, but the online runner does not currently preload scikit-learn. The small data is for learning the API, not evidence of production model quality.

A worked example

Python

from sklearn.linear_model import LinearRegression
X = [[1, 0], [0, 1], [1, 1], [2, 1], [1, 2]]
y = [3, 4, 6, 8, 9]
model = LinearRegression().fit(X, y)
print(model.predict([[2, 2]]).round(2).tolist())

Read the result

The prediction is approximately [11.0] for the synthetic rule 1 + 2x + 3z.

Try one change

Name both feature columns and add a validation check for the required number of features.

For package options, see the scikit-learn documentation.