Python nltk.classify.accuracy() Examples
The following are 2
code examples of nltk.classify.accuracy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
nltk.classify
, or try the search function
.
Example #1
Source File: SpamDetection_NLTK.py From Mastering-Machine-Learning-for-Penetration-Testing with MIT License | 6 votes |
def evaluate(training, tesing, classifier): print ('Training Accuracy is ' + str(classify.accuracy(classifier,train_set))) print ('Testing Accuracy i ' + str(classify.accuracy(classifier,test_set)))
Example #2
Source File: svm.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def demo(): def gender_features(word): return {'last_letter': word[-1], 'penultimate_letter': word[-2]} from nltk.classify import accuracy from nltk.corpus import names import random names = ([(name, 'male') for name in names.words('male.txt')] + [(name, 'female') for name in names.words('female.txt')]) import random random.seed(60221023) random.shuffle(names) featuresets = [(gender_features(n), g) for (n,g) in names] train_set, test_set = featuresets[500:], featuresets[:500] print '--- nltk.classify.svm demo ---' print 'Number of training examples:', len(train_set) classifier = SvmClassifier.train(train_set) print 'Total SVM dimensions:', len(classifier._svmfeatureindex) print 'Label mapping:', classifier._labelmapping print '--- Processing an example instance ---' print 'Reference instance:', names[0] print 'NLTK-format features:\n ' + str(test_set[0]) print 'SVMlight-format features:\n ' + str(map_instance_to_svm(test_set[0], classifier._labelmapping, classifier._svmfeatureindex)) distr = classifier.prob_classify(test_set[0][0]) print 'Instance classification and confidence:', distr.max(), distr.prob(distr.max()) print '--- Measuring classifier performance ---' print 'Overall accuracy:', accuracy(classifier, test_set)