I'm trying to import CountVectorizer from sklearn with the following line:
from sklearn.feature_extraction.text import CountVectorizer
sklearn: 0.0
scikit-learn: 0.23.2
numpy: 1.19.2
scipy: 1.5.2
threadpoolctl: 2.1.0
joblib: 0.17.0
Every time I try to run the code I receive the following error:
No name 'feature_extraction' in module 'sklearn' pylint(no-name-in-module)
Unable to import 'sklearn.feature_extraction.text' pylint(import-error)
If it matters I am running this in vscode on a Linux system inside of a VM. Also, I was able to run it earlier on the VM and it just stopped working for no apparent reason.
I found out the reason why for some reason my vscode was saving my file as .pyc and it wouldn't recognize the library with pyc. If anyone else experiences this problem note my file still said py but auto-generated a pycache folder.
because sklearn is deprecated
try this :
pip install scikit-learn
Related
I'm trying to run the following code:
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.feature_selection import SelectFromModel
from sklearn.model_selection import train_test_split
from sklearn import cross_validation
ExtraTreesClassifiers runs, and so does SelectFrom Model. But the latter two lines do not run. I get an error that says "ImportError: cannot import name 'cross_validation' from 'sklearn'."
I've checked in PyCharm to see if my interpreter has scikit-learn installed, and it's installed. I've uninstalled and reinstalled it from my terminal using pip3. I've tried running the file from my terminal, and it says "No such file or directory." I'm not sure what else to try.
Does anyone have any suggestions for what I could do next?
Thank you for your time.
cross_validation was used to exist as a scipy package but is now deprecated and so it isn't advisable to use it.
You can use sklearn.model_selection.train_test_split instead
:
from sklearn.model_selection import train_test_split
You can also try downgrading it by installing an older version of sklearn to continue using the cross_validation package.
References: ImportError: cannot import name cross_validation
I've loaded my Jupyter notebook as usual, when the only thing I changed is the Numpy version to 1.21.4.
However once I imported Kmeans from sklearn.cluster import KMeans I received the following error:
ImportError: DLL load failed while importing lapack_lite: The specified module could not be found.
I've tried the solution given in the link here, but it didn't help: ImportError: DLL load failed: The specified module could not be found
I've also tried to reinstall scikit-learn, but it also didn't help. So did restarting the kernel and the notebook didn't help.
My scikit-learn version is 1.1.1
I code on the same code on my laptop and on my desktop PC. On my laptop the code runs good the this specific import won't produce this error. But on my desktop PC, it does produce this error, which is strange because the scikit-learn and numpy versions are the same on both my desktop PC and laptop.
How can I fix this issue?
Recently I have upgraded my sklearn package in Python 3.7 and after that I could not find some important packages like gridsearch() , cross_validation() , GaussianNb () etc .
I am a beginner in Machine learning and I want to continue working with Python 3 instead of using Python 2. Can anyone please help me with this problem ? BTW, I use Anaconda 3 and Spyder 3.
I was able to create python 3.7.2 environment, then I could import gridsearch() , cross_validation() , GaussianNb () methods that you have described in the question.
Note: There are multiple ways in which you can install sklearn. One of the popular way to do it is using conda package manager.
The following is working on Windows-10 OS. I am creating python 3.7 as conda virtual environment.
I am pretty sure, this must work on other OS(Linux, redhat). But I havent tested.
My steps.
Created the virtual environment.
>>> conda create --name Py37Test python=3.7 pandas scikit-learn
>>> import sklearn
>>> from sklearn.model_selection import GridSearchCV
>>> from sklearn.model_selection import cross_validate
>>> from sklearn.naive_bayes import GaussianNB
i want to make recommendation location but i have problem with my sklearn. i have been update my library but it is not work. i use python 2.7 with anaconda
please help me :D
it is my library code.
from sklearn.cluster import KMeans
import numpy as np
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score, recall_score, precision_score
from sklearn import svm
from numpy import algorithms, environment
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
Windows
Open command prompt(as admin)
enter 'pip install -U scikit-learn'
Unix
Open terminal
Enter 'sudo pip install -U scikit-learn'
The default Anaconda distribution should have all of these packages, so it's likely your interpreter is looking for packages in a different spot. This is controlled by the PYTHONPATH system variable, which tell it where to look for package imports.
Anaconda can set this correctly for you during (re)installation if you choose to update the variable. You can also edit it yourself--how you do so depends on your OS.
To view the variable in python for troubleshooting:
How do I find out my python path using python?
This should point to a directory on you computer containing the package files.
I installed xgboost in PythonAnywhere and it shows successful but when I import it in a script, an error is given which says, "No module xgboost found". What can be the reason?
You probably installed it for a version of Python that is different to the one that you're running.
In my case, I use Anaconda2 and installed xgboost through git. Everything was ok but I got this message while trying to use import xgboost:
No module xgboost found
When I run pip install xgboost I got the message that everything is ok and xgboost is installed.
I went on ../Anaconda2/Lib/site-package and saw a folder xgboost-0.6-py2.7.egg, and inside there was other one xgboost. I just copied this folder xgboost and pasted it inside ../Anaconda2/Lib/site-package. And now it works =)