ComenzarEmpieza gratis

Mean squared error

Let's focus on the 2017 NBA predictions again. Every year, there are at least a couple of NBA teams that win way more games than expected. If you use the MAE, this accuracy metric does not reflect the bad predictions as much as if you use the MSE. Squaring the large errors from bad predictions will make the accuracy look worse.

In this example, NBA executives want to better predict team wins. You will use the mean squared error to calculate the prediction error. The actual wins are loaded as y_test and the predictions as predictions.

Este ejercicio forma parte del curso

Model Validation in Python

Ver curso

Instrucciones del ejercicio

  • Manually calculate the MSE. $$ MSE = \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i ) ^2 }{n} $$
  • Calculate the MSE using sklearn.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

from sklearn.metrics import ____

n = ___(predictions)
# Finish the manual calculation of the MSE
mse_one = sum((y_test - predictions)____) / n
print('With a manual calculation, the error is {}'.format(mse_one))

# Use the scikit-learn function to calculate MSE
mse_two = ____
print('Using scikit-learn, the error is {}'.format(mse_two))
Editar y ejecutar código