2

I trained a model using caret package. while predicting using the function is giving an error.

In my model only two variable are in final selection. while predicting on a new dataset(which has only model selected features), giving an error: "object 'Cell' not found"

here is the sample program. please help me on the same.

library(AppliedPredictiveModeling)
data(segmentationOriginal)
train <- subset(segmentationOriginal,Case=='Train')

# Learning function
library(caret);set.seed(125)
cart <- train(Class~.,data=train,method="rpart")

# Plot DT
library(rattle);fancyRpartPlot(print(cart$finalModel))

# Scoring data
library(plyr)
scoredata <- rbind.fill(data.frame(TotalIntench2 = 23000, FiberWidthCh1 = 10, PerimStatusCh1=2),
               data.frame(TotalIntench2 = 50000, FiberWidthCh1 = 10, VarIntenCh4 = 100),
               data.frame(TotalIntench2 = 57000, FiberWidthCh1 = 8, VarIntenCh4 = 100),
               data.frame(FiberWidthCh1 = 8, VarIntenCh4 = 100, PerimStatusCh1=2))
predict(cart,newdata=scoredata)

I knew that it will give you the results; if you have the newdata has the same structure as train. But one thing is concern me: In future predictions why would I collect all other variables information though it is not using for the prediction.

Sivaji
  • 164
  • 9
  • You are using variable `Cell` to construct the model, but not for prediction. You also have a spelling error in `TotalInteCh2` (you have ...ch2) when constructing `scoredata`. Note also that you won't be able to predict if some of the variables are NA. – Roman Luštrik Jan 14 '15 at 10:55

0 Answers0