0
0
ML Pythonprogramming~10 mins

Model comparison strategies 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 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'
Atrain_test_split
Btrain_test_ratio
CGridSearchCV
Dcross_val_score
Attempts:
3 left
2fill in blank
medium

Complete 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'
A3
B5
C1
D10
Attempts:
3 left
3fill in blank
hard

Fix 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'
Ay_pred
By_true
Cy_score
Dy_train
Attempts:
3 left
4fill in blank
hard

Fill 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'
Amean
Bmax
Cmodels
Dscores
Attempts:
3 left
5fill in blank
hard

Fill 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'
Ak
Bbest_model_name
Dcv_scores
Attempts:
3 left