MAINT refactor gradient boosting code

Fixes gh-3790