Complete the code to import the class used for oversampling minority classes.
from imblearn.over_sampling import [1]
The SMOTE class is commonly used to oversample minority classes in imbalanced datasets.
Complete the code to convert text data into numerical features using TF-IDF.
from sklearn.feature_extraction.text import [1] tfidf = [1](stop_words='english') X = tfidf.fit_transform(texts)
TfidfVectorizer converts text into numerical features by calculating term frequency-inverse document frequency.
Fix the error in applying SMOTE to the feature matrix X and labels y.
smote = SMOTE(random_state=42) X_resampled, y_resampled = smote.fit_resample([1], y)
The fit_resample method takes the feature matrix X and labels y. Passing y as the first argument is incorrect.
Fill both blanks to create a balanced dataset using RandomOverSampler and convert text to features.
from imblearn.over_sampling import [1] from sklearn.feature_extraction.text import [2] ros = [1](random_state=0) tfidf = [2](stop_words='english') X = tfidf.fit_transform(texts) X_resampled, y_resampled = ros.fit_resample(X, y)
RandomOverSampler is used to oversample minority classes. TfidfVectorizer converts text to numerical features.
Fill all three blanks to create a pipeline that balances data and trains a logistic regression model.
from imblearn.pipeline import Pipeline from sklearn.linear_model import [1] from imblearn.over_sampling import [2] from sklearn.feature_extraction.text import [3] pipeline = Pipeline([ ('vectorizer', [3](stop_words='english')), ('oversample', [2](random_state=42)), ('classifier', [1]()) ])
This pipeline vectorizes text with TfidfVectorizer, balances classes with RandomOverSampler, and trains a LogisticRegression model.