【发布时间】:2016-12-07 09:51:02
【问题描述】:
我尝试使用 python 包“Orange”进行交叉验证。 这个库看起来很不错,但我有一些问题。
对于版本信息,我使用 Python 2.7 和 Orange 2.7.8。 我的任务很简单。 我想通过交叉验证来验证模型,包括 (1) 数字属性的离散化和 (2) 特征选择。
如您所知,在交叉验证循环中处理离散化和特征选择非常重要。换句话说,对于每个交叉验证循环,(1) 仅离散化训练数据,并对测试数据使用相同的 binning cut;(2) 从训练数据中获取重要特征,并将这些特征用于测试数据。
在研究了 Orange 之后,我编写了以下脚本。
import Orange, orange, orngDisc, orngTest, orngStat, orngFSS
data = Orange.data.Table("test.tab") # has numeric, discrete features
nb = Orange.classification.bayes.NaiveLearner()
dBayes = orngDisc.DiscretizedLearner(nb, method=Orange.feature.discretization.Entropy(), name="disc nb")
# feature selection (three important features based on information gain)
fss = orngFSS.FilterBestN(n=3, measure=Orange.feature.scoring.InfoGain())
fBayes = orngFSS.FilteredLearner(dBayes, filter=fss, name="nb & fss")
learners = [nb, dBayes, fBayes]
results = orngTest.crossValidation(learners, data, folds=10, storeClassifiers=1, storeExamples=1)
# print accuracy for the three models (no errors in this block!)
print "\nLearner Accuracy #Atts"
for i in range(len(learners)):
print "%-15s %5.3f %5.2f" % (learners[i].name, orngStat.CA(results)[i], natt[i])
简而言之,数据集(代码中的“数据”)包含数字和离散特征,我想做离散化(基于熵),然后在交叉验证过程中进行特征选择(基于信息增益的前 3 个特征) .
但是,error 表示在计算数字特征的信息增益时发生了错误。我认为特征选择是在离散化之前处理的。 我认为一些小的修改是必要的,但在 web 上的 Orange 上没有很多示例......而且我对修改没有明显的想法。
你能给我一些修改的积分吗? 谢谢。
【问题讨论】:
标签: python cross-validation orange discretization