我在 python 中使用了 maxent 分类器并制作了一个模型分类器。我不知道我是否正确地制作了模型。因为有错误,但是模型仍然可以进行分类,但结果仍然不如预期。
from nltk.classify import MaxentClassifier
#MaxEnt_classifier = MaxentClassifier
#MaxEnt_classifier.fit(features_train_transformed,y_train)
MaxEnt_classifier =linear_model.LogisticRegression(C=1,solver ='saga',penalty = 'l2',max_iter = 50000)
MaxEnt_classifier.fit(features_train_transformed,y_train)
#Evaluate the model on the training data set
from sklearn.metrics import classification_report,confusion_matrix, accuracy_score
predictions_MaxEnt = MaxEnt_classifier.predict(features_train_transformed)
print(classification_report(y_train ,predictions_MaxEnt ))
print('Confusion Matrix: \n',confusion_matrix(y_train,predictions_MaxEnt))
print()
print('Accuracy: ', accuracy_score(y_train,predictions_MaxEnt))
import pickle
# def save(vectorizer, classifier):
# '''
# save classifier to disk
# '''
with open('model(indo)_30.pkl', 'wb') as file:
pickle.dump((vectorizer, MaxEnt_classifier), file)
def load():
'''
load classifier from disk
'''
with open('model(indo)_30.pkl', 'rb') as file:
vectorizer, clf, svm = pickle.load(file)
return vectorizer, clf, svm
vectorizer, MaxEnt_classifier = load()
print('\nPerform a test')
df = pd.read_csv('hasil_labelling_dataLatih(1).csv') #read the CSV file
data = df["Labeled Data"]
#data_label = df["label"]
tweet_input_transformed = vectorizer.transform(data)
#NB_prediction = NB_classifier.predict(tweet_input_transformed)
#SVM_prediction = SVM_Clasifier.predict(tweet_input_transformed)
predictions_MaxEnt = model.predict(tweet_input_transformed)
这是错误(我知道我做错了,请链接到 Maxent 的工作原理)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-532749b3090b> in <module>
----> 1 vectorizer, MaxEnt_classifier = load()
2 print('\nPerform a test')
3 df = pd.read_csv('hasil_labelling_dataLatih(1).csv') #read the CSV file
4 data = df["Labeled Data"]
5 #data_label = df["label"]
<ipython-input-11-02129d8d7ca0> in load()
4 '''
5 with open('model(indo)_30.pkl', 'rb') as file:
----> 6 vectorizer, clf, svm = pickle.load(file)
7 return vectorizer, clf, svm
ValueError: not enough values to unpack (expected 3, got 2)