# How to reconstruct a scikit-learn predictor for Gradient Boosting Regressor?

I would like to train my datasets in scikit-learn but export the final Gradient Boosting Regressor elsewhere so that I can make predictions directly on another platform.

I am aware that we can obtain the individual decision trees used by the regressor by accessing regressor.estimators[].tree_. What I would like to know is how to fit these decision trees together to make the final regression predictor.

• You can directly save the model to disk and load it on the other platform. Why you want to do this complex exercise. Please explain a bit more in detail Dec 23 '20 at 17:34
• By 'another platform' I mean a software environment other than Python. It is MQL5 used for forex trading. Dec 23 '20 at 22:52

There are two estimators i.e. The initial predictor and the sub-estimators

init_estimator
The estimator that provides the initial predictions. Set via the init argument or loss.init_estimator.
estimators_
ndarray of DecisionTreeRegressor of shape (n_estimators, 1)
The collection of fitted sub-estimators.

Prediction after the first (i.e. init) estimator is controlled by the learning rate.

You can get the prediction as done in the below code -

trees = model.estimators_

x  = x_test.iloc[10,:].values # A sample X to be predicted
y_pred = model.init_.predict(x.reshape(1, -1)) # prediction from init estimator

for tree in trees:
pred = tree[0].predict(x.reshape(1, -1)) # prediction from sub-estimator

y_pred = y_pred + model.learning_rate*pred  # Summing with LR
y_pred

• Interesting. I will test it out tomorrow. So we just use the initial sample repeatedly without having to worry about deviation from y, ie. the gradient? Dec 24 '20 at 10:30
• Not initial sample, it's the "x" to be predicted e.g. x_test. Trees are already fitted. Dec 24 '20 at 11:53
• Great. The figures matched precisely! Dec 25 '20 at 3:32
• You seem to be knowledgeable in this field. I have some other questions. Could you please take a look? datascience.stackexchange.com/questions/87122/… datascience.stackexchange.com/questions/87121/… Dec 25 '20 at 7:33