Scikit-learn version ambiguity - python

I have anaconda 2.7 for Windows 7, 64 bit. I wanted to upgrade my scikit-learn version from 0.15 to 0.16.1 but I had some connection problems so I could not follow the guide here: http://scikit-learn.org/dev/install.html#id1 (I tried several times...) . So I used scikit-learn-0.16.1.win-amd64-py2.7.exe (md5) downloaded from https://pypi.python.org/pypi/scikit-learn/0.16.1.
When I go to check the version of scikit learn in spider using the code:
import sklearn
sklearn.__version__
I read the exact version, that is: '0.16.1' but if I try to use:
from sklearn import cross_validation
I have the following error:
ImportError: cannot import name check_arrays
that means that actually, it doesn't use the version 0.16.1!
So how can I solve? I tried to unistall and install again but it is the same. Since I have network restriction I can't access to the web using the command windows.
Thank you

You can't upgrade a package installed with anaconda with pip. Just do conda update scikit-learn, see the installation docs

Related

Virtualenv for project started giving error for sklearn

I created vritualenv for my project A. I ran the same project A after long time.
I was using same virtualenv for other projects as well ,so depending upon other requirements I have installed other libraries as well.
Now when I running project It gives me sklearn, which was working fine earlier.
What can be the reason now it gives import error with sklearn package?
Since you are using the code after a long time, I suspect your old code is outdated.
You can actually use import joblib directly instead of doing it using sklearn.externals, since it is deprecated in the latest version of scikitlearn.
DeprecationWarning: sklearn.externals.joblib is deprecated in 0.21 and will be removed in 0.23. Please import this functionality directly from joblib, which can be installed with: pip install joblib.
You might want to run this first:
pip install joblib

I can't import sklearn modules anymore

Previously sklearn worked without a hitch. Since yesterday however, I receive the error message
'cannot import name 'logger'' , when I try to import a sklearn module (originally RobustScaler, but it happens for all sklearn modules now.) error message.
My sklearn version is 0.21.3 and I've tried to update the module (Requirements were already up-to-date) and to uninstall and then reinstall the module. This did not work either.
Your help would be appreciated!
Regards,
RM
EDIT: I solved it. I had to upgrade the joblib module (Through the command prompt). My former version was joblib 0.12.5 and my new version is joblib 0.13.2. The update command was pip install -U joblib.
check if you use many environments. For example under Anaconda, you can create different env (ex. Python 3.7 or 2.6).

Cannot load scikit-learn

When I try to import sklearn, I get the following error message:
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
(In English: The specified module was not found)
I'm working on Windows 10, 64-Bit. I'm using Python 3.6.1. (and no other version), Anaconda and PyCharm. I installed scikit-learn using
conda install scikit-learn
and I can find it in
conda list
as well as in File | Settings | Project Interpreter with version 0.19.1. I also have numpy 1.13.3 and scipy 1.0.0.
I know this error message has been discussed multiple, but none of these discussions could help me ...
I tried uninstalling and re-installing numpy, scipy and scikit-learn. I also tried installing scikit-learn using pip.
If I randomly try to load other packages, that are in my conda list, they all work perfectly fine, but not scikit-learn.
I don't even know where my error is. Can anyone give me a hint in the right direction, or a suggestion what I could try?
Thanks!
Have you tried to import sklearn directly from a Python interpreter ?
Also, try to check in your Project Settings that sklearn is recognized as a package of the Python interpreter associated (Settings --> Project --> Project Interpreter)
I was having the same problem. The version of Sklearn was 0.14.1 and when I did a py -3.6 -m pip install --upgrade scipy I got the message that the version I have is current. But sklearn was not recognized from within Jupyter or from the Idle environment. So I went to the site https://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn, downloaded the correct .whl file, and installed it. Now I can import it.
By the way, to use scikit-learn, you will need both numpy and mkl.

How to upgrade the classifier to the latest version of scikit-learn

I have a big trained TfidfVectorizer dumped with joblib.dump.
It was created on my laptop with scikit-learn version 0.18. When I'm trying to put it to my server where the newest version of scikit-learn 0.18.1 is installed I'm getting warned with the following:
/usr/local/lib/python2.7/dist-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator TfidfTransformer from version 0.18 when using version 0.18.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
/usr/local/lib/python2.7/dist-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator TfidfVectorizer from version 0.18 when using version 0.18.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
Is there a natural way to upgrade my TfidfVectorizer to prevent any problems?
Should I better uninstall scikit-learn 0.18.1 and install version 0.18 to the server instead?
Yes you should install the same version on your server as you used for development, best practice is to use a requirements.txt for all the requirements of your project and install a new environment on your server using conda or virtualenv, this will save you the problems of manually setting this stuff up.
This link gives you instructions on how to upgrade.
pip install -U scikit-learn
The above command should upgrade whatever your current version of scikit is to the latest version. Depending on what you are doing with the tfidf vectorizer, you may or may not have issues; I would recommend staying updated with new releases. So, you would be better off making sure your server and computer both run the latest sci-kit.
You should be able to circumvent this problem by first updating sklearn to the latest version, then loading the pickled objects with joblib.load and dumping it with joblib.dump. When I've done this, I no longer receive a warning.
Just uninstall and reinstall the latest Scikit (or upgrade to the latest version) .
And then train the model once again and that will generate a new joblib model. This will surely work.
you should install the version of scikit that your project use.
first uninstall scikit :
pip uninstall scikit-learn
then install correct version like that:
pip install -v scikit-learn==0.18

Xgboost package on mac

I am trying to use Xgboost but facing problems in installation.
i am using mac and I use python notebook jupyter for the same. I opened the command line and used pip install xgboost and it got installed successfully but when I try to use it in my code by writing import xgboost as xg then I get ImportError: No module named xgboost
Can anyone help me?
It may come from the fact that you have two (or more) python environments. A hacky solution is to install it within Jupyter Notebook (note the '!'):
!pip install xgboost

Categories

Resources