0

windows 10 rstudio 1.01.136 i have been trying to build model to classify customers which are going to default or not

prediction_test <- predict(train.tree,newdata = test ,type = "class") 

I'm getting the following error

Error in eval(expr, envir, enclos) : object 'Workclass.dummy' not found

so please can anyone tell me how can i remove this error

the variable workclass has only 5 values namely

 as.matrix(prop.table(table(train$Workclass)))
                    [,1]
Federal-gov      0.02948
Never-worked     0.00021
others           0.13885
Private          0.75342
Self-emp-not-inc 0.07804

as I combined others having less proportion into others

to make it more clear I used decision tree

library(rpart)
set.seed(333)
train.tree <- rpart(Income.Group~.,data = train,method = "class",
    control= rpart.control(minsplit = 20,minbucket = 100,maxdepth = 10),
    xval = 5)

I previously got the error

factor Workclass has new levels Local-gov, Self-emp-inc, State-gov, Without-pay

which I corrected by removing variable ID from test data

jatin singh
  • 123
  • 1
  • 1
  • 13
  • What type of object is `train.tree`? The `type = " workclass"` argument doesn't seem right. You don't use use the column names there. So did you want `type = "response"`? It's easier to help you if you provide a proper [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Mar 23 '17 at 17:45
  • i have corrected it ..its class actually and i m trying to predict by using predict function – jatin singh Mar 23 '17 at 17:50
  • @MrFlick i have corrected it ..its class actually and i m trying to predict by using predict function ..please have a look.sorry for the error – jatin singh Mar 23 '17 at 17:56
  • So you are still getting the error about "Workclass.dummy"? I'm not sure the code makes anything more clear because in the sample you are predicting "Income.Group" and I would have expected "Workclass". A fully reproducible example with sample input data would clear things up. – MrFlick Mar 23 '17 at 18:01
  • yes i m still getting error .income .group is depedent variable and i have transformed workclass as some values has less than 5% proportion. dataset is quite big how can i share here having 32561 obs – jatin singh Mar 23 '17 at 18:11
  • @ MrFlick may be you can tell me where can i send you the dataset so you can figure it out. and i have done only data preprocessing on income.group setting it <= 50k as 1 and .50k as 2.rest then predicting it – jatin singh Mar 23 '17 at 18:23
  • You should create a minimal reproducible example like in the link I provided earlier and include it in the question itself. It doesn't have to be your actual data, it just has to produce the same error. – MrFlick Mar 23 '17 at 18:26

0 Answers0