Ravindra BagaleCourses & study guides मराठी Track your progress

33. Linear Regression in Python with sklearn

33.1 Why Predict a Number (Regression)

Why. Many India business questions are numbers: rent in ₹, daily pedha sales, delivery minutes. Classification says yes/no. Regression predicts a number.

What. Linear regression draws a straight-line style relationship: “as flat size goes up, rent tends to go up.” sklearn’s LinearRegression finds the best-fitting line (or plane) from your training rows.

How.

Spot a regression question

  1. Ask: “Is the answer a number I care about in ₹ / kg / minutes?”
  2. If yes → regression (this chapter). If yes/no or category → Chapter 34.
  3. Write one sentence: “I will predict ___ from ___.” Example: predict monthly rent from area_sqft and city tier (fictional Pune flats).

Worked example — fictional rent rows.

import pandas as pd

rent = pd.DataFrame({
 "area_sqft": [450, 600, 750, 900, 1100],
 "rent_inr": [12000, 15500, 19000, 22500, 27000],
})
print(rent)
print("Target y = rent_inr (a number). Feature X = area_sqft.")

What you should see. A tiny table where larger flats tend to cost more. Linear regression will learn that slope from data — not from a hand-typed formula.

Fictional data

Rents and flat sizes are teaching samples only, not real listings.

Ravindra Bagale's Tip

Regression = number. Classification = class. Interview madhe he ek line clear asa.