How to update scikit-learn in Google Colab? - python

I want to use sklearn.metrics plot_confusion_matrix in Google Colab. It comes with the latest stable update of sklearn 0.22.
https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html#sphx-glr-auto-examples-model-selection-plot-confusion-matrix-py
I tried this Make colab use the latest installation of a library
But in the end it shows the version of sklearn is still 0.21.

I uninstalled sklearn from colab like you do in the start of your image and reinstalled it again updating it as it is mentioned in sklearn documentation. The code I used was the following:
!pip uninstall scikit-learn -y
!pip install -U scikit-learn
After I checked if my version was updated with:
import sklearn
sklearn.__version__
'0.24.1'

Make sure to hit Runtime > Restart Runtime

Related

Transformer: Error importing packages. "ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler'"

I am working on a machine learning project on Google Colab, it seems recently there is an issue when trying to import packages from transformers. The error message says:
ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler' (/usr/local/lib/python3.7/dist-packages/torch/optim/lr_scheduler.py)
The code is simple as follow:
!pip install transformers==3.5.1
from transformers import BertTokenizer
So far I've tried to install different versions of the transformers, and import some other packages, but it seems importing any package with:
from transformers import *Package
is not working, and will result in the same error. I wonder if anyone is running into the same issue as well?
Change the torch version in colab by running this command
!pip install torch==1.4.0. Then, It worked for me.
Just change the version of tranformers to the latest one (4.5.1 at this time). That worked in colab.
!pip install transformers
The same issue occurred to me with the PyTorch version after being upgraded.
As for the solution downgrade Pytorch version to 1.4.0.
Use the below command to install
!pip install -q torch==1.4.0 -f https://download.pytorch.org/whl/cu101/torch_stable.html
It's solved a lot of problems with transformers also.
The above from udara vimukthi worked for me after trying a lot of different things, trying to get the code for "Getting started with Google BERT" to work after cloning the gitHub repository locally, so now ALL of the chapter code works while I'm showing my daughter the models.
Operating system - Windows. Running locally with GPU support, using Anaconda environment.
pip install -q --user torch==1.4.0 -f https://download.pytorch.org/whl/cu101/torch_stable.html
then I ran into some more issues and had to install the ipwidgets
pip install ipywidgets
Now it all works, as far as I've gotten. Thanks for the help with the above suggestion it saved me a lot of headaches. :)

Error Arviz not installed Using in Google Colab Pymc3

I want to plot using pm.traceplot(mcmc_trace,['theta']) in Google Colab but getting error:
ImportError: ArviZ is not installed. In order to use plot_trace:
pip install arviz
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
Whereas I have already installed Arviz and and import arviz which works but not able to plot.
Install via pip on Google ColLab will make the plot run of ArviZ again.
!pip install pymc3[plots] -q

How to get back to default tensorflow version on google colab

I did not know that tensorflow and keras were installed by default on the machine used by Google Colab. And I installed my own versions. But it was buggy. So I decided to go back to the previous versions. I did:
!pip install tensorflow==1.6.0
and
!pip install keras==2.1.5
But now, when I do import keras, I get the following error:
AttributeError: module 'tensorflow' has no attribute 'name_scope'
Nota:
I asked a friend to know the default tensorflow and keras versions, and he gave me these:
!pip show tensorflow # 1.6.0
!pip show keras # 2.1.5
So I suspect, my installations were wrong somehow. What can I do so I can import keras again ?
To get back to the default versions, I had to restart the VM.
To do so, just do:
!kill -9 -1
Then, wait 30 seconds, and reconnect.
I got the information by opening an issue on the github repository.

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

Scikit-learn version ambiguity

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

Categories

Resources