Challenge - 5 Problems
Cross-validation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why use K-fold cross-validation?
Imagine you have a small dataset and want to estimate how well your machine learning model will perform on new data. Why is K-fold cross-validation a better choice than a single train-test split?
Attempts:
2 left
❓ Predict Output
intermediate2:00remaining
Output of K-fold split indices
What will be the output of the following Python code that uses KFold from scikit-learn?
ML Python
from sklearn.model_selection import KFold import numpy as np X = np.array([10, 20, 30, 40, 50]) kf = KFold(n_splits=2, shuffle=False) splits = [] for train_index, test_index in kf.split(X): splits.append((train_index.tolist(), test_index.tolist())) print(splits)
Attempts:
2 left
❓ Model Choice
advanced2:00remaining
Choosing K for K-fold cross-validation
You have a dataset with 1000 samples. You want to use K-fold cross-validation to estimate model performance. Which choice of K balances bias and variance best?
Attempts:
2 left
❓ Metrics
advanced2:00remaining
Calculating average accuracy from K-fold results
You performed 4-fold cross-validation and got these accuracy scores for each fold: [0.82, 0.85, 0.80, 0.83]. What is the correct average accuracy to report?
Attempts:
2 left
🔧 Debug
expert2:00remaining
Why does this K-fold code raise an error?
Consider this Python code snippet using KFold. It raises an error. What is the cause?
ML Python
from sklearn.model_selection import KFold import numpy as np X = np.array([1, 2, 3]) kf = KFold(n_splits=5) for train_index, test_index in kf.split(X): print('Train:', train_index, 'Test:', test_index)
Attempts:
2 left