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

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'

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

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

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)

How to fix this AttributeError: module 'tensorflow' has no attribute 'get_default_graph'?

My tensorflow version=2.0.0,keras version=2.1.5,python version=3.7
code:
import os
import cv2
import numpy as np
import argparse
import json
from PIL import Image
from mtcnn import MTCNN
detector = MTCNN()
return a error as like:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
A lot of the newer versions of Tensorflow have inconsistencies.
Try either downgrading your tensorflow version pip install tensorflow==1.13.1
or upgrading your Keras to something 2.3 or above pip install -U keras
If you're brave you could also go digging to find which python file has a line like import keras.something.something and change it to import tensorflow.keras.something

Wrong tensorflow version used after !pip install tf-nightly

I'm using some code written by my lecturer & I'm running it on a GPU in Google Colab. At the beginning of the code the tf-nightly package is installed using !pip install tf-nightly. Afterwards, the following packages are imported and the version of tf used is printed out as follows:
from tensorflow import keras
from tensorflow.keras import layers
# Helper libraries
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from mpl_toolkits.axes_grid1 import make_axes_locatable
print(tf.__version__)
For some reason, sometimes the version of tf used isn't always 2.3.xxx but instead sometimes it's 2.2 - but not always. Usually this happens when the tab has been open for a while but I haven't been using it.
This then causes the error
"AttributeError: module 'tensorflow.keras.preprocessing' has no attribute 'image_dataset_from_directory'" when I try to use this package.
Can anyone tell me how to stop this from happening/what to do if it does happen?
Thank you very much in advance.

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