简体   繁体   English

如何将分类器升级到最新版本的 scikit-learn

[英]How to upgrade the classifier to the latest version of scikit-learn

I have a big trained TfidfVectorizer dumped with joblib.dump .我有一个训练有素的大 TfidfVectorizer 倾倒了joblib.dump It was created on my laptop with scikit-learn version 0.18.它是在我的笔记本电脑上使用 scikit-learn 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:当我尝试将它放到安装了最新版本 scikit-learn 0.18.1 的服务器上时,我收到以下警告:

/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?有没有一种自然的方法来升级我的 TfidfVectorizer 以防止出现任何问题?

Should I better uninstall scikit-learn 0.18.1 and install version 0.18 to the server instead?我应该更好地卸载 scikit-learn 0.18.1 并将 0.18 版安装到服务器上吗?

是的,您应该在您的服务器上安装与开发相同的版本,最佳实践是使用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.上面的命令应该将您当前版本的 scikit 升级到最新版本。 Depending on what you are doing with the tfidf vectorizer, you may or may not have issues;根据您使用 tfidf 向量化器的操作,您可能会或可能不会遇到问题; 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.因此,最好确保您的服务器和计算机都运行最新的 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.您应该能够通过首先将 sklearn 更新到最新版本,然后使用 joblib.load 加载腌制对象并使用 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) .只需卸载并重新安装最新的 Scikit(或升级到最新版本)。 And then train the model once again and that will generate a new joblib model.然后再次训练模型,这将生成一个新的 joblib 模型。 This will surely work.这肯定会奏效。

you should install the version of scikit that your project use.您应该安装您的项目使用的 scikit 版本。

first uninstall scikit :首先卸载scikit:

pip uninstall scikit-learn

then install correct version like that:然后安装正确的版本:

pip install -v scikit-learn==0.18

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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