Wrong scikit-learn version installed? - python

I encountered the same
ValueError: scoring must return a number, got [...] (<class 'numpy.core.memmap.memmap'>) instead.
error as discussed in Q34857870.
Based on answers to this question, and my own research, I believe this issue to be fixed in scikit-learn version 0.17.1, though I'm still encountering it. Then I noticed something strange.
conda lists the right version.
$ conda list scikit-learn
packages in environment:
scikit-learn 0.17.1 np111py27_0
My Jupyter notebook gives the right version:
%load_ext watermark
%watermark scikit-learn
scikit-learn 0.17.1
But I get a different version when I check the version within my code:
import sklearn
print(sklearn.__version__)
0.17
I wouldn't think anything of this, except I'm still seeing a bug in 0.17 that should have been fixed in 0.17.1, so I'm wondering whether I'm using the wrong version somehow.
I'm wondering if it is somehow connected to Q30666685.

You probably have multiple versions of scikit learn installed. You can see where it is installed by using
print(sklearn.__file__)
and then simply delete that. In case if you are still having version troubles work within a virtual environment.

Related

TypeError: mannwhitneyu() got an unexpected keyword argument 'method'

I am trying to run a Mann-Whitney test using scipy.stats.mannwhitneyu() with the method argument 'asymptotic' but I am getting a type error.
Though in the documentation this argument and key exist. See link: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mannwhitneyu.html
I upgraded to the latest version but it didn't solve it. Any idea why is this happening and how can I fix it ?
I am getting the same answer for scipy.stats wilcoxon package, although the documentation appeared to state method as a valid parameter.
But, I noticed that the documentation I was using referenced scipy 1.9.0 (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wilcoxon.html), which is not available on Anaconda-Navigator under Python 3.7 or Python 3.10.4.
So, although to my knowledge I thought I had the most recent version of this package installed, I did not. When I go back and look at the documentation for previous versions of this package, it looks like method was not an applicable parameter in older versions of scipy.stats. I am currently using 1.7.3 in my environments, (the most recent version that Anaconda-Navigator will let me install).
So, the limitations of Anaconda Navigator are preventing me from installing the version I actually need for this parameter (1.9.0).
In short: check your GUI limitations and your version of the mannwhitneyu package and see if method is a valid parameter for the specific version you have installed. I'll check back if I find another answer.

UserWarning: Trying to unpickle estimator ExtraTreesClassifier from version 0.22.2.post1 when using version 0.22

I have already trained 85 models using ExtraTreeClassifiers and saved them (TO be honest, I cannot remember the python version or Sci-kit version or Anaconda version I was using while training the models). Due to some disk issues I had to replace hard disk and install OS(Windows10) again and installed Anaconda3 2020.07(Python 3.8.3 64 bit) now.
But now when I try to use this models for prediction purpose I am getting the following warning:
quote
C:\Users\DELL\anaconda3\lib\site-packages\sklearn\base.py:313: UserWarning: Trying to unpickle estimator ExtraTreesClassifier from version 0.22.2.post1 when using version 0.23. This might lead to breaking code or invalid results. Use at your own risk.
So I uninstalled sklearn version 0.23 and installed version 0.22.2. If I do this I get the following warning
quote
C:\Users\DELL\anaconda3\lib\site-packages\sklearn\base.py:313: UserWarning: Trying to unpickle estimator ExtraTreesClassifier from version 0.22 post1 when using version 0.22.2. This might lead to breaking code or invalid results. Use at your own risk.
So I uninstalled sklearn version 0.22.2 and installed version 0.22. If I do this I get the following error:
quote
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'C:\Users\DELL\anaconda3\Lib\site-packages\~-learn\.libs\vcomp140.dll'
Consider using the --user option or check the permissions.
But still it gives me the needed output without any error. If I check the version of sklearn it shows me 0.22 even if there was error installing it.
quote
C:\Users\DELL\anaconda3\lib\site-packages\sklearn\base.py:313: UserWarning: Trying to unpickle estimator ExtraTreesClassifier from version 0.22.2 post1 when using version 0.22. This might lead to breaking code or invalid results. Use at your own risk.
And this process is going on vice-versa(0.22.2 to 0.22 and 0.22 to 0.22.2) if I install or uninstall accordingly.
Though that I have seen various answers regarding this warning on Stackoverflow and worked upon as above, somehow I am unable to fix it and keep on getting this warning again and again or may be I am missing something. Even if I install Anaconda 2019.10 (Python 3.7.4 64 bit) this incompatibility issue still persist. I get the required output but at the back of my mind I am doubtful what if the output generated is not correct because of such warnings and incompatible versions. It is not possible to train all these models again due to time constraints or should I forget about warnings and go ahead and do the predictions with the trained models that I have. Please help. Thanks a lot.
pip install scikit-learn==0.22.2.post1 resolved a similar issue for me.

emcee EnsembleSampler object has no attribute get_chain

I am having trouble accessing the values generated from emcee using the get_chain() method. My code is provided below:
import numpy as np
import emcee
def log_prob(x): return -np.sum(x**2)
p0 = np.array(np.random.randn(12, 1))
sampler = emcee.EnsembleSampler(12, 1, log_prob)
sampler.run_mcmc(p0, 1000)
samples = sampler.get_chain()
When I run this, I get the message AttributeError: 'EnsembleSampler' object has no attribute 'get_chain', and I am not sure why.
I read somewhere online that the get_chain() method was only added in a newer release of emcee, and that it needed to be downloaded from GitHub. If this is the issue, how would I download it from GitHub and ensure it still works with Anaconda (I'm new to Python/GitHub, and I'm not too familiar with how this would be done)?
Any help would be greatly appreciated! Thanks!
As you suspect, this is probably due to having installed an old version of emcee. You can check the version installed with
emcee.__version__
emcee 3 was only a release candidate (instead of an official release) for quite a long time, hence the advise from the blog post you read. It has already been released however, the post is probably nearly a year old at least. You should be able to update to latest emcee and fix your issue with pip
pip install -U emcee
or with conda (which looks like what you are using).
conda install -c conda-forge emcee
see more details on emcee installation with conda on its conda forge page

Issue with loading python matplotlib

This is the error I am getting:
ImportError: /lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not
found (required by
/home/anaconda2/lib/python2.7/site-packages/matplotlib/../../.././libpng16.so.16)
Problem solved. It turned out that my version of libpng was looking for the older version of zlib. I reinstalled(updated) libpng and things are working correctly now.
For my conda environment 4.5.11 (miniconda2), I had the same error `ZLIB_1.2.9' not found.. etc.. /site-packages/matplotlib/../../.././libpng16.so.16). I was not able upgrade, since 1.16.35 was not yet available from conda. For my solution, I kept downgrading libpng to version 1.6.30, and downgraded matplotlib=2.0.2.
I do not like downgrading, however, to keep my operational environment to work, it was necessary. I am trying to automate my deployments and was not happy that I had to manually intervene. I like using conda, since it typically manages the matplotlib install very well, however, it the nature of the beast for open source to have upgrade/downgrade issues.
In conclusion, ZLIB is really not the issue, but what versions of matplotlib you are running. You just have to try upgrading and downgrading packages to get a good fit for matplotlib.
As a reference, I also encountered the same problem, so I report the solution in case it can help someone.
It appeared to be some incompatibilities between pyqtgraph and matplotlib. Importing matplotlib before pyqtgraph solved the problem.
matplotlib version: '3.3.1'
pyqtgraph version: '0.11.0'

could i re-initilize the sklearn library

http://screencloud.net/v/cPBi
I had problem in importing the sklearn neighbors library (called "LSHForest").
the online example here did exactly the same I did when importing the LSHForest, but mine is not working :(
Not really sure what is possibility wrong. do I have to reinstall ubuntu (because i heared that reinstall python under ubuntu environment is not recommended)
thanks for all the great help
You most likely have an older version of scikit-learn. You can check the current version using:
python -c "import sklearn as sk; print sk.__version__"
If you're using 0.16.1, you should be able to import LSHForest.

Categories