[R] Error in 'Contrasts<-' while using GBM.

Karteek Pradyumna Bulusu kartikpradyumna92 at gmail.com
Sun Nov 29 04:04:46 CET 2015


Hey,

I was trying to implement Stochastic Gradient Boosting in R. Following is
my code in rstudio:



library(caret);

library(gbm);

library(plyr);

library(survival);

library(splines);

library(mlbench);

set.seed(35);

stack = read.csv("E:/Semester 3/BDA/PROJECT/Sample_SO.csv", head
=TRUE,sep=",");

dim(stack); #displaying dimensions of the dataset



#SPLITTING TRAINING AND TESTING SET

totraining <- createDataPartition(stack$ID, p = .6, list = FALSE);

training <- stack[ totraining,]

test <- stack[-totraining,]



#PARAMETER SETTING

t_control <- trainControl(method = "cv", number = 10);





# GLM

start <- proc.time();



glm = train(ID ~ ., data = training,

             method = "gbm",

             metric = "ROC",

             trControl = t_control,

             verbose = FALSE)



When I am compiling last line, I am getting following error:



Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :

  contrasts can be applied only to factors with 2 or more levels





Can anyone tell me where I am going wrong and How to rectify it. It’ll be
greatful.



Thank you. Looking forward to it.



Regards,
Karteek Pradyumna Bulusu.

	[[alternative HTML version deleted]]



More information about the R-help mailing list