0
0
ML Pythonprogramming~10 mins

Cross-validation (K-fold) in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the KFold class from scikit-learn.

ML Python
from sklearn.model_selection import [1]
Drag options to blanks, or click blank then click option'
AKFold
Btrain_test_split
Ccross_val_score
DGridSearchCV
Attempts:
3 left
2fill in blank
medium

Complete the code to create a KFold object with 5 splits.

ML Python
kf = KFold(n_splits=[1])
Drag options to blanks, or click blank then click option'
A3
B5
C10
D1
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly split data using KFold.

ML Python
for train_index, test_index in kf.[1](X):
    X_train, X_test = X[train_index], X[test_index]
Drag options to blanks, or click blank then click option'
Atransform
Bfit
Cfit_transform
Dsplit
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a dictionary of train and test indices for each fold.

ML Python
folds = {i: {'train': train_idx, 'test': test_idx} for i, (train_idx, [1]) in enumerate(kf.[2](X))}
Drag options to blanks, or click blank then click option'
Atest_idx
Btrain_idx
Csplit
Dfit
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to perform K-fold cross-validation scoring with accuracy metric.

ML Python
scores = cross_val_score([1], X, y, cv=[2], scoring=[3])
Drag options to blanks, or click blank then click option'
Amodel
Bkf
C'accuracy'
D'neg_mean_squared_error'
Attempts:
3 left