我试图将新数据传递给预测函数,而新数据只是110+列中的3个被填充,我得到了错误:
eval(expr,envir,enclos)中的错误:找不到对象'Cell'
虽然列“Cell”存在,但下面是我的R脚本:
library("AppliedPredictiveModeling")
library("ElemStatLearn")
library("pgmm")
library("rpart")
library("gtools")
library("caret")
# load data
data(segmentationOriginal)
# Subset the data to a training set and testing set based on
# the Case variable in the data set.
training <- segmentationOriginal[which(segmentationOriginal$Case ==
"Train"), ]
testing <- segmentationOriginal[which(segmentationOriginal$Case ==
"Test"), ]
# Set the seed to 125 and fit a CART model with the rpart
# method using all predictor variables and default caret
# settings.
set.seed(125)
modFit <- train(Class ~ ., method = "rpart", data = training)
modFit$finalModel
# use new values to predict , TotalIntench2 = 23,000;
# FiberWidthCh1 = 10; PerimStatusCh1=2
# create new data frame based on old data frame columns, this
# will contain new data
training1 <- training[0, ]
# create data frame with test values
newdata = data.frame(TotalIntench2 = 50000, FiberWidthCh1 = 10,
VarIntenCh4 = 100)
# use gtools package smartbind()
training1 <- training1[nrow(training1) + 1, ]
training1 <- smartbind(training1, newdata)
# remove initial empty row
training1[-c(1), ]
# inspect
training1[1, 0]
predict(modFit, newdata = training1[1, 0])
如何将填充了部分列的新数据传递给predict()函数?
由于