Cannot import name 'plot_precision_recall_curve' from 'sklearn.metrics' - scikit-learn

Hello i got trouble to import my package?cannot import name from sklearn
cannot import name 'plot_precision_recall_curve' from 'sklearn.metrics' (\Programs\Python\Python311\Lib\site-packages\sklearn\metrics_init_.py)
i try uninstall and install again pip install scikit-learn still not working at VScode
jupyter, python, scikit-learn

That function is from an old version of scikit-learn.
You can try using scikit-plot
Installation
pip install scikit-plot
Import library
# Import scikit-plot
import scikitplot as skplt
import matplotlib.pyplot as plt
skplt.metrics.plot_precision_recall(y, y_pred)
plt.show()
Documentation: https://scikit-plot.readthedocs.io/en/stable/metrics.html#scikitplot.metrics.plot_precision_recall
Or you can use precision_recall_curve in the current version of sklearn as mentioned by Dr. Snoopy
from sklearn.metrics import precision_recall_curve

Related

AttributeError: module 'numpy.random' has no attribute 'BitGenerator' in python 3.8.10

I'm trying to import the xarray module into python 3.8.10 but I get this error:
AttributeError: module 'numpy.random' has no attribute 'BitGenerator'
In order to allow you to reproduce the error: First of all, I created a new environment with conda and by importing at the same time the modules I need (to avoid the problems of incompatible dependencies) :
conda create -n Myenv Python=3.8 matplotlib numpy time xarray netCDF4 termcolor
Then, I try to import in ipython3 all modules I need to run my code:
import matplotlib as mpl
mpl.use('agg')
import numpy as np
import os
import time
import glob
import sys
from datetime import datetime,date,timedelta
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.colors as colors
# from operator import itemgetter
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap, shiftgrid
from termcolor import colored
import xarray as xr
and, at this moment, I get the error...
I searched the documentation to see if the BitGenerator Attribute exists in my version of numpy (1.22.3), and it does. So I don't understand why this error occurs.
Someone can help me to understand please ?
Thank u !
If you want more informations about my environnement, I can provide.
I solved mine with pip install --upgrade numpy

How can I solve this problem? (vs code error)

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import check_util.checker as checker
from IPython.display import clear_output
from PIL import Image
import os
import time
import re
from glob import glob
import shutil
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow import keras
print('tensorflow version: {}'.format(tf.__version__))
print('GPU available: {}'.format(tf.test.is_gpu_available()))
Error: Session cannot generate requests Error: Session cannot generate
requests at w.executeCodeCell
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:320068)
at w.execute
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:319389)
at w.start
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:315205)
at runMicrotasks () at processTicksAndRejections
(internal/process/task_queues.js:93:5) at async
t.CellExecutionQueue.executeQueuedCells
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:329732)
at async t.CellExecutionQueue.start
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:329272)
I think this problem has something to do with kernel.
But I can't find a solution, even though I've already reinstalled and restarted.
Please help me solve this problem.
I'm using Python 3.7.10, Tensorflow 2.3
Please try again by restarting the VS code or by changing the jupyter virtual environment (Change kernel for the notebook) while executing this code in VS code.
(I tried the same code as mentioned above in VS code using python 3.7.10 and tensorflow=2.3 and it executed successfully)
Please check this output:
tensorflow version: 2.3.0
WARNING:tensorflow:From C:\Users\Hp\AppData\Local\Temp\ipykernel_6944\127915523.py:16: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
GPU available: False

'gensim' is not defined even though it shows in the virtualenv packages

I use virtualenv in Python. I use gensim in a script. I get this error
name 'gensim' is not defined
I tried to install genism using pip and conda. I ended up updating conda packages after some suggested solution .
I see there is genism 3.8 after reunnig pip list, but I still have the error !. Could you please tell me what to do
P.S. I take input from a html form in a Flask function. Inside the function, I call the script that has genism. The program show the forms input buttons . After clicking the submit buton, I get the error message.
import re
import numpy as np
import pandas as pd
from pprint import pprint
#database
import db
from db import *
# Gensim
import gensim
import gensim.corpora as corpora
from gensim.utils import simple_preprocess
from gensim.models import CoherenceModel
from gensim.parsing.preprocessing import preprocess_string, strip_punctuation, strip_numeric
# spacy for lemmatization
import spacy
# Plotting tools
import pyLDAvis
import pyLDAvis.gensim # don't skip this
import matplotlib.pyplot as plt
#matplotlib inline
from conn import *
from functions import *
# Enable logging for gensim - optional
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.ERROR)
import warnings
warnings.filterwarnings("ignore",category=DeprecationWarning)
Thanks in advance

Cannot import Sklearn from sklearn.externals.joblib

I am a beginner and I just started with machine learning. I am trying to import classes like imputer from sklearn but i am unable to do it.
from sklearn.preprocessing import Imputer,LabelEncoder,OneHotEncoder,StandardScaler
ImportError: cannot import name 'version' from
'sklearn.externals.joblib'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib__init__.py)
I had the same problem.
I have replaced
from sklearn.externals import joblib
with
import joblib
and it works fine in Python 3.7.2
I believe there was an update on Scikit-learn that render that import unusable.
I had my local installation to be version 0.20.3 and this import is pefectly working. But on my server I have installation 0.23.1 and this error pop up. Something must be chaging in the new version.
For my case, use import joblib fix the problem. In your case it seems more complicated. This sounds very much likeky to be caused if you have more than one Scikit-learn version installed on your system. You need to uninstall all of them and do a clean install of sklearn.
The problem sometimes happens due to the version. This may help:
If you has written like this
from sklearn.externals import joblib
Modify it as this:
import joblib
Try
python -m pip install sklearn --upgrade
and
python -m pip install joblib --upgrade
and then, use this :
import joblib
Good luck.
import joblib
This works for me. Actually I was having that kinda challenge

ModuleNotFoundError: no module named 'scipy'

Hi I am bit of newby tinkering around with some machine learning, and I am getting an error in the python shell for scipy. I did a pip install for scipy in the windows command prompt and there are some odd looking errors when pip attempts to install. This is the simple little code I am using, any ideas to try for the scipy error?
import pandas as pd
import math
import numpy as np
import scipy
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
df = pd.read_csv('C:\\Users\\bbartling\\Documents\\Python\\test_SP data\\testElectData.csv')
df = df[['kWhDay','CDDbase55',]]
print(df.head())
# forecast_col = 'kWhDay'
X = np.array(df.drop(['kWhDay'],1))
y = np.array(df.drop(['CDDbase55'],1))
I figured this out on how to install python modules thru wheels. Good U tube video to make it work
https://www.youtube.com/watch?v=YXIlclFQZVU

Resources