我在Python2.7中使用https://github.com/inspirehep/magpie训练了多标签分类模型。
现在,我正尝试用Python3.5进行移植。
要进行移植,需要将Word2Vec嵌入、Scaler和Keras移植到Python3.5。
单词嵌入和Keras模型移植得很好。
我正在使用StandardScaler.I,我在Python2.7中对它进行了腌制,在Python3.5中将其解泡化,这样就可以了。
当我在Python3.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”。
发布于 2019-07-25 05:28:52
我试过使用joblib转储并加载它,运行良好。
另外,我还分别在Python2中对StandardScaler - mean_、scale_、var_和n_samples_seen_的4个属性进行了筛选。
然后在Python 3中解锁它们,它可以很好地工作。
https://stackoverflow.com/questions/55830995
复制相似问题