简体   繁体   中英

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?

是的,您应该在您的服务器上安装与开发相同的版本,最佳实践是使用requirements.txt来满足您项目的所有要求,并使用condavirtualenv在您的服务器上安装一个新环境,这将为您节省手动设置这些东西的问题。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM