TypeError: mean_squared_error() got an unexpected keyword argument 'squared'

Screen Link:

My Code:

from sklearn.metrics import mean_squared_error

train_columns = ['accommodates', 'bathrooms']
knn = KNeighborsRegressor(n_neighbors=5, algorithm='brute', metric='euclidean')
knn.fit(train_df[train_columns], train_df['price'])
predictions = knn.predict(test_df[train_columns])

two_features_mse = mean_squared_error(test_df['price'], predictions)
two_features_rmse = mean_squared_error(test_df['price'], predictions, squared=False)

print(two_features_mse, two_features_rmse)

What I expected to happen:
Pass

What actually happened:

TypeErrorTraceback (most recent call last)
<ipython-input-1-3d17d90e5339> in <module>()
      6 predictions = knn.predict(test_df[train_columns])
      7 
----> 8 two_features_mse = mean_squared_error(test_df['price'], predictions, squared=True)
      9 two_features_rmse = mean_squared_error(test_df['price'], predictions, squared=False)
     10 

TypeError: mean_squared_error() got an unexpected keyword argument 'squared'

Hi :slight_smile:
I’m completing the practice ‘8. Calculating MSE using Scikit-Learn’ under ‘Multivariate K-Nearest Neighbors’. I followed the documentation to get RMSE by using the ‘squared’ argument but didn’t get the expected output.
Documentation here: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html#sklearn.metrics.mean_squared_error
Please could anyone help? Thanks in advance!

1 Like

Hi, Sally.

Sorry about this! Running the following script in the app outputs 0.18.

import sklearn
print(sklearn.__version__)

This means that we’re using version 0.18 of scikit-learn. Consulting the documentation for this function in this version of the library, we see that squared isn’t a parameter in it.

You’ll have to find a workaround to obtain the same result. Let me know if you need help with this.

Hi Bruno,

I’m still seeing this error in this module. The documentation linked to in the course takes you to the latest version of scikit-learn documentation ( 0.23.2):

we can instead use the sklearn.metrics.mean_squared_error function().

It would be great if the app could use that version OR if the link to the documentation could be changed to the one you shared.

3 Likes

How is this still unfixed months later? This feel exceptionally sloppy

Hi @bullchris2,

Thank you for bringing this to our attention; we have fixed this issue:

Best,
Sahil