【发布时间】:2015-06-30 04:29:08
【问题描述】:
这是我的data.frame的一个小样本
naiveBayesPrediction knnPred5 knnPred10 dectreePrediction logressionPrediction correctClass
1 non-bob 2 2 non-bob 0.687969711847463 1
2 non-bob 2 2 non-bob 0.85851872253358 1
3 non-bob 1 1 non-bob 0.500470892627383 1
4 non-bob 1 1 non-bob 0.77762739066215 1
5 non-bob 1 2 non-bob 0.556431439357365 1
6 non-bob 1 2 non-bob 0.604868385598237 1
7 non-bob 2 2 non-bob 0.554624186182919 1
我已经考虑了所有因素
'data.frame': 505 obs. of 6 variables:
$ naiveBayesPrediction: Factor w/ 2 levels "bob","non-bob": 2 2 2 2 2 2 2 2 2 2 ...
$ knnPred5 : Factor w/ 2 levels "1","2": 2 2 1 1 1 1 2 1 2 1 ...
$ knnPred10 : Factor w/ 2 levels "1","2": 2 2 1 1 2 2 2 1 2 2 ...
$ dectreePrediction : Factor w/ 1 level "non-bob": 1 1 1 1 1 1 1 1 1 1 ...
$ logressionPrediction: Factor w/ 505 levels "0.205412826873861",..: 251 415 48 354 92 145 90 123 28 491 ...
$ correctClass : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
然后我尝试使用神经网络来集成它
ensembleModel <- neuralnet(correctClass ~ naiveBayesPrediction + knnPred5 + knnPred10 + dectreePrediction + logressionPrediction, data=allClassifiers[ensembleTrainSample,])
神经元错误[[i]] %*% 权重[[i]]:需要数字/复数 矩阵/向量参数
然后我尝试放入一个矩阵
m <- model.matrix( correctClass ~ naiveBayesPrediction + knnPred5 + knnPred10 + dectreePrediction + logressionPrediction, data = allClassifiers )
contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) 中的错误:
对比只能应用于具有 2 个或更多级别的因素
我认为这一定与只有一个级别的“decistreePrediction”功能有关,但它只能在 2 个可能的结果(bob 或非 bob)中找到一个级别,所以我不知道从那里去哪里.
【问题讨论】:
-
您是否可能不小心将您的
allClassifiers$dectreePrediction重命名为同一个东西(回复:your previous question)?另外,我认为将$logressionPrediction设为一个因素是没有意义的,除非您先将其装箱。 -
alexforrence 感谢您的回复我不明白这个问题,我更新了我的决策树代码,看看它是否有用,如果还有什么有用的,我也可以展示一下。
标签: r neural-network