寻求橙色专家的帮助。
我有一个大约 600 万行的数据集。为简单起见,我们将只考虑两列。一个是正十进制数,并作为连续值导入。另一个是离散值(0 或 1),其中 1 与 0 的比率为 30:1。
我正在使用分类树(我将其标记为“学习者”)来获取分类器。然后,我尝试对我的数据集进行交叉验证,同时调整压倒性的 30:1 样本偏差。我已经尝试了几种变体来做到这一点,但无论我是否对数据进行分层,都会继续得到相同的结果。
下面是我的代码,我已经注释掉了我尝试过的各种行(使用 True 和 False 值进行分层):
import Orange
import os
import time
import operator
start = time.time()
print "Starting"
print ""
mydata = Orange.data.Table("testData.csv")
# This is used only for the test_with_indices method below
indicesCV = Orange.data.sample.SubsetIndicesCV(mydata)
# I only want the highest level classifier so max_depth=1
learner = Orange.classification.tree.TreeLearner(max_depth=1)
# These are the lines I've tried:
#res = Orange.evaluation.testing.cross_validation([learner], mydata, folds=5, stratified=True)
#res = Orange.evaluation.testing.proportion_test([learner], mydata, 0.8, 100, store_classifiers=1)
res = Orange.evaluation.testing.proportion_test([learner], mydata, learning_proportion=0.8, times=10, stratification=True, store_classifiers=1)
#res = Orange.evaluation.testing.test_with_indices([learner], mydata, indicesCV)
f = open('results.txt', 'a')
divString = "\n##### RESULTS (" + time.strftime("%Y-%m-%d %H:%M:%S") + ") #####"
f.write(divString)
f.write("\nAccuracy: %.2f" % Orange.evaluation.scoring.CA(res)[0])
f.write("\nPrecision: %.2f" % Orange.evaluation.scoring.Precision(res)[0])
f.write("\nRecall: %.2f" % Orange.evaluation.scoring.Recall(res)[0])
f.write("\nF1: %.2f\n" % Orange.evaluation.scoring.F1(res)[0])
tree = learner(mydata)
f.write(tree.to_string(leaf_str="%V (%M out of %N)"))
print tree.to_string(leaf_str="%V (%M out of %N)")
end = time.time()
print "Ending"
timeStr = "Execution time: " + str((end - start) / 60) + " minutes"
f.write(timeStr)
f.close()
注意:似乎存在语法错误(分层与分层),但程序按原样运行,无一例外。另外,我知道文档显示了诸如 stratified=StratifiedIfPossible 之类的内容,但由于某种原因,只有布尔值对我有用。