0
0
ML Pythonprogramming~10 mins

Why proper evaluation prevents overfitting in ML Python - Test Your Understanding

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 = train_test_split(X, y, test_size=0.2, random_state=42)
Drag options to blanks, or click blank then click option'
Across_val_score
BStandardScaler
CGridSearchCV
Dtrain_test_split
Attempts:
3 left
2fill in blank
medium

Complete the code to train a model on the training data.

ML Python
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Apredict
Bfit
Cscore
Dtransform
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to evaluate the model correctly on test data.

ML Python
accuracy = model.[1](X_test, y_test)
print(f"Test accuracy: {accuracy:.2f}")
Drag options to blanks, or click blank then click option'
Atransform
Bpredict
Cscore
Dfit
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a dictionary of accuracy scores for training and testing data.

ML Python
scores = {
    'train_accuracy': model.[1](X_train, y_train),
    'test_accuracy': model.[2](X_test, y_test)
}
Drag options to blanks, or click blank then click option'
Ascore
Bpredict
Cfit
Dtransform
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to perform cross-validation and print the mean accuracy.

ML Python
from sklearn.model_selection import [1]
scores = cross_val_score(model, X, y, cv=[2])
print(f"Mean CV accuracy: {scores.[3]():.2f}")
Drag options to blanks, or click blank then click option'
Across_val_score
B5
Cmean
Dfit
Attempts:
3 left