错误:nrow(x)== n使用列车在插入中时不为TRUE [英] Error: nrow(x) == n is not TRUE when using Train in Caret
问题描述
我有一个训练集,看起来像
I have a training set that looks like
Name Day Area X Y Month Night
ATTACK Monday LA -122.41 37.78 8 0
VEHICLE Saturday CHICAGO -1.67 3.15 2 0
MOUSE Monday TAIPEI -12.5 3.1 9 1
名称
是结果/因变量。我将名称
,区域
和 Day
转换为因素,我不知道我是否应该是月
和 Night
,它只占整数值1-12和0-1。
Name
is the outcome/dependent variable. I converted Name
, Area
and Day
into factors, but I wasn't sure if I was supposed to for Month
and Night
, which only take on integer values 1-12 and 0-1, respectively.
然后将数据转换为矩阵
ynn <- model.matrix(~Name , data = trainDF)
mnn <- model.matrix(~ Day+Area +X + Y + Month + Night, data = trainDF)
然后我设置调整参数
nnTrControl=trainControl(method = "repeatedcv",number = 3,repeats=5,verboseIter = TRUE, returnData = FALSE, returnResamp = "all", classProbs = TRUE, summaryFunction = multiClassSummary,allowParallel = TRUE)
nnGrid = expand.grid(.size=c(1,4,7),.decay=c(0,0.001,0.1))
model <- train(y=ynn, x=mnn, method='nnet',linout=TRUE, trace = FALSE, trControl = nnTrControl,metric="logLoss", tuneGrid=nnGrid)
但是,我得到错误错误:nrow(x)== n不是真的
为模型< -train
如果我使用 xgboost
而不是 nnet
任何人都知道什么是ca使用这个?
Anyone know whats causing this?
推荐答案
y
应该是一个数字或因子矢量,包含每个样本的结果,而不是矩阵。使用
y
should be a numeric or factor vector containing the outcome for each sample, not a matrix. Using
train(y = make.names(trainDF$Name), ...)
帮助,其中 make.names
修改值,使其成为有效的变量名。
helps, where make.names
modifies values so that they could be valid variable names.
这篇关于错误:nrow(x)== n使用列车在插入中时不为TRUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!