<jupyter_start><jupyter_text>Import libraries<jupyter_code>import pandas as pd
import numpy as np

from pandas.core.common import SettingWithCopyWarning
import warnings
warnings.simplefilter(action="ignore", category=SettingWithCopyWarning)

import seaborn as sns
from matplotlib import pyplot
import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split, cross_val_score

from sklearn.preprocessing import Normalizer
from sklearn.model_selection import StratifiedKFold
from sklearn.preprocessing import StandardScaler

#classifiers
from sklearn.gaussian_process.kernels import RBF
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.tree import DecisionTreeClassifier
import xgboost as xgb
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import VotingClassifier, StackingClassifier, BaggingClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, ExtraTreesClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

#Prformance metrics
from sklearn import metrics
from sklearn.metrics import roc_curve, auc, roc_auc_score, accuracy_score, confusion_matrix, classification_report
from sklearn.metrics import make_scorer
from sklearn.metrics import accuracy_score
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.metrics import f1_score
from sklearn.model_selection import cross_validate
from sklearn.metrics import plot_roc_curve

#Explainable AI
import shap
%matplotlib inline
plt.rcParams['figure.figsize']=15,10<jupyter_output><empty_output><jupyter_text>Load dataset<jupyter_code>mgh = pd.read_excel('.../mghML.xlsx')
mgh_con = mgh[['KIT', 'KITLG', 'HEART', 'LUNG', 'DIABETES', 'IMMUNO', 'BMI cat',
       'abs_neut_0_cat', 'abs_lymph_0_cat', 'abs_mono_0_cat', 'Age cat',
       'KIDNEY', 'HTN', 'WHO max']]
mgh_con<jupyter_output><empty_output><jupyter_text>Normalize data<jupyter_code>col = mgh_con.drop(['HEART', 'LUNG', 'DIABETES', 'IMMUNO', 'BMI cat', 'abs_neut_0_cat',
       'abs_lymph_0_cat', 'abs_mono_0_cat', 'Age cat',	'KIDNEY',	'HTN','WHO max'], axis=1).columns

sc = StandardScaler()

for i in col:
 
  mgh_con[[i]] = sc.fit_transform(mgh_con[[i]])<jupyter_output><empty_output><jupyter_text>Drop null values<jupyter_code>mgh_con = mgh_con.drop([45, 61, 104, 124, 173, 60, 121, 163, 246])
percent_missing = mgh_con.isnull().sum() * 100 / len(mgh_con)
missing_value_df = pd.DataFrame({'column_name': mgh_con.columns,
                                 'percent_missing': percent_missing})
missing_value_df.loc[missing_value_df['percent_missing']> 0.000]<jupyter_output><empty_output><jupyter_text>Machine learning model<jupyter_code>X = mgh_con.drop(['WHO max'], axis=1)
y = mgh_con['WHO max']
X, X_test, y, y_test = train_test_split( X, y, test_size=0.2, random_state=42)

clf_xgb = xgb.XGBClassifier()

clf_xgb.fit(X, y)
y_pred = clf_xgb.predict(X_test)
plot_roc_curve(clf_xgb, X_test, y_test)<jupyter_output>Function plot_roc_curve is deprecated; Function `plot_roc_curve` is deprecated in 1.0 and will be removed in 1.2. Use one of the class methods: RocCurveDisplay.from_predictions or RocCurveDisplay.from_estimator.<jupyter_text>Explainable AI<jupyter_code>shap.initjs()

shap.Explainer
# build an Exact explainer and explain the model predictions on the given dataset
explainer = shap.TreeExplainer(clf_xgb)
shap_values = explainer.shap_values(X)
shap.summary_plot(shap_values, features=X, feature_names=X.columns )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09227066060443968, 'fraction_numerical': 0.013907461888205403, 'mean_word_length': 7.461538461538462, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '170299', 'license': 'MIT', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1291, 'n_words': 290, 'path': 'ExpainableAImodel.ipynb', 'repo_name': 'Dimstella/Asystems-approach-on-plasma-proteomics-reveals-the-implication-of-KITLG-signaling-in-critical-COVID-', 'size': '3739'}