Difference between scikit-learn and sklearn (now deprecated) - python

On OS X 10.11.6 and python 2.7.10 I need to import from sklearn manifold.
I have numpy 1.8 Orc1, scipy .13 Ob1 and scikit-learn 0.17.1 installed.
I used pip to install sklearn(0.0), but when I try to import from sklearn manifold I get the following:
Traceback (most recent call last): File "", line 1, in
File
"/Library/Python/2.7/site-packages/sklearn/init.py", line 57, in
from .base import clone File
"/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in
from .utils.fixes import signature File
"/Library/Python/2.7/site-packages/sklearn/utils/init.py", line
10, in from .murmurhash import murmurhash3_32 File
"numpy.pxd", line 155, in init sklearn.utils.murmurhash
(sklearn/utils/murmurhash.c:5029) ValueError: numpy.dtype has the
wrong size, try recompiling.
What is the difference between scikit-learn and sklearn? Also,
I cant import scikit-learn because of a syntax error

Regarding the difference sklearn vs. scikit-learn:
The package "scikit-learn" is recommended to be installed using pip install scikit-learn but in your code imported using import sklearn.
A bit confusing, because you can also do pip install sklearn and will end up with the same scikit-learn package installed, because there is a "dummy" pypi package sklearn which will install scikit-learn for you.
From this thread:
scikit-learn is in install_requires of sklearn setup.py so you do
end-up with scikit-learn installed
So:
At the end, pip install sklearn or pip install scikit-learn ---
apart from the annoying sklearn (0.0) showed in the pip list ---
will install the latest available build from PyPI.

You might need to reinstall numpy. It doesn't seem to have been installed correctly.
sklearn is how you type the scikit-learn name in python (only the latter should be installed, the former is now deprecated).
Also, try running the standard tests in scikit-learn and check the output. You will have detailed error information there.
As a side note, do you have nosetests installed? Try: nosetests -v sklearn. You type this in bash, not in the python interpreter.

As of Dec. 1, 2022 you have to use scikit-learn in pip requirements files as pip install sklearn is now deprecated.
source: https://github.com/scikit-learn/sklearn-pypi-package

The 'sklearn' PyPI package is deprecated, use 'scikit-learn'
rather than 'sklearn' for pip commands.
Hereafter sklearn won't available for pip install from the latest versions. So it is better to start scikit-learn
Reason for the deprecation:
sklearn package on PyPI exists to prevent malicious actors from using the sklearn package, since sklearn (the import name) and scikit-learn (the project name) are sometimes used interchangeably. scikit-learn is the actual package name and should be used with pip
Please check this link for further info

I got the same problem when uploading my project on Google Cloud. The error log said
File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py"
.......ModuleNotFoundError: No module named 'sklearn'
The solution as said above worked.
Changed 'sklearn' to 'scikit-learn' in my requirements.txt

Related

Pycaret cannot imported due to another import error

ImportError: cannot import name '_joblib_parallel_args' from 'sklearn.utils.fixes' (c:\users\ezgi\appdata\local\programs\python\python38\lib\site-packages\sklearn\utils\fixes.py)
To fix I update sklearn library. But, it don't work. Anyone know the reason behind it?
I update sklearn with
pip install --upgrade scikit-learn
Also, uninstall and install it with pip.
This is because one of pycaret's dependencies (imbalanced-learn) fails with the latest version of sklearn
https://github.com/scikit-learn-contrib/imbalanced-learn/issues/894
A temporary workaround until this is fixed would be to use a lower version of sklearn. If you are using pip install pycaret, then you need to use a version of sklearn < 1.0.0

ModuleNotFoundError: No module named 'pandas' (when running a linear regression)

I am new to Python and I am trying to run a linear regression Python code, which I have downloaded.
My problem starts here
import pandas as pd
When I run the code, it tells me
Traceback (most recent call last):
File "E:\MACHINE LEARNING\linear regression tutorial\free_python_tips-main\free_python_tips-main\04_linear_regression\04_linear_regression.py", line 9, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
although this package is installed, in Anaconda as well.
How could I solve this?
go to your command prompt and type
pip install pandas
or if you are using anaconda then type
conda install pandas
you can refer these links for more details:
package installation with anaconda and
pandas documentation
and if you wanted to use Linear Regression then you need to install scikit learn
for pip
pip install -U scikit-learn
for anaconda
conda install -c conda-forge scikit-learn
then you need to import it in your code
from sklearn.linear_model import LinearRegression
Hope it solves your issue !!

MacOS Catalina, pip has installed packages but python cannot find them?

My pip has worked fine with my python 3 in the past and I have downloaded things such as pandas which all work fine in python. The problem I now encounter is any library I attempt to download using pip is not recognised by python. Here is how I have tried downloading skl.
pip install sklearn
pip3 install sklearn
When I input
pip list
or
pip3 list
Both list sklearn as being downloaded, however, when I go in python and input:
from sklearn import linear_model
I get the error
Traceback (most recent call last):
File "/Users/nicross/Desktop/RainDance/RainFaller.py",line 8, in <module>
from sklearn import linear_model
ModuleNotFoundError: No module named 'sklearn'
Any help solving this would be greatly appreciated.
python3 -m pip install sklearn
From the sklearn docs it looks like you might want to try:
pip install -U scikit-learn
(For more, try following the steps here: https://scikit-learn.org/stable/install.html and see if those fix it)

ImportError: cannot import name 'MultiOutputMixin' from 'sklearn.base'

I just want to do a linear regression with scikit-learn. When I try to import the linear model package the error message from the title appears.
I tried to follow the solution from a similar problem (link). The suggestion is basically to just get rid of the part of the code where it requests for the "MultipleOutputMixin" thingy.
When I do this, of course the MultiOuputMixin is no longer the problem, but it derives in an error at the line marked as 22 in the error message shown below.
Any ideas on what can I do to avoid the problem?
Thanks in advance for your help! :)
Python version = 3.70
scikit-learn verion = 0.21.2
This is what I'm doing:
from sklearn import linear_model
This is the error that I get:
ImportError Traceback (most recent call last)
<ipython-input-46-1c4d4ebecc3f> in <module>()
1 # Select a linear
----> 2 from sklearn import linear_model
C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\linear_model\__init__.py in <module>()
13
14 from .bayes import BayesianRidge, ARDRegression
---> 15 from .least_angle import (Lars, LassoLars, lars_path, lars_path_gram, LarsCV,
16 LassoLarsCV, LassoLarsIC)
17 from .coordinate_descent import (Lasso, ElasticNet, LassoCV, ElasticNetCV,
C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\linear_model\least_angle.py in <module>()
18
19 from .base import LinearModel
---> 20 from ..base import RegressorMixin, MultiOutputMixin
21 from ..utils import arrayfuncs, as_float_array, check_X_y
22 from ..model_selection import check_cv
ImportError: cannot import name 'MultiOutputMixin' from 'sklearn.base' (C:\Users\Usuario\Anaconda3\lib\site-packages\sklearn\base.py)
I have encountered a similar problem. I could solve by opening a new IPython console.
I don't think so it's a good idea to modify library related files without understanding it fully. I got this issue when I had updated scikit learn package. It worked after I launched a new shell.
!pip install scikit-learn==0.18.2 is the wrong advice.
You'll need scikit-learn version 0.22 or higher.
This was solved after shutting down the existing notebook and reopening it from home page. It may need a restart is what I got to know.
uninstall and install the imblearn again :
pip install imblearn
with the updated sklearn packages this worked for me.
From installation anacoda prompt:
Installing collected packages: imblearn, scikit-learn
Attempting uninstall: scikit-learn
Found existing installation: scikit-learn 0.20.3
Uninstalling scikit-learn-0.20.3:
Successfully uninstalled scikit-learn-0.20.3
Successfully installed imblearn-0.0 scikit-learn-0.23.1
Problem reasons
This issue occurs when you tried to install a new version of scikit-learn, I encountered the same issue while trying to install sklearn (1.0) while an old scikit-learn version (0.22.2) was installed.
I encountered this problem, because I had to update the version of sciki-learn on Colab and retrain my model to avoid some warnings with the production environment. The problem was as shown below:
UserWarning: Trying to unpickle estimator TfidfVectorizer from version 0.22.2.post1 when using version 1.0. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
So, when I did this:
!pip install scikit-learn==1.0
I got the error below while importing the following libraries:
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
This is the rrror:
ImportError: cannot import name '_OneToOneFeatureMixin' from 'sklearn.base' (/usr/local/lib/python3.7/dist-packages/sklearn/base.py)
How to fix it
This problem can be fixed by simply trying to restart the runtime environment, or open a new notebook (runtime env restart by default as mentioned by AnandOCF)
This worked for me.
Activate your conda env
conda activate 'your_env_name'
Install imblearn library using pip if you haven't
pip install imblearn
Again install imbalanced-learn library using conda
conda install -c conda-forge imbalanced-learn
Then, you should be able to import without any errors.
You can run the following command on your notebook to solve the issue:
!pip install scikit-learn==0.18.2

ImportError: cannot import name NUMPY_MKL

I am trying to run the following simple code
import scipy
scipy.test()
But I am getting the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 586, in runfile
execfile(filename, namespace)
File "C:/Users/Mustafa/Documents/My Python Code/SpectralGraphAnalysis/main.py", line 8, in <module>
import scipy
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name NUMPY_MKL
I am using python 2.7 under windows 10.
I have installed scipy but that does not seem to solve the problem
Any help is appreciated.
If you look at the line which is causing the error, you'll see this:
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
This line comment states the dependency as numpy+mkl (numpy with Intel Math Kernel Library). This means that you've installed the numpy by pip, but the scipy was installed by precompiled archive, which expects numpy+mkl.
This problem can be easy solved by installation for numpy+mkl from whl file from here.
Reinstall numpy-1.11.0_XXX.whl (for your Python) from www.lfd.uci.edu/~gohlke/pythonlibs. This file has the same name and version if compare with the variant downloaded by me earlier 29.03.2016, but its size and content differ from old variant. After re-installation error disappeared.
Second option - return back to scipy 0.17.0 from 0.17.1
P.S. I use Windows 64-bit version of Python 3.5.1, so can't guarantee that numpy for Python 2.7 is already corrected.
I'm not sure if this is a good solution but it removed the error.
I commented out the line:
from numpy._distributor_init import NUMPY_MKL
and it worked. Not sure if this will cause other features to break though
I had the same problem while installing gensim on windows. Gensim is dependent on scipy and scipy on numpy. Making all three work is real pain. It took me a lot of time to make all there work on same time.
Solution:
If you are using windows make sure you install numpy+mkl instead of just numpy.
If you have already installed scipy and numpy, uninstall then using "pip uninstall scipy" and "pip uninstall numpy"
Then download numpy-1.13.1+mkl-cp34-cp34m-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
and install using pip install numpy-1.13.1+mkl-cp34-cp34m-win32.wh
Note: in cp34-cp34m 34 represent the version of python you are using, so download the relevant version.
Now download scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy (appropriate version for your python and system)
and install using "pip install scipy‑0.19.1‑cp34‑cp34m‑win32.whl"
Your numpy and Scipy both should work now.
These binaries by Christoph Gohlke makes it very easy to install python packages on windows. But make sure you download all the dependent packages from there.
I don't have enough reputation to comment but I want to add, that the cp number of the .whl file stands for your python version.
cp35 -> Python 3.5.x
cp36 -> Python 3.6.x
cp37 -> Python 3.7.x
I think it's pretty obvious but still I wasted almost an hour because of this and maybe other people struggle with that, too.
So for me worked version cp36 that I downloaded here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
since I am using Python 3.6.8.
Then I uninstalled numpy:
pip uninstall numpy
Then I installed numpy+mkl:
pip install <destination of your .whl file>
The reason for the error is you upgraded your numpy library of which there are some functionalities from scipy that are required by the current version for it to run which may not be found in scipy. Just upgrade your scipy library using python -m pip install scipy --upgrade. I was facing the same error and this solution worked on my python 3.5.
From your log its clear that numpy package is missing. As mention in the PyPI package:
The SciPy library depends on NumPy, which provides convenient and fast N-dimensional array manipulation.
So, try installing numpy package for python as you did with scipy.
I recently got the same error when trying to load scipy in jupyter (python3.x, win10), although just having upgraded to numpy-1.13.3+mkl through pip.
The solution was to simply upgrade the scipy package (from v0.19 to v1.0.0).
yes,Just reinstall numpy,it works.

Categories

Resources