3

I am using the SVM classifier built in NLTK and after training the model, when I try to classify a document, the program terminates with Error during execution, QProcess error: 1 Execution Interrupted

I am using the following code:-

classifier = nltk.classify.svm.SvmClassifier.train(train_features)
for test_record in test_data_list:
    features = extract_features(test_record)
    predict = classifier.classify(features)
    print predict

What could be the reason for the error?

4

2 回答 2

8

nltk.classify.svm已弃用。用于基于支持向量机的分类 SVM 使用nltk.classify.scikitlearn (或scikit-learn直接)。有关更多详细信息NLTK 3.0 文档

您可以使用nltk.classify.scikitlearn如下

import nltk.classify
from sklearn.svm import LinearSVC

classifier = nltk.classify.SklearnClassifier(LinearSVC())
classifier.train(train_features)

for test_record in test_data_list:
    features = extract_features(test_record)
    predict = classifier.classify(features)
    print predict
于 2013-11-08T21:04:09.910 回答
0

nltk 已弃用 svm,您将不得不使用 scikit - 学习使用支持向量分类进行分类

您可以使用 :

import nltk.classify
from sklearn.svm import LinearSVC

classifier = nltk.classify.SklearnClassifier(LinearSVC())
classifier.train(train_set)
from nltk import classify 

accuracy = classify.accuracy(classifier, test_set)
print (accuracy)
于 2019-10-03T04:55:43.770 回答