import nltk

from classifiers.maxent_most_informative_features import most_informative_features
from features.feature_set_builder import get_feature_set

train_set, test_set = get_feature_set("all")
classifier = nltk.MaxentClassifier.train(train_set)
with open("classifier_maxent_all.txt", "w") as f:
    f.write("Accuracy: " + str(nltk.classify.accuracy(classifier, test_set)))
    f.write("\n")
    for k in most_informative_features(classifier, 15):
        f.write(k.split('_')[0] + " " + k.split('_')[-1] + "\n")
Example #2
0
import nltk

from classifiers.decision_tree_most_informative_features import most_informative_features
from features.feature_set_builder import get_feature_set

train_set, test_set = get_feature_set("pos")
classifier = nltk.DecisionTreeClassifier.train(train_set)
features = most_informative_features(classifier, 15)

with open("classifier_decision_tree_pos.txt", "w") as f:
    f.write("Accuracy: " + str(nltk.classify.accuracy(classifier, test_set)))
    f.write("\n")
    for k in features:
        f.write(k.split('_')[0] + "\n")
Example #3
0
import nltk

from features.feature_set_builder import get_feature_set

train_set, test_set = get_feature_set("neg")
classifier = nltk.NaiveBayesClassifier.train(train_set)

with open("classifier_bayes_neg.txt", "w") as f:
    f.write("Accuracy: " + str(nltk.classify.accuracy(classifier, test_set)))
    f.write("\n")
    for k, v in classifier.most_informative_features(15):
        f.write(k.split('_')[0] + "\n")