0
0
ML Pythonprogramming~10 mins

Bias-variance tradeoff 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 calculate the mean squared error (MSE) between predictions and true values.

ML Python
mse = ((predictions - true_values) [1] 2).mean()
Drag options to blanks, or click blank then click option'
A-
B+
C*
D**
Attempts:
3 left
2fill in blank
medium

Complete the code to split data into training and testing sets using scikit-learn.

ML Python
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=[1], random_state=42)
Drag options to blanks, or click blank then click option'
A2
B0.2
C0.5
D20
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to train a linear regression model and make predictions.

ML Python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.[1](X_train, y_train)
predictions = model.predict(X_test)
Drag options to blanks, or click blank then click option'
Afit
Bscore
Cpredict
Dtrain
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps model complexity to training error.

ML Python
errors = {complexity: model_errors[complexity] [1] for complexity in model_errors if model_errors[complexity] [2] 0}
Drag options to blanks, or click blank then click option'
A* 100
B>
C<
D+ 1
Attempts:
3 left
5fill in blank
hard

Fill the blanks to calculate bias, variance, and total error from predictions.

ML Python
bias = (([1] - true_values) ** 2).mean()
variance = predictions.var(axis=0).mean()
total_error = bias + [2]
Drag options to blanks, or click blank then click option'
Apredictions.mean(axis=0)
Bvariance
Cbias
Dtrue_values
Attempts:
3 left