Menu

Regression and Classification

Lesson 2: Regression and Classification

What is regression?

Regression predicts a numeric outcome.

Example target

Possible features

House priceSize, location, age, number of rooms
Delivery timeDistance, time of day, weather, courier
Monthly revenueAd spend, season, price, promotions

Common algorithms: linear regression, decision tree regressor, random forest, gradient boosting (e.g., XGBoost, LightGBM).

What is classification?

Classification predicts a category.

Example target

Classes

Customer churnWill churn / Won't churn
Fraud detectionFraud / Legitimate
Email filteringSpam / Not spam
Lead scoringHot / Warm / Cold
  • Many models output a probability (e.g., 0.73 chance of churn).
  • A threshold converts it into a class (e.g., ≥ 0.5 → "churn").
  • Choose the threshold based on business costs, not just the default 0.5.

Common algorithms: logistic regression, decision trees, random forest, gradient boosting.

Example

Question

Task type

Target

How much will we sell next month?RegressionSales amount (₹)
Will this subscriber renew?ClassificationRenew: yes/no
How many minutes will this delivery take?RegressionMinutes
Is this transaction fraudulent?ClassificationFraud: yes/no

The data, target definition, evaluation metrics, and business costs differ between the two.

How it works

Step

Action

1Define the target and confirm it's measured correctly
2Choose features that would be available at prediction time
3Split data into training and test sets (e.g., 80/20; time-based for temporal data)
4Fit preprocessing (scaling, encoding) on training data only
5Train the model on training data
6Evaluate on the held-out test data
7Compare against a baseline
8Interpret and communicate results with uncertainty
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
X = df[['tenure', 'monthly_charges', 'support_tickets']]
y = df['churned']
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y
)
model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)
print(model.score(X_test, y_test)) # accuracy on unseen data

Common mistakes

  • Treating model output as a decision: a prediction informs a decision; it doesn't make one.
  • Wrong target definition: e.g., "churn" defined inconsistently.
  • Unrepresentative data: training data that doesn't reflect future cases.
  • Ignoring costs: a false positive and a false negative usually have different costs.

Error

Churn example

Cost

False positivePredict churn; customer would have stayedUnnecessary discount
False negativePredict stay; customer actually leavesLost customer

Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details