Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to calculate residuals from actual and predicted values.
ML Python
residuals = actual - [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
2fill in blank
mediumComplete the code to plot residuals against predicted values using matplotlib.
ML Python
plt.scatter([1], residuals) plt.axhline(y=0, color='r', linestyle='--') plt.xlabel('Predicted Values') plt.ylabel('Residuals') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
3fill in blank
hardFix the error in the code to compute residuals correctly.
ML Python
residuals = [1] - predicted Drag options to blanks, or click blank then click option'
Attempts:
3 left
4fill in blank
hardFill both blanks to create a dictionary of residuals for each data point where residual is positive.
ML Python
positive_residuals = {i: residuals[i] for i in range(len(residuals)) if residuals[i] [1] 0 and residuals[i] [2] 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
5fill in blank
hardFill all three blanks to compute mean squared error (MSE) from residuals.
ML Python
mse = sum([1]**2 for [2] in residuals) / [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left