'LIME XAI shows wrong Location of the record in the Dataset
import pandas as pd
import numpy as np
df=pd.read_csv('C:/gag/lpd.csv', engine='python',encoding='unicode_escape')
x = df.iloc[: , 0:-1]#Takes all rows of all columns except the last colum
y = df.iloc[: , -1] # Takes all rows of the last column
from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
x_train = sc_x.fit_transform(x_train)
x_test = sc_x.transform(x_test)
import xgboost as xgb
model=xgb.XGBClassifier(random_state=1,learning_rate=0.55,eval_metric='mlogloss')
model=xgb.XGBClassifier(random_state=1,learning_rate=0.55,eval_metric='mlogloss')
model.fit(x_train, y_train)
y_predxgb = model.predict(x_test)
model.score(x_test,y_test)
0.9973937123309985
explainer=lime_tabular.LimeTabularExplainer(training_data=np.array(x_train ),
class_names=['Affected' , 'Not Affected'],
mode="classification",
feature_names=x_train.columns,
categorical_features=[0])
x_test.iloc[0]
Age of the patient 37.0
Gender of the patient 0.0
Total Bilirubin 8.9
Direct Bilirubin 4.5
Alkphos Alkaline Phosphotase 272.0
Sgpt Alamine Aminotransferase 31.0
Sgot Aspartate Aminotransferase 61.0
Total Protiens 5.8
ALB Albumin 2.0
A/G Ratio Albumin and Globulin Ratio 0.5
**Name: 5302**, dtype: float64
exp=explainer.explain_instance(data_row=x_test.iloc[0],
predict_fn=model.predict_proba)
exp.show_in_notebook(show_table=True)
Here the 'x_test.iloc[0]' the position iloc have given is zero but the result of the explainer shows 5302th record. how to get the correct position record result please help me to solve this problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
