Complete the code to calculate residuals from actual and predicted values.
residuals = actual - [1]The residual is the difference between the actual value and the predicted value.
Complete the code to plot residuals against predicted values using matplotlib.
plt.scatter([1], residuals) plt.axhline(y=0, color='r', linestyle='--') plt.xlabel('Predicted Values') plt.ylabel('Residuals') plt.show()
Plotting residuals against predicted values helps check for patterns in errors.
Fix the error in the code to compute residuals correctly.
residuals = [1] - predictedResiduals are actual minus predicted, so actual must be first.
Fill both blanks to create a dictionary of residuals for each data point where residual is positive.
positive_residuals = {i: residuals[i] for i in range(len(residuals)) if residuals[i] [1] 0 and residuals[i] [2] 0}We want residuals greater than zero, so both conditions use > 0.
Fill all three blanks to compute mean squared error (MSE) from residuals.
mse = sum([1]**2 for [2] in residuals) / [3]
MSE is average of squared residuals. We square each residual and divide by count.
