4. Supervised ML: Regression, Classification & Ensembles
Sections 13-17: Linear/Ridge/Lasso, Logistic, KNN, SVM, Decision Trees, Random Forest, XGBoost & Evaluation Metrics
Module 1: Regression & Classification Algorithms
Continuous target forecasting and discrete category prediction models.
🇬🇧 English Definition
Linear Regression predicts continuous values (regularized with L1 Lasso or L2 Ridge). Logistic Regression models binary class probabilities. Decision Trees recursively partition feature spaces.
🇮🇳 Hinglish Definition
Linear Regression numeric values predict karta hai. Ridge (L2) aur Lasso (L1) overfitting rokne ke liye regularization penalties add karte hai. Logistic Regression classification baseline hai.
Core Concepts & Principles
- Ridge vs Lasso: Ridge (L2) shrinks coefficients; Lasso (L1) can force small feature coefficients exactly to 0 for feature selection.
- Support Vector Machines (SVM): Finds maximum-margin decision boundary using kernel tricks for non-linear boundaries.
🔍 Line-by-Line Code Breakdown
- Line 1-2: Import Ridge regression and LogisticRegression models.
- Line 3-4: Fit LogisticRegression model on training data with max_iter=1000.
🎯 Interview Focus & Questions
- Q: L1 vs L2 Regularization?
A: L1 (Lasso) adds absolute penalty creating sparse models; L2 (Ridge) adds squared penalty shrinking weights.
from sklearn.linear_model import Ridge, LogisticRegression
model_reg = Ridge(alpha=1.0)
model_clf = LogisticRegression(max_iter=1000)
print("Regression and Classification Models Initialized.")
Module 2: Ensemble Learning (Random Forest, XGBoost) & Metrics
Bagging, Boosting, and comprehensive evaluation metrics (MAE, RMSE, R², Precision, Recall, F1, ROC-AUC).
🇬🇧 English Definition
Ensembles combine weak learners. Random Forest uses bagging (bootstrap aggregation). Gradient Boosting (XGBoost, LightGBM, CatBoost) builds sequential trees correcting previous errors.
🇮🇳 Hinglish Definition
Random Forest multiple trees ki voting/average leta hai. Gradient Boosting (XGBoost) errors ko sequentially learn karke improve karta hai. Imbalanced data me accuracy ke bajaye Precision/Recall/F1-Score dekhe.
Core Concepts & Principles
- Bagging vs Boosting: Bagging builds independent parallel trees; Boosting builds sequential dependent trees.
- Classification Metrics: Accuracy = correct/all; Precision = TP/(TP+FP); Recall = TP/(TP+FN); F1 = Harmonic Mean.
- Regression Metrics: MAE (mean absolute error), RMSE (root mean squared error), R² (explained variance).
🔍 Line-by-Line Code Breakdown
- Line 1-2: Import RandomForestClassifier and XGBClassifier ensembles.
- Line 3-4: Import evaluation metrics classification_report and mean_squared_error.
🎯 Interview Focus & Questions
- Q: Random Forest vs Gradient Boosting?
A: Random Forest averages independent randomized decision trees; Boosting builds trees sequentially correcting prior residual errors.
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.metrics import classification_report
print("Ensemble Models & Evaluation Metrics Suite Configured.")