为什么LightGBM回归R平方值为负?

2024-10-06 12:17:04 发布

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

根据下面的代码,我得到了一个负r2分值,为什么? 当我试图

in_data_in_leaf=0,
    min_sum_hessian_in_leaf=0.0 this code, r2 score can ben acquired positive and strong but in this time SHAP plot shows all value as a ZERO.

这是一个数据链接:https://github.com/kilickursat/Tunnelling/blob/main/TBM_Performance.xlsx

import pandas as pd
from lightgbm import LGBMRegressor
import shap

# import the data
df = pd.read_excel('TBM_Performance.xlsx') 
df['ROCK_PRO'] = df['UCS(MPa)'] / df['BTS(MPa)']
print(df.shape[0])
# 18

# extract the features and target
X = df[['UCS(MPa)', 'BTS(MPa)', 'Fs(m)', 'Alpha(degree)', 'PI(kN/mm)', 'ROCK_PRO']]
y = df[['ROP(m/hr)']]

# train the model with min_data_in_leaf=20
hyper_params = {
    'task': 'train',
    'boosting_type': 'goss',
    'objective': 'regression',
    'metric': 'mse',
}

model = LGBMRegressor(**hyper_params).fit(X, y)
print(model.predict(X))
# [2.52277776 2.52277776 2.52277776 2.52277776 2.52277776 2.52277776
#  2.52277776 2.52277776 2.52277776 2.52277776 2.52277776 2.52277776
#  2.52277776 2.52277776 2.52277776 2.52277776 2.52277776 2.52277776]

# train the model with min_data_in_leaf=3
hyper_params = {
    'task': 'train',
    'boosting_type': 'goss',
    'objective': 'regression',
    'metric': 'mse',
    'min_data_in_leaf': 3,
}

model = LGBMRegressor(**hyper_params).fit(X, y)
print(model.predict(X))
# [2.21428748 2.21428748 2.21428748 2.68171691 2.36794282 2.37986215
#  2.37986215 2.77942405 2.84938042 2.84938042 2.8104722  2.8104722
#  2.50056257 2.47946274 2.46754341 2.58446466 2.58446466 2.24212594]

explainer = shap.Explainer(model)
shap_values = explainer(X)
shap.plots.waterfall(shap_values[0])

#R2_SCORE = -0.4

enter image description here


Tags: theinimportdfdatamodeltrainparams