Class imbalance ঘটে যখন classification problem-এর একটি class অন্য class-এর তুলনায় অনেক বেশি frequent।

উদাহরণ:

Normal Transaction = 99.8%
Fraud              = 0.2%

বা:

Not Churned = 95%
Churned     = 5%

কেন Problem?

Model training-এর সময় majority class dominate করতে পারে।

Fraud example:

100,000 transactions

99,800 Normal
200 Fraud

Model যদি majority pattern শেখে এবং প্রায় সবকিছু Normal predict করে, তাহলে accuracy খুব high হবে।

কিন্তু:

Fraud detection

fail করবে।

তাই শুধু Accuracy নয়

Useful metrics হতে পারে:

Precision
Recall
F1 Score
PR-AUC
ROC-AUC
Recall at Fixed Precision
Precision at Fixed Recall

কোন metric important সেটা business cost-এর উপর depend করে।

Precision vs Recall

Fraud detection example:

High Recall:

Most fraud detected

কিন্তু অনেক legitimate transaction-ও fraud flag হতে পারে।

High Precision:

Fraud flag করলে mostly সত্যিই fraud

কিন্তু কিছু fraud miss হতে পারে।

তাই trade-off আছে।

Business Cost

সব prediction mistake equally costly নয়।

Fraud miss করলে:

False Negative
→ Financial Loss

Legitimate customer-কে fraud বললে:

False Positive
→ Good Customer Blocked
→ Bad User Experience

তাই threshold business cost অনুযায়ী select করতে হবে।

Class Weights

Minority class-এর mistakes-কে বেশি penalty দেওয়া যায়।

উদাহরণ:

Normal mistake → Weight 1
Fraud mistake  → Weight 10

এতে model fraud class-এর প্রতি বেশি attention দিতে পারে।

Under-sampling

Majority class-এর কিছু observations remove করা হয়।

99,800 Normal
200 Fraud

↓

2,000 Normal
200 Fraud

Benefit:

Training faster
Class imbalance কম

Problem:

Useful majority information হারাতে পারি

Over-sampling

Minority examples বেশি sample করা হয়।

200 Fraud
↓
Repeated / Resampled
↓
2,000 Fraud

Benefit:

Minority signal stronger

Problem:

Overfitting risk

বিশেষ করে একই examples repeatedly copy করলে।

SMOTE

SMOTE-এর full form:

Synthetic Minority Over-sampling Technique

এটি শুধু minority observations duplicate না করে nearby minority points-এর মধ্যে synthetic examples তৈরি করে।

তবে blindly SMOTE ব্যবহার করা উচিত নয়।

বিশেষ করে:

temporal data unusual feature space categorical-heavy data fraud-like anomalies

এতে synthetic samples unrealistic হতে পারে।

Threshold Tuning

Default:

Probability > 0.50
→ Positive

সব problem-এর জন্য best threshold নয়।

Fraud detection-এ হয়তো:

Threshold = 0.20

ব্যবহার করলে বেশি fraud detect হবে।

কিন্তু false positives-ও বাড়বে।

তাই threshold tune করা হয় desired:

Precision
Recall
Business Cost

এর ভিত্তিতে।

Anomaly Detection

যখন positive cases extremely rare এবং fundamentally unusual pattern represent করে, তখন supervised classification-এর পাশাপাশি anomaly detection approach consider করা যেতে পারে।

উদাহরণ:

Rare fraud
Equipment failure
Network intrusion

Important Rule

Imbalanced dataset দেখলেই automatically resampling করতে হবে—এমন নয়।

Strong models অনেক সময়:

Class Weight
+
Correct Metric
+
Threshold Tuning
+
Better Features

দিয়েই ভালো result দিতে পারে।

Interview-ready Explanation

Class imbalance occurs when one class is much rarer than
another.

In this situation, accuracy can be misleading because a
model may achieve high accuracy simply by predicting the
majority class.

Useful approaches include choosing appropriate metrics,
using class weights, under-sampling, over-sampling,
SMOTE where appropriate, better feature engineering,
and threshold tuning.

The decision threshold should be chosen based on the
business cost of false positives and false negatives,
rather than automatically using 0.5.