Multiple Linear Regression
Multiple Linear Regression extends simple linear regression to use two or more input features together to predict a single target variable - reflecting the fact that most real-world outcomes depend on several factors, not just one.
The Equation
y = b0 + b1*x1 + b2*x2 + ... + bn*xn
# y = predicted target
# x1, x2, ... xn = input features
# b1, b2, ... bn = coefficients for each feature
# b0 = intercept
Implementing in Python
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
df = pd.DataFrame({
"HoursStudied": [1, 2, 3, 4, 5, 6, 7, 8],
"AttendancePercent": [60, 65, 70, 75, 80, 85, 90, 95],
"Score": [35, 45, 50, 60, 65, 75, 80, 90]
})
X = df[["HoursStudied", "AttendancePercent"]]
y = df["Score"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
model = LinearRegression()
model.fit(X_train, y_train)
print("Coefficients:", model.coef_)
print("Intercept:", model.intercept_)
Interpreting Multiple Coefficients
Each coefficient represents the effect of that feature on the target, holding all other features constant - for example, the coefficient for AttendancePercent shows the score change per 1% increase in attendance, assuming hours studied stays fixed.
Multicollinearity
A key challenge in multiple regression is when input features are strongly correlated with each other, making it hard to isolate each one's individual effect on the target.
Coming Up Next
Next, you'll look at where Linear Regression is actually used across different industries.