繁体   English   中英

在Python 3.5中取消StandardScaler(从Python 2.7中转储)

[英]Unpickling StandardScaler (dumped from Python 2.7) in Python 3.5

我在Python 2.7中使用https://github.com/inspirehep/magpie训练了多标签分类模型。

现在我试图在Python 3.5中移植相同的东西。
要移植,需要将Word2Vec Embedding,Scaler和Keras模型移植到Python 3.5。

单词嵌入和Keras模型移植得很好。

我正在使用StandardScaler。我已经在Python 2.7中腌制它并在Python 3.5中将其取消。解开可以很好。

当我在Python 3.5中运行预测时,我得到以下错误:

sklearn.exceptions.NotFittedError:此StandardScaler实例尚未安装。 在使用此方法之前,使用适当的参数调用'fit'。

Python 2.7:

scaler_path = 'path to file ......'
pickle.dump(scaler_obj, open(scaler_path, 'wb'))

Python 3:

from sklearn.preprocessing import StandardScaler
scaler_path = 'path to file ......'
loaded_scaler = pickle.load(open(scaler_path, 'rb'),encoding='bytes')

sklearn.exceptions.NotFittedError:此StandardScaler实例尚未安装。 在使用此方法之前,使用适当的参数调用'fit'。

我尝试过使用joblib转储并加载它工作正常。

另外,我在Python 2中单独挑选了StandardScaler的4个属性 - mean_,scale_,var_和n_samples_seen_。

然后在Python 3中取消它们,它工作正常。

暂无
暂无

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

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