Linear Regression
Part of the Data Science Roadmap
In short
Linear regression is the first model to try for predicting a number. It's fast, easy to explain, and a strong baseline that fancier models must beat to earn their place.
Predicting a continuous number as a weighted sum of input features — simple, interpretable, and still a strong baseline model before reaching for anything more complex.

Think of it like this
Guessing the electricity bill
Your bill goes up with AC hours, the number of people at home and the size of the flat. Linear regression learns how many rupees each one adds, plus a fixed base charge, from past months' bills.
Watch it happen
Building a bill predictor
1/5Past months: AC hours, people, flat size and the bill in rupees.
The big ideas
What you need to know
Prediction is a weighted sum
bill = base + w1 × AC hours + w2 × people + w3 × size. Each weight is readable.
Coefficients explain
A weight is the change in the prediction for one more unit of that feature, others held fixed.
MAE and R²
MAE is the average miss in real units, like rupees. R² is the share of variation explained.
Regularised versions
Ridge and Lasso shrink weights to reduce overfitting. Lasso can push useless features to zero.
See it in code
Walk through the code
1import pandas as pd2from sklearn.model_selection import train_test_split3from sklearn.linear_model import LinearRegression4from sklearn.metrics import mean_absolute_error, r2_score5 6df = pd.read_csv("electricity.csv") # ac_hours, people, sqft, bill7X, y = df[["ac_hours", "people", "sqft"]], df["bill"]8X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, random_state=0)9 10model = LinearRegression().fit(X_tr, y_tr)11print(dict(zip(X.columns, model.coef_.round(1))), round(model.intercept_, 1))12 13pred = model.predict(X_te)14print(mean_absolute_error(y_te, pred), r2_score(y_te, pred))1/3Pick three features and the target, then hold out 20% for testing.
Fit, read the weights, then judge on unseen months. MAE in rupees is easy to explain to anyone.
Save yourself the pain
Common mistakes
Oops
Comparing raw coefficients of features on different scales.
Do this instead
Standardise features first if you want to compare which one matters more.
Oops
Using linear regression on a clearly curved relationship as-is.
Do this instead
Plot residuals. If they curve, add features like squares or logs, or try a tree model.
Your mission
Predict a real number
Quick check
A coefficient for 'people' is 350. What does it mean?
Go deeper
- 1Fit a linear regression model in scikit-learn on a real dataset.
- 2Learn to interpret each coefficient in plain business language.
- 3Check the model's assumptions (linearity, residual patterns) rather than trusting it blindly.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.