5.3 Practical Exercises for Chapter 5
These exercises will help you practice handling imbalanced data with class weighting and SMOTE and using appropriate cross-validation methods. Each exercise includes a solution with code for guidance.
Exercise 1: Evaluating a Model with Class Weighting
Train a Logistic Regression model on an imbalanced dataset using class weighting to improve the model’s sensitivity to the minority class. Use Stratified K-Folds Cross-Validation to ensure balanced class representation across each fold.
Create an imbalanced dataset and split it into training and testing sets.
Apply class weighting to a Logistic Regression model.
Evaluate the model using Stratified K-Folds cross-validation.
from sklearn.datasets import make_classification ...