By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Supervised regression learns a mapping (f(\mathbf{x})) from input features (\mathbf{x}) to a continuous target (y) using labeled examples. It’s the workhorse when you need to predict a numeric quantity—e.g., estimating next‑month house prices from location, size, and age, or forecasting daily electricity demand from weather and calendar data. Because the target is continuous, the model’s error can be measured directly, making regression ideal for budgeting, capacity planning, and any “how much?” business question.
train_test_split(..., stratify=y)
python import pandas as pd df = pd.read_csv('house_prices.csv') df.head(); df.describe()
PolynomialFeatures
StandardScaler
python from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42)
python from sklearn.linear_model import LinearRegression lin = LinearRegression().fit(X_train, y_train)
python from sklearn.metrics import mean_squared_error, r2_score preds = lin.predict(X_test) mse = mean_squared_error(y_test, preds) rmse = mse0.5 r2 = r2_score(y_test, preds)
RidgeCV
LassoCV
ElasticNetCV
alpha
python from sklearn.linear_model import RidgeCV ridge = RidgeCV(alphas=[0.1, 1.0, 10.0], cv=5).fit(X_train, y_train)
scaler.fit(X_train)
scaler.transform
Scenario: Your model’s training RMSE is 5, but test RMSE is 20. Answer: The model is over‑fitting; increase regularization (e.g., raise λ in Ridge/Lasso) or reduce model complexity.
Scenario: You have 10,000 features but only 200 samples. Answer: Use Lasso (or Elastic Net) to enforce sparsity, or first perform dimensionality reduction (PCA) before regression.
Scenario: After adding a quadratic term, R² improves from 0.70 to 0.71, but RMSE barely changes. Answer: The extra term adds little predictive power; the small R² gain may be noise—prefer the simpler model to avoid unnecessary complexity.
Keep this guide handy; you now have the core theory, the practical workflow, and the interview‑ready nuggets to own any regression‑focused data‑science task. Happy modeling!
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.