在XG Boost回归中如何根据叶的值预测y

时间:2019-07-24 10:51:19

标签: python linear-regression xgboost

我对XG Boost回归还比较陌生,需要帮助了解xg boost模型如何根据python中叶子的值来预测测试数据集上的y值。

我已经建立了XGB回归模型。我已经提供了代码和下面看到的叶子。 One of the trees from the model printed 我的y_train的平均值为0.81。但是,我在叶子中看到的值太小。我已经将基本分数设置为0.0

import numpy as np
import pandas as pd
import csv as csv
from matplotlib import pyplot
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score,KFold
from sklearn.metrics import mean_absolute_error
import matplotlib.pyplot as plt 
from scipy.stats import skew
from collections import OrderedDict
import xgboost
from xgboost import plot_importance

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=123)

best_xgb_model = xgboost.XGBRegressor(colsample_bytree=0.4,base_score=0.0, gamma=0,  learning_rate=0.07, max_depth=3, min_child_weight=10, n_estimators=1000,                                                                reg_alpha=0.75, reg_lambda=0.45, subsample=0.95, seed=42)

y_pred = best_xgb_model.predict(X_test)

from xgboost import plot_tree
plot_tree(best_xgb_model, num_trees= 4, rankdir= 'LR')
plt.rcParams['figure.figsize'] = [60, 60]
plt.show()

0 个答案:

没有答案