By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Regression is a statistical method that models the relationship between a dependent (target) variable and one or more independent (predictor) variables. You’d use it today to predict continuous outcomes—like sales, house prices, or temperature—based on historical data.
Regression powers decisions in business, finance, healthcare, and engineering. It answers questions like: - How will ad spend affect revenue? - What’s the fair price for a used car? - How does education level correlate with salary?
Without regression, you’d rely on guesswork or gut feelings instead of data-driven insights.
price = 50 * sq_ft + 20000
50
sq_ft
R² = 0.8
Regression assumes: - Linearity: The relationship between X and Y is roughly linear.- Independence: Residuals aren’t correlated (e.g., no time-series patterns).- Homoscedasticity: Residuals have constant variance across X values.- Normality: Residuals are normally distributed (for small samples).
[(sq_ft, price), ...]
Simple diagram description:
Y (Price) | | * | * * | * * | * * +---------------- X (Sq. Ft)
The line of best fit runs through the "center" of the points, minimizing vertical distances (residuals).
pandas
scikit-learn
matplotlib
Goal: Predict house prices using square footage.
import pandas as pd data = pd.read_csv("houses.csv") # Columns: "sq_ft", "price" X = data[["sq_ft"]] # Independent variable y = data["price"] # Dependent variable
from sklearn.linear_model import LinearRegression model = LinearRegression() model.fit(X, y)
print(f"Slope (coefficient): {model.coef_[0]}") print(f"Intercept: {model.intercept_}") # Example output: "price = 120 * sq_ft + 50000"
new_house = [[1500]] # 1500 sq. ft predicted_price = model.predict(new_house) print(f"Predicted price: ${predicted_price[0]:,.2f}")
from sklearn.metrics import r2_score y_pred = model.predict(X) print(f"R-squared: {r2_score(y, y_pred):.2f}")
Expected Outcome:- A working model that predicts prices from square footage.- Coefficients you can explain to stakeholders (e.g., "Each extra sq. ft adds $120 to the price").- An R² score to gauge model quality.
You train a linear regression model to predict house prices using square footage. The coefficient for sq_ft is 150. What does this mean?A) A 1 sq. ft increase in house size predicts a $150 increase in price.B) The average house price is $150 per sq. ft.C) The model explains 150% of the price variation.D) The intercept of the model is 150.
Correct Answer: A Explanation: The coefficient represents the slope of the line. A value of 150 means each additional sq. ft is associated with a $150 increase in price, holding other factors constant.Why the Distractors Are Tempting:- B: Confuses coefficient with average price.- C: R² (not coefficients) measures explained variation.- D: The intercept is a separate term.
Your regression model has an R² of 0.95. What should you do next?A) Deploy the model immediately—it’s highly accurate.B) Check for overfitting by testing on unseen data.C) Add more variables to increase R² further.D) Assume the model is valid because R² is high.
Correct Answer: B Explanation: A high R² on training data may indicate overfitting. Always validate on a holdout set.Why the Distractors Are Tempting:- A: High R² can be misleading (e.g., overfitting).- C: Adding variables can inflate R² without improving predictions.- D: R² alone doesn’t validate assumptions (e.g., linearity).
You’re predicting employee salaries using years of experience. The residual plot shows a U-shaped pattern. What’s the issue?A) The model is overfitted.B) The relationship between experience and salary is nonlinear.C) There are outliers in the data.D) The residuals are normally distributed.
Correct Answer: B Explanation: A U-shaped residual plot suggests the linear model misses a curved relationship (e.g., salaries rise quickly early in careers, then plateau).Why the Distractors Are Tempting:- A: Overfitting would show random residuals, not a pattern.- C: Outliers would appear as isolated points, not a U-shape.- D: Normal residuals would be randomly scattered.
sklearn.datasets.load_diabetes()
Visualize relationships with scatter plots.
Intermediate:
Learn regularization (Ridge/Lasso) to prevent overfitting.
Advanced:
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.