我有一个训练数据集
Out Revolver Ratio Num ...
0 1 0.766127 0.802982 0 ...
1 0 0.957151 0.121876 1
2 0 0.658180 0.085113 0
3 0 0.233810 0.036050 3
4 1 0.907239 0.024926 5
结果变量Out
是二进制的,只取值0或1. Num
不是因素
然后我尝试使用nnet
运行caret
。我想最终尝试nnGrid
,但我只是想确保它先行:
nnTrControl=trainControl(method = "cv", classProbs = TRUE, summaryFunction = twoClassSummary,
number = 2,verboseIter = TRUE, returnData = FALSE, returnResamp = "all")
#nnGrid = expand.grid(.size=c(1,4,7),.decay=c(0,0.001,0.1))
Outf<-factor(training$Out)
model <- train(Outf~ Revolver+Ratio+Num, data=training, method='nnet',
trControl = nnTrControl, metric="logLoss")#, tuneGrid=nnGrid)
我收到错误
Error in train.default(x, y, weights = w, ...) :
At least one of the class levels is not a valid R variable name; This will cause errors when class probabilities are generated because the variables names will be converted to X0, X1 . Please use factor levels that can be used as valid R variable names (see ?make.names for help).
但是,我之前使用过caret
并收到此错误,我使用make.names
解决了这个问题。所以当我尝试以下代替时:
yCat<-make.names(training$Out, unique=FALSE, allow_=TRUE)
mnn <- model.matrix( ~Revolver + Ratio + Num, data = training)
model <- train(y=yCat, x=mnn, method='nnet',
trControl = nnTrControl, metric="logLoss")#, tuneGrid=nnGrid)
然后我收到消息
The metric "logLoss" was not in the result set. ROC will be used instead.
但我不明白为什么不根据logLoss
进行评估?
如果我然后用它来预测测试集
probs<-predict(model, newdata=testSet, type="prob")
我得到了
Error in eval(expr, envir, enclos) : object '(Intercept)' not found
我该如何解决这个问题?