报错:cannot import name joblib from sklearn.externals

  • 在机器学习中,有时需要保存或加载模型,大多数文章提到的方法总结为:
from sklearn.externals import joblib
joblib.dump(clf, 'model.pkl',compress=3)
clf = joblib.load('model.pkl')
  • 但是报错
cannot import name 'joblib' from 'sklearn.externals'
  • 后来发现是Scikit-learn版本问题(多数文章发布时间较久)。原本安装的是0.23.1,报错如上,尝试安装0.20.4后,可以正常 from sklearn.externals import joblib,安装0.21.3后,报错如下
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
  • 也就是说0.21版本以下可以使用sklearn.externals.joblib,新版本需要pip install joblib
  • Scikit-learn版本查看

你可能感兴趣的:(报错:cannot import name joblib from sklearn.externals)