2

I'm trying to tune my decision tree in R. I use the tune.rpart function in e1071 package. I have the following code:

fm <- formula(classNames[y_train] ~ AirTemperature + WindSpeed + AtmosphericPressure + 
                SurfaceSolarRadiationDownwards + EnergyPurchaseScaled + Residents)

M.tune <- tune.rpart(fm, data = X_traindf, cp = c(0.001, 0.005,0.01, 0.05, 0.1), na.action=na.pass)

I've already checked, that the length of classNames[y_train] is the same as each of the individual variables in fm. I've set the na.action just in case the data frame contained any NA's. The fm formula works fine if I just use it in the regular rpart fitting. The problem is only in the tune.rpart.

Why do I get the error that the length differs?

Error in model.frame.default(formula, data) : 
  variable lengths differ (found for 'AirTemperature')

0 Answers0