Python pickle负载训练模型

时间:2019-01-08 16:32:21

标签: python scikit-learn pickle

我正在尝试将加载的训练模型应用于新的数据集。我腌制和解开模型:

classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
classifier = classifier.fit(features, classes)

saved_pickle_file = open('saved_model.pkl', 'wb')
pickle.dump(classifier, saved_pickle_file)
saved_pickle_file.close()

load_pickle_file = open('saved_model.pkl', 'rb')
loaded_model = pickle.load(load_pickle_file)

但是当我将加载的模型应用于新数据集时,会产生此错误:

loaded_model.predict(new_dataset)

AttributeError: 'function' object has no attribute 'predict'

为什么会这样?

0 个答案:

没有答案