如何从XG-boost回归中的叶值预测y

2024-04-19 20:23:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我对XG boost回归比较陌生,需要帮助理解XG boost模型如何从python中的叶子值预测测试数据集上y的值。你知道吗

我建立了一个XGB回归模型。我已经提供了下面的代码和叶子。One of the trees from the model printed 我的火车平均值是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()

Tags: fromtestimportmodelplotastrainplt