Извлечь собственную модель xgboost из модели H2OXGBoostEstimator в Python - PullRequest
0 голосов
/ 27 сентября 2018

Можно ли извлечь собственный файл выбора модели xgboost из модели H2OXGBoostEstimator в Python и прочитать с помощью необработанного API-интерфейса XGBoost Python?Спасибо!

1 Ответ

0 голосов
/ 05 октября 2018

вы можете использовать следующее:

import matplotlib.pyplot as plt
from xgboost import plot_tree

# model is your xgboost model, choose which tree in num_trees and layout direction default if top to bottom, LR is left to right
plot_tree(model, num_trees=0, rankdir='LR') 
plt.show()

здесь приведен полностью воспроизводимый пример, но обратите внимание, что он использует набор данных , найденный в репозитории xgboost, и использует этот пример для создания модели

import numpy as np
import scipy.sparse
import pickle
import xgboost as xgb
import matplotlib.pyplot as plt
from xgboost import plot_tree

### simple example
# load file from text file, also binary buffer generated by xgboost
dtrain = xgb.DMatrix('../data/agaricus.txt.train')
dtest = xgb.DMatrix('../data/agaricus.txt.test')

# specify parameters via map, definition are same as c++ version
param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic'}

# specify validations set to watch performance
watchlist = [(dtest, 'eval'), (dtrain, 'train')]
num_round = 2
bst = xgb.train(param, dtrain, num_round, watchlist)

plot_tree(bst, num_trees=0, rankdir='LR') # bst is your xgboost model, choose which tree in num_trees and layout direction default if top to bottom, LR is left to right
plt.show()
...