I am trying to perform parameter tunning for gbm using train function in caret package (RStudio) using custom weights argument and receiving an error. The error is
Error in {: task 1674 failed - inputs must be factors
The original dataset consists of 1649 observations and its split into training and test set using a 60/40 split. The tuning parameters are defined using trainControl and a grid for trying different parameter values.
The column weights contains 1 or 10 for yes/no class and is a numeric vector of values in the data frame. The main function call is given below:
model <- train(train[,predictors],train[,class], method="gbm", weights=df$weights, trControl=trainControl obj, tuneGrid=Grid obj, metric="ROC")
df$weights is the vector of weights for each observation. The metric "ROC" is used due to class imbalance. The class was converted into factor containing yes, no values prior to running the model. Also if I do not mentioned the weights argument then the function works fine.
I will apprecite if someone can shed some light on how to overcome this error or if someone has had the same trouble and how they rectified it.
Thanks.