当前位置: 首页>>代码示例>>Python>>正文


Python classify.accuracy方法代码示例

本文整理汇总了Python中nltk.classify.accuracy方法的典型用法代码示例。如果您正苦于以下问题:Python classify.accuracy方法的具体用法?Python classify.accuracy怎么用?Python classify.accuracy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.classify的用法示例。


在下文中一共展示了classify.accuracy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: demo

# 需要导入模块: from nltk import classify [as 别名]
# 或者: from nltk.classify import accuracy [as 别名]
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) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:34,代码来源:svm.py

示例2: evaluate

# 需要导入模块: from nltk import classify [as 别名]
# 或者: from nltk.classify import accuracy [as 别名]
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))) 
开发者ID:PacktPublishing,项目名称:Mastering-Machine-Learning-for-Penetration-Testing,代码行数:5,代码来源:SpamDetection_NLTK.py


注:本文中的nltk.classify.accuracy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。