ModuleNotFoundError: No module named 'sklearn.metrics.regression'

Question:

trying to do the following import:

from sklearn.metrics.regression import mean_absolute_error, mean_squared_error, r2_score

and I get the error:

ModuleNotFoundError: No module named 'sklearn.metrics.regression'

tried fixing with the installation of:

pip install -U scikit-learn scipy matplotlib

but I don’t think that’s what I’m missing since it didn’t work…

Asked By: user17809580

||

Answers:

You’re probably looking to import them from sklearn.metrics, not sklearn.metrics.regression

Link to the library

Answered By: DaSim

What you are looking for is:

from sklearn import metrics 

metrics.mean_absolute_error(<your params here>)
metrics.mean_squared_error(<your params here>)
metrics.r2_score(<your params here>)

Edit

you can check the attributes of the metrics instance with:

dir(metrics)
Answered By: SeF