I got a figure using LightLgb and Shap force plot but have no data on my figure

Viewed 19

I've been struggling to getting a feature importance of my data, which has 22 indices' variations during certain periods, and total count of typhoons during same period. And this dataframe's dimension is like (30, 22).

    SF 10.7 SOI N12 N3  N34 N4  BEST lv TNA TSA WHWP    ... PWR TPSE    ATSE    AMOL    AMM NTA CAR QBO GIAM    counts
Unnamed: 0                                                                                  
1979    1803.0  1.1 0.16    -0.15   -0.29   -0.24   -0.08   0.42    0.10    -0.81   ... -0.200  0.517   0.514   -0.051  1.96    0.11    -0.20   -19.60  0.68    2
1980    1932.0  -0.0    -0.36   0.08    0.21    0.16    0.64    0.47    -0.08   1.21    ... -0.163  0.781   0.645   0.100   3.64    0.07    0.10    7.33    0.45    3
1981    1569.0  2.0 -0.63   -0.43   -0.46   -0.59   -0.47   0.18    -0.22   -0.80   ... -0.041  -0.190  0.220   -0.066  2.19    -0.07   -0.08   -3.49   0.20    0
1982    1719.0  -1.7    0.13    0.54    0.53    0.45    1.74    -0.15   -0.45   -0.14   ... -0.273  1.468   -0.734  -0.188  -0.30   -0.24   -0.19   -15.94  1.14    3
1983    1386.0  0.1 4.24    1.52    0.54    -0.00   0.82    0.35    -0.45   4.82    ... 0.043   2.425   -0.034  -0.058  1.25    0.14    -0.04   3.12    1.38    3

This is the data i have, sorry for looking not tidy though.

I'd like to get a feature importance of this dataset. So I used a libray Shap but I do not know why I cannot get a exact result from a figure.

This is my codes.

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split

# uplaod dataset
X = pd.read_csv('june_index.csv')
X.set_index('Unnamed: 0', inplace=True)

raw_data = pd.read_csv('jul_aug_TC_sum.csv')
y = raw_data.iloc[30:60, -1]

ind = X.index
y = pd.DataFrame(y.values, index=ind, columns=['counts'])

data = pd.concat([X,y], axis=1)

------------------------------------------------------------

feature_columns = list(data.columns.difference(['counts']))
XX = data[feature_columns]
yy = data['counts']

X_train, X_test, y_train, y_test = train_test_split(XX, yy, test_size = 0.3, random_state = 42)
print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)

------------------------------------------------------------

import lightgbm as lgb
from math import sqrt
from sklearn.metrics import mean_squared_error

lgb_dtrain = lgb.Dataset(data = X_train, label = y_train) # 학습 데이터를 LightGBM 모델에 맞게 변환
lgb_param = {'max_depth' : 10,
             'learning_rate' : 0.01,
             'n_estimators' : 1000,
             'objective' : 'regression'}
lgb_model = lgb.train(params = lgb_param, train_set = lgb_dtrain) # 학습 진행
lgb_model_predict = lgb_model.predict(X_test) # 평가 데이터 예측
print('RMSE : {}' .format(sqrt(mean_squared_error(lgb_model_predict, y_test))))

----------------------------------------------------
explainer = shap.TreeExplainer(lgb_model) <------ THIS IS THE PART OF PROBLEM
shap_values = explainer.shap_values(X_test)

shap.initjs()
shap.force_plot(explainer.expected_value, shap_values[1, :], X_test.iloc[1, :])
shap.force_plot(explainer.expected_value, shap_values, X_test)

this is a result figure

please help me...

0 Answers
Related