Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
2fill in blank
mediumComplete 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'
Attempts:
3 left
3fill in blank
hardFix 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'
Attempts:
3 left
4fill in blank
hardFill 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'
Attempts:
3 left
5fill in blank
hardFill 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'
Attempts:
3 left