These are the commands I am using in R:

Outcome_factor= factor(train$Outcome) rpart_model= rpart(Outcome_factor~., data=train, method='class',rpart.control(minsplit = 2, cp = 0))

The dataset "train" has the variables: Outcome,Pregnacies, Glucose, Blood Pressure, Skin Thickness, Insulin, BMI, Age, and DiabetesPedigreefunction..

I get the following message: Error in model.frame.default(formula = Outcome_factor ~ ., data = train, : invalid type (list) for variable '(weights)'

I also noticed that this error message disappears if I dont use the repart.control parameter while calling rpart function. Can someone please help me understand why I might be getting this error?

1

There are 1 answers

0
jhon torres On

I had the same issue and solved it including the word "control" prior to the rpart.control() function, using as example the code you provided the solution would be:

rpart_model = rpart(Outcome_factor~., data=train, method='class',
                    control= rpart.control(minsplit = 2, cp = 0))

Please let us know if it works.