No module named sklearn - python

I am trying to install sklearn module through pip, but below is the error i am encountered.

I think error code 1 actually refers to missing Lapack/Blast dependencies on your windows installation. Lapack/BLAST are requirements for most scientific Python packages for example : numpy, scipy, sklearn etc...
You could either build these for source and then pip install sklearn
Instructions for this here > http://www.scipy.org/scipylib/building/windows.html
Or just install anaconda and not have any of these issues. If you want to do advanced data analytics with Python, I would recommend using Anaconda especially in windows machine where any scipy package installation will be like fighting with windmills
Instructions how to get Anaconda here > https://www.continuum.io/downloads#windows
Further tip. I would go with Anaconda full 3.6 for your dev machine so you have all that you might need out of the box. This includes popular science, data manipulation and math packages + Jupyper (iPython) notebooks and Spider IDE for development.
For server you only want required packages so use miniconda there.

Just install Anaconda and there type in conda install scikit-learn in the console.

Related

No module named 'mlflow.sklearn'; 'mlflow' is not a package

installed mlflow on my windows machine with
pip install mlflow
followed by other dependent library pandas,numpy,sklearn
Ran a tutorial on wine quality model from the give link
https://www.mlflow.org/docs/latest/tutorials-and-examples/tutorial.html
I am getting the below error.
import mlflow.sklearn
ModuleNotFoundError: No module named 'mlflow.sklearn'; 'mlflow' is not a package
I thought it may be some firewall issue, so I tried on my personal system, and it's still the same error.
What could be the mistake I am doing here? or some library related issues I am facing here?
Please make sure you are installing the package at the correct PATH.
For example, if you have different versions of Python installed on your computer, installing packages can get a little tricky and thus, it's recommended to use a virtual environment to keep packages or different installations properly organised on your computer.
Since you are using a conda environment, I would suggest to use conda install mlflow with an appropriate channel instead of pip install mlflow i.e. conda install -c conda-forge mlflow.
For more details, please check https://anaconda.org/conda-forge/mlflow.

Does installing anaconda conflict with Python3 and R already installed?

On my Ubuntu 18.04, I have Python 3 and R installed. I am about to study some data science, and just found https://www.anaconda.com/distribution/.
anaconda comes with Python and R and some packages. Will installing anaconda conflict with my existing installation of Python 3 and R?
Shall I install anaconda, or shall I install the packages manually and individually on demand?
How do people in data science install the tools?
Thanks.
I have a system python and R as well as anaconda and they don’t seem to conflict and I have the same OS as you. Conda, the package and environment manager that comes with anaconda, supposedly does not mix well with pip, meaning if you have a virtual environment you should use one or the other. However, I have mixed them without any difficulties.
I prefer creating virtual environments the more standard way, but there are some scientific packages that are much easier to install using conda.

How to add module in spyder IDE of python

I started learning machine learning. I was stuck in the IDE where I was unable to add the module of sklearn in my Python file. It was showing ModuleNotFoundError: No module named 'sklearn.cross_validation'
Refer to this link on guide on how to install libraries in Spyder. If you are on ubuntu, then the best thing for you would be to install packages using pip as that will install and settle dependencies. You can also use conda for that. Make sure that python environment that spyder is using is same as the python environment you are installing the package for.
Great that you started learning machine learning, enjoy the journey!
I would advise you to install python using Anaconda https://www.anaconda.com/distribution/
If you do this most of the modules you will need will be pre-installed.

ModuleNotFoundError: No module named 'sklearn'

I want to import sklearn but there is no module apparently:
ModuleNotFoundError: No module named 'sklearn'
I am using Anaconda and Python 3.6.1; I have checked everywhere but still can't find answers.
When I use the command:
conda install scikit-learn should this not just work?
Where does anaconda install the package?
I was checking the frameworks in my python library and there was nothing about sklearn only numpy and scipy.
Please help, I am new to using python packages especially via anaconda.
You can just use pip for installing packages, even when you are using anaconda:
pip install -U scikit-learn scipy matplotlib
This should work for installing the package.
And for Python 3.x just use pip3:
pip3 install -U scikit-learn scipy matplotlib
Will leave below two options that may help one solve the problem:
Using conda
Using pip
One might want to consider the notes at the end, specially before resorting to the 2nd option.
Option 1
If one wants to install it in the root and one follows the requirements - (Python (>= 2.7 or >= 3.4), NumPy (>= 1.8.2), SciPy (>= 0.13.3).) - the following should solve the problem
conda install scikit-learn
Alternatively, as mentioned here, one can specify the channel as follows
conda install -c anaconda scikit-learn
Let's say that one is working in the environment with the name ML.
Then the following should solve one's problem:
conda install -n ML scikit-learn
# or
conda install -n ML -c anaconda scikit-learn
Option 2
If the above doesn't work, on Anaconda Prompt one can also use pip (here's how to pip install scikit-learn), so the following may help
pip install scikit-learn
However, consider the last note below before proceeding.
Notes:
When using Anaconda, one needs to be aware of the environment that one is working.
Then, in Anaconda Prompt, one needs to run the following
conda $command -n $ENVIRONMENT_NAME $IDE/package/module
$command - Command that one intends to use (consult documentation for general commands)
$ENVIRONMENT NAME - The name of one's environment (if one is working in the root,
conda $command $IDE/package/module is enough)
$IDE/package/module - The name of the IDE or package or module
If one needs to install/update packages, the logic is the same as mentioned in the introduction. If you need more information on Anaconda Packages, check the documentation.
What is the flag -c.
pip doesn't manage dependencies the same way conda does and can, potentially, damage one's installation.
If you are using Ubuntu 18.04 or higher with python3.xxx then try this command
$ sudo apt install python3-sklearn
then try your command. hope it will work
I did the following:
import sys
!{sys.executable} -m pip install sklearn
I've tried a lot of things but finally, including uninstall with the automated tools. So, I've uninstalled manually scikit-learn.
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/sklearn
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/scikit_learn-0.20.0-py3.6.egg-info
And re-install using pip
sudo pip3.6 install -U scikit-learn
Hope that can help someone else!
This happened to me, I tried all the possible solutions with no luck!
Finaly I realized that the problem was with Jupyter notebook environment, not with sklearn!
I solved the problem by re-installing Jupyter at the same environment as sklearn
the command is: conda install -c anaconda ipython. Done...
The other name of sklearn in anaconda is scikit-learn. simply open your anaconda navigator, go to the environments, select your environment, for example tensorflow or whatever you want to work with, search for scikit_learn in the list of uninstalled packages, apply it and then you can import sklearn in your jupyter.
SOLVED:
The above did not help. Then I simply installed sklearn from within Jypyter-lab, even though sklearn 0.0 shows in 'pip list':
!pip install sklearn
import sklearn
What I learned later is that pip installs, in my case, packages in a different folder than Jupyter. This can be seen by executing:
import sys
print(sys.path)
Once from within Jupyter_lab notebook, and once from the command line using 'py notebook.py'.
In my case Jupyter list of paths where subfolders of 'anaconda' whereas Python list where subfolders of c:\users[username]...
On Windows, I had python 3+ version. pip version - 22.3.1
I had installed:
pip install sklearn
But, it seems it is deprecated with scikit-learn.
So, I did:
pip install scikit-learn
And, it worked!!!
Cause
Conda and pip install scikit-learn under ~/anaconda3/envs/$ENV/lib/python3.7/site-packages, however Jupyter notebook looks for the package under ~/anaconda3/lib/python3.7/site-packages.
Therefore, even when the environment is specified to conda, it does not work.
conda install -n $ENV scikit-learn # Does not work
Solution
pip 3 install the package under ~/anaconda3/lib/python3.7/site-packages.
Verify
After pip3, in a Jupyter notebook.
import sklearn
sklearn.__file__
~/anaconda3/lib/python3.7/site-packages/sklearn/init.py'
I had the same problem.
The issue is when we work on multiple anaconda environments, not all packages are installed in all environments.
you can check your conda environment by writing the following code in anaconda prompt:
conda env list
then you can check the packages installed in each environment :
conda list -n NAME_OF_THE_ENVIRONMENT
for me, the environment that I was working with , was missing sklearn, although the package was installed in the other environments.
therefore, I just simply installed sklearn package in that particular environment
conda install -n NAME_OF_THE_ENVIRONMENT scikit-learn
and the issue was resolved
install these ==>> pip install -U scikit-learn scipy matplotlib
if still getting the same error then ,
make sure that your imoprted statment should be correct. i made the mistike while writing ensemble so ,(check spelling)
its
should be >>> from sklearn.ensemble import RandomForestClassifier
I had the same issue as the author, and ran into the issue with and without Anaconda and regardless of Python version. Everyone's environment is different, but after resolving it for myself I think that in some cases it may be due to having multiple version of Python installed. Each installed Python version has its own \Lib\site-packages\ folder which can contain a unique set of modules for that Python version, and where the IDE looks into folder path that doesn't have scikit-learn in it.
One way to try solve the issue: you might clear your system of all other Python versions and their cached/temp files/system variables, and then only have one version of Python installed anywhere. Then install the dependencies Numpy and Scipy, and finally Scikit-learn.
More detailed steps:
Uninstall all Python versions and their launchers (e.g. from Control Panel in Windows) except the one version you want to keep. Delete any old Python version folders in the Python directory --uninstalling doesn't remove all files.
Remove other Python versions from your OS' Environment Variables (both under the system and user variables sections)
Clear temporary files. For example, for Windows, delete all AppData Temp cache files (in C:\Users\YourUserName\AppData\Local\Temp). In addition, you could also do a Windows disk cleanup for other temporary files, and then reboot.
If your IDE supports it, create a new virtual environment in Settings, then set your only installed Python version as the interpreter.
In your IDE, install the dependencies Scipy and Numpy from the module list first, then install Scikit-Learn.
As some others have suggested, the key is making sure your environment is set up correctly where everything points to the correct library folder on your computer where the Sklearn package is located. There are a few ways this can be resolved. My approach was more drastic, but it turns out that I had a very messy Python setup on my system so I had to start fresh.
Using Anaconda-navigator UI environment
When running Anaconda-navigator:
Choose the 'Environments' tab on the left and create a new environment (e.g. ML - see Gonçalo Peres answer above, I made one called 'CourseraML').
Set Python version 3.7 (for Coursera course Applied Machine Learning in Python). Also include R.
Then find modules to install using the 'not installed' drop-down menu item. Search for each module needed in the search bar and select. sklearn is part of scikit-learn. Select it and install (it should find all relevant dependencies). Modules needed for Applied ML course: seaborn, numpy, scikit-learn, pandas, matplotlib
You'll need to restart Jupyter Notebook and reopen your file.
Command line version of above:
conda install -n CourseraML seaborn scikit-learn pandas numpy matplotlib graphviz
Causes
-your jupyter notebook might be importing the sklearn and other libraries from the
another the location(path) than the libraries from conda or pip.
MY Problem
In my case, My jupyter notebook was importing the libraries for snap manager. Since, I install jupyter using the snap instead of other ways.
You can check where other libraries are being imported in jupyter using code:
import cv2 as cv
print(cv.__file__)
Solution
So , I uninstall jupyter notebook and then install notebook using conda.
sudo snap remove jupyter
conda install -c conda-forge notebook

How to install xgboost in Rodeo GUI for a Mac OS?

xgboost is recognized in terminal but not in Rodeo GUI
I've been trying to install xgboost since last night, but I just can't seem to get it to work. My latest development so far is that I am able to successfully call on the module when using the terminal, but it has an ImportError when using my Rodeo GUI, also in atom-hydrogren. Any tips how I can call xgboost for these?
Here 's a screencap for importing xgboost:
Success:
Failure:
>>> import xgboost
ImportError: No module named xgboost
Rodeo and Mac Terminal use different versions of Python and obviously different PYTHONPATH with their own set of libraries.
When you installed xgboost with git, you used the Terminal which is configured to use Python 2.7.10 (probably pre-installed with the OS). However, it is not installed in the package site that Rodeo uses.
You have two options:
Make Rodeo use the package site that the Terminal uses
Install xgboost in Rodeo's package site
Since you stated that Rodeo is installed alongside with Anaconda, I'd go with option 2. Anaconda has a lot of useful packages pre-installed that don't come along with the pre-installed libraries that the Terminal uses.
You could follow this link to install xgboost in Anaconda. After which, it should work fine with Rodeo.
Otherwise, you could try this code directly in Rodeo:
import pip
pip.main(['install','xgboost'])
If xgboost cannot compile, then it means that you don't have a compatible compiler to build it. To build it in a Mac, do the following (provided you have Homebrew)
brew install gcc5 --without-multilib
and then install xgboost with pip.

Categories