⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accuracy3.py

📁 orange源码 数据挖掘技术
💻 PY
字号:
# Category:    evaluation
# Description: Set a number of learners, split data to train and test set, learn models from train set and estimate classification accuracy on the test set
# Uses:        voting.tab
# Classes:     MakeRandomIndices2
# Referenced:  c_performance.htm

import orange, orngTree

def accuracy(test_data, classifiers):
    correct = [0.0]*len(classifiers)
    for ex in test_data:
        for i in range(len(classifiers)):
            if classifiers[i](ex) == ex.getclass():
                correct[i] += 1
    for i in range(len(correct)):
        correct[i] = correct[i] / len(test_data)
    return correct

# set up the classifiers
data = orange.ExampleTable("voting")
selection = orange.MakeRandomIndices2(data, 0.5)
train_data = data.select(selection, 0)
test_data = data.select(selection, 1)

bayes = orange.BayesLearner(train_data)
tree = orngTree.TreeLearner(train_data)
bayes.name = "bayes"
tree.name = "tree"
classifiers = [bayes, tree]

# compute accuracies
acc = accuracy(test_data, classifiers)
print "Classification accuracies:"
for i in range(len(classifiers)):
    print classifiers[i].name, acc[i]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -