'Trying to draw a partial dependence plot but an error is reported

I tried to build the gbm model and prepared a partial dependence plot of the variables but got an error.

partial(gbm.fit.final,pred.var = "lstat", n.trees = gbm.fit.final$n.trees, grid.resolution = 100)

Error in copy_classes(pred.grid, train) : 
  sapply(x[column.names], class) and sapply(y[column.names], class) are not equal:
  Lengths: 1, 2
  names for target but not for current
  Attributes: < names for current but not for target >
  ....

I'm not sure what's wrong, please fix this problem.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source