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
Related
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)
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'
I am able to pip install (pip install skope-rules) but not import skoperules used for interpretable ML applications (https://github.com/scikit-learn-contrib/skope-rules).
I am getting the following error:
ImportError: cannot import name 'six'
This has been documented as an issue here: https://github.com/scikit-learn-contrib/skope-rules/issues/41
However, the fix suggested (see code snippet below) does not work either:
pip install git+https://github.com/csinva/interpretability-implementations-demos from imodels import SkopeRules
Any ideas on how to import skrules?
This worked for me:
import six
import sys
sys.modules['sklearn.externals.six'] = six
from skrules import SkopeRules
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
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