Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to split data into training and testing sets.
ML Python
from sklearn.model_selection import [1] X_train, X_test, y_train, y_test = [1](X, y, test_size=0.2, random_state=42)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
2fill in blank
mediumComplete the code to perform 5-fold cross-validation on a model.
ML Python
from sklearn.model_selection import cross_val_score scores = cross_val_score(model, X, y, cv=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
3fill in blank
hardFix the error in the code to calculate accuracy score after predictions.
ML Python
from sklearn.metrics import accuracy_score accuracy = accuracy_score(y_true, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
4fill in blank
hardFill both blanks to create a dictionary of mean cross-validation scores for each model.
ML Python
cv_scores = {model_name: cross_val_score(model, X, y, cv=5).[1]() for model_name, model in [2].items()} Drag options to blanks, or click blank then click option'
Attempts:
3 left
5fill in blank
hardFill all three blanks to select the best model based on highest mean cross-validation score.
ML Python
best_model_name = max(cv_scores, key=lambda k: cv_scores[[1]]) best_score = cv_scores[[2]] print(f"Best model: [3] with score {best_score:.2f}")
Drag options to blanks, or click blank then click option'
Attempts:
3 left