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

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...

You're probably looking to import them from sklearn.metrics, not sklearn.metrics.regression
Link to the library

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)

Related

ImportError: cannot import name 'ConfusionMatrixDisplay' from 'sklearn.metrics' [duplicate]

I receive an error message:
cannot import name 'ConfusionMatrixDisplay' from 'sklearn.metrics'".
when I run the following import code:
from sklearn.metrics import ConfusionMatrixDisplay
How to fix it?
Most likely your version of sklearn is outdated -
sklearn.metrics.ConfusionMatrixDisplay was added in sklearn>=1.0.0.
Source (docs)
You can check your sklearn version with:
python3 -m pip show scikit-learn

module 'sklearn.preprocessing' has no attribute 'Normalization'

I try to to use the preprocessing method from sklearn. I found other threads with the same issue but it didn't helped me to uninstall my existing sklearn versions. I think my problem is still that I have somewhere on my mac a scikit package. I just wonder how to fix this error?
My imports:
!pip install -q git+https://github.com/tensorflow/docs
import matplotlib.pyplot as plt
import numpy as np
import pandas as p
My code where the error line is dropped:
normalizer = preprocessing.Normalization(axis=-1)
Error:
AttributeError: module 'sklearn.preprocessing' has no attribute 'Normalization'

sklearn: cannot import name '_print_elapsed_time' from 'sklearn.utils' when using PDP feature

I am using sklearn version 0.22.1 (the latest one as of this writing).
When I do:
from sklearn.inspection import partial_dependence
from sklearn.inspection import plot_partial_dependence
it reported an error:
ImportError: cannot import name '_print_elapsed_time' from 'sklearn.utils'
I consulted the page ImportError: cannot import name '_print_elapsed_time' but the solution there (downgrading to sklearn 0.20) does not work for me as the PDP is available only in sklearn 0.22.1
How could I fix the problem? It is quite strange as I followed exactly the example on sklearn website https://scikit-learn.org/stable/modules/generated/sklearn.inspection.plot_partial_dependence.html#sklearn.inspection.plot_partial_dependence

cannot import name balanced_accuracy_score

I am using anaconda and running a script on spyder. When I call
import from sklearn.metrics balanced_accuracy_score
I get the error: "cannot import name balanced_accuracy_score "
Why is this particular metric not being imported?
import from is not valid syntax for Python, the pattern is
import <package> - for entire package
or
from <package> import <module> - only specific module in package
you want the latter, try:
from sklearn.metrics import balanced_accuracy_score

Python module Gensim error "cannot import name utils"

Hi I am using Gensim Word2Vec for word embedding in python.
from gensim.models import Word2Vec, KeyedVectors
But i am getting error like:
from gensim import utils
# cannot import whole gensim.corpora, because that imports wikicorpus...
from gensim.corpora.dictionary import Dictionary
ImportError: cannot import name utils. Thank you
I had a similar issue - In my case it was a dependency issue on scipy. I did the following to reinstall scipy.
pip uninstall scipy
conda install scipy
Hope this helps!

Categories

Resources