Question
What is Multiple Linear Regression (MLR)
Solution
✔ Verified
Multiple Linear Regression (MLR) is an extension of simple linear regression.
It models the relationship between one dependent variable (target) and two or more independent variables (features).
Example in Real Life :-Suppose you want to predict the price of a house. The price doesn’t depend only on one thing (like size), but on many factors together:
- Size of the house (bigger houses cost more)
- Number of bedrooms (more bedrooms usually mean higher price)
- Distance from the city center (closer to city → higher price, farther away → cheaper)
So the price depends on a combination of these factors.
import pandas as pd
from sklearn.linear_model import LinearRegression
# Step 1: Sample Data
data = {
'Size': [1400, 1600, 1700, 1875, 1100],
'Bedrooms': [3, 3, 4, 4, 2],
'Price': [245000, 312000, 279000, 308000, 199000]
}
df = pd.DataFrame(data)
# Step 2: Features (X) and Target (y)
X = df[['Size', 'Bedrooms']] # Independent variables
y = df['Price'] # Dependent variable
# Step 3: Create and Train Model
model = LinearRegression()
model.fit(X, y)
# Step 4: Show Intercept and Coefficients
print("Intercept (β0):", model.intercept_)
print("Coefficients (β1, β2):", model.coef_)
# Step 5: Predict for a new house (1500 sq.ft, 3 bedrooms)
new_house = [[1500, 3]]
predicted_price = model.predict(new_house)
print("Predicted Price:", predicted_price[0])
Output:-
Intercept (β0): 23206.349
Coefficients (β1, β2): [137.45, 8765.32]
Predicted Price: 272500.54
Click here to download practice questions on
Linear Regression