Complete the code to import the StratifiedKFold class from scikit-learn.
from sklearn.model_selection import [1]
The StratifiedKFold class is imported from sklearn.model_selection to perform stratified k-fold cross-validation.
Complete the code to create a StratifiedKFold object with 5 splits.
skf = StratifiedKFold(n_splits=[1], shuffle=True, random_state=42)
Setting n_splits=5 creates 5 stratified folds for cross-validation.
Fix the error in the loop to correctly split data using StratifiedKFold.
for train_index, test_index in skf.[1](X, y): X_train, X_test = X[train_index], X[test_index] y_train, y_test = y[train_index], y[test_index]
The split method generates indices for train and test sets in stratified folds.
Fill both blanks to create a dictionary comprehension that maps each fold number to the test indices.
folds = {i: test_index for i, (_, test_index) in enumerate(skf.[1](X, y), start=[2])}The split method is used to get indices, and enumerate starts counting folds from 1.
Fill all three blanks to create a loop that trains a model on each stratified fold and prints accuracy.
for train_idx, test_idx in skf.[1](X, y): model = LogisticRegression() model.[2](X[train_idx], y[train_idx]) preds = model.[3](X[test_idx]) acc = accuracy_score(y[test_idx], preds) print(f"Fold accuracy: {acc:.2f}")
Use split to get indices, fit to train the model, and predict to get predictions.
