Complete the code to import the SMOTE class from the imblearn library.
from imblearn.[1] import SMOTE
The SMOTE class is located in the over_sampling module of the imblearn library. This module contains techniques to increase minority class samples.
Complete the code to create a SMOTE object with a random state for reproducibility.
smote = SMOTE(random_state=[1])Setting random_state=42 ensures the SMOTE sampling is reproducible. The value 42 is commonly used as a fixed seed.
Fix the error in the code to fit and resample the training data using SMOTE.
X_resampled, y_resampled = smote.[1](X_train, y_train)The fit_transform method fits the SMOTE model and returns the resampled data. Using only fit does not return the resampled data.
Fill both blanks to create a logistic regression model with balanced class weights and fit it on training data.
model = LogisticRegression(class_weight=[1]) model.[2](X_train, y_train)
Setting class_weight='balanced' tells the model to adjust weights inversely proportional to class frequencies. Then fit trains the model on data.
Fill all three blanks to compute class weights manually and train a logistic regression model with them.
from sklearn.utils.class_weight import compute_class_weight weights = compute_class_weight(class_weight=[1], classes=[2], y=[3]) class_weights = dict(zip([2], weights)) model = LogisticRegression(class_weight=class_weights) model.fit(X_train, y_train)
To compute class weights manually, use class_weight='balanced', pass the unique classes from training labels, and the training labels themselves. Then create a dictionary for the model.