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 = train_test_split(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 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'
Attempts:
3 left
3fill in blank
hardFix 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'
Attempts:
3 left
4fill in blank
hardFill 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'
Attempts:
3 left
5fill in blank
hardFill 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'
Attempts:
3 left