Error in running GBM




I’m trying to run the GBM.FIT for a data and the error i getting is

"The number of rows in x does not equal the length of y"

I 'm attaching the code below for reference.Can anyone help me out ??



x=spam[,1:57]# predictor variable
y=spam[,58]#response variable

y <- ifelse(spam==“spam”, 0, 1)


model<,y,offset=NULL,distribution = “bernoulli”,n.trees=ntrees,shrinkage =0.01,interaction.depth = 3,n.minobsinnode = 10,nTrain = NULL,verbose = T)


May be the ifelse line is not correct:

Assuming the 58th columnname is “spam”, then code can be:
y <- ifelse(y$spam=="spam", 0, 1)


well the code is correct…the only error i m getting is while running the as that the rows of x and y are not equal, however they are equal as well


Just check that the class of Y is not data.frame

also spam==“spam” will not give the desired results since “spam” is a data.frame


sonu …if you have look at the dataset spam it has variable name spam…wud you mind running the code and then telling any answers


Hi @mudit1712. Sonny is trying to help you, please respect the guidelines.

What you can do simply is, post the first few lines of target “y”. before sending it to It will be clear if indeed there is some unknown error.

Does this seem reasonable?


hey sorry sonny…found out there was some mistake in the code in the ifelse line…sorry if i did sounded offensive…

thanks for the help