0

I am using the gbm package for generalized boosted regression models, and would like to be able to extract the coefficients produced for storage in a database.

I am already using R to automatically generate formulas that I can export to a database and store. For example, I have been using Dr. Harrell's lrm package to perform logistic regression, e.g.:

output <- lrm(outcome~predictor1+predictor2,data=dataset) 
cat(output$coefficients)

Is it possible to do this with gbm? I know gbm gives a number of trees linearly combined by weights but is there any possibility that I get each of the tree printed? Or is it perhaps at least possible to do so in the case where interaction.depth=1 (e.g., no interactions are allowed)?

eunivy
  • 1
  • 1
  • 2
    Welcome to SO! The following would make it easier to help you: Provide a small, reproducable example that uses `gbm`. Then explain which part of the object you want to save and/or what you'd like to do with the saved data afterwards. – CL. Aug 25 '15 at 11:22
  • Suggestion: examine `dput(output)` for your `gbm` object. The coefficients are bound to be stored in there somewhere. – MichaelChirico Aug 25 '15 at 12:14
  • @MichaelChirico tried it but there's terribly many outputs.. totally don't know what they mean lol – eunivy Aug 25 '15 at 15:25

2 Answers2

1

GBM's (and other tree-based models) don't have coefficients so there isn't anything to extract. Are you trying to score a database using your gbm object? If so you have two options: 1) Encode each of the gbm trees as SQL queries 2) Pull the data into R, score it, and write it back to the database.

scribbles
  • 4,089
  • 7
  • 22
  • 29
  • actually I am analyzing how variables impact the dependent variable and do prediction in that data so i have to see how the trees are like if it's tree-based.. – eunivy Aug 25 '15 at 15:05
  • At their core, the trees are just a series of if else statements. – scribbles Aug 25 '15 at 15:09
0

You can use the pretty.gbm.tree function to look at the tree structure: https://cran.r-project.org/web/packages/gbm/gbm.pdf

There are more details about the output here: Understanding tree structure in R gbm package

Community
  • 1
  • 1
at888
  • 1
  • 4