{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nfrom sklearn.feature_selection import SelectKBest\nfrom sklearn.feature_selection import chi2\nfrom sklearn.preprocessing import MinMaxScaler\nfrom sklearn.feature_selection import RFE\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.feature_selection import SelectFromModel\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.model_selection import StratifiedKFold\nfrom sklearn.model_selection import train_test_split\nfrom lightgbm import LGBMClassifier\nfrom sklearn.ensemble import AdaBoostClassifier\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.neural_network import MLPClassifier\nfrom sklearn.ensemble import VotingClassifier","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-27T14:30:00.711904Z","iopub.execute_input":"2022-06-27T14:30:00.712379Z","iopub.status.idle":"2022-06-27T14:30:00.721057Z","shell.execute_reply.started":"2022-06-27T14:30:00.712343Z","shell.execute_reply":"2022-06-27T14:30:00.720198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_y_train = pd.read_csv('/kaggle/input/bgudrugchallenge2022/X_y_train.csv')\nX_test = pd.read_csv('/kaggle/input/bgudrugchallenge2022/X_test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:01.137137Z","iopub.execute_input":"2022-06-27T14:30:01.137910Z","iopub.status.idle":"2022-06-27T14:30:06.217798Z","shell.execute_reply.started":"2022-06-27T14:30:01.137852Z","shell.execute_reply":"2022-06-27T14:30:06.216853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. Preprocess","metadata":{}},{"cell_type":"code","source":"y_train = X_y_train['y']\nX_train = X_y_train.iloc[:, X_y_train.columns != 'y']","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:06.220574Z","iopub.execute_input":"2022-06-27T14:30:06.221296Z","iopub.status.idle":"2022-06-27T14:30:06.275773Z","shell.execute_reply.started":"2022-06-27T14:30:06.221245Z","shell.execute_reply":"2022-06-27T14:30:06.274600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# spliting the train data to train set and validation set\nX_train, X_val, y_train, y_val = train_test_split(X_train,y_train,test_size=0.25)\n# check the splited data\nprint(len(X_train))\nprint(len(X_val))\nprint(y_train.value_counts())\nprint(y_val.value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:06.277068Z","iopub.execute_input":"2022-06-27T14:30:06.277731Z","iopub.status.idle":"2022-06-27T14:30:06.393051Z","shell.execute_reply.started":"2022-06-27T14:30:06.277691Z","shell.execute_reply":"2022-06-27T14:30:06.392081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. Feature Selection","metadata":{}},{"cell_type":"code","source":"num_features = 500\nX_norm = MinMaxScaler().fit_transform(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:06.395630Z","iopub.execute_input":"2022-06-27T14:30:06.396302Z","iopub.status.idle":"2022-06-27T14:30:06.562903Z","shell.execute_reply.started":"2022-06-27T14:30:06.396256Z","shell.execute_reply":"2022-06-27T14:30:06.561651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.1 Pearson Correlation","metadata":{}},{"cell_type":"code","source":"def cor_selector(X, y,num_features):\n    cor_list = []\n    feature_name = X.columns.tolist()\n    # calculate the correlation with y for each feature\n    for i in X.columns.tolist():\n        cor = np.corrcoef(X[i], y)[0, 1]\n        cor_list.append(cor)\n    # replace NaN with 0\n    cor_list = [0 if np.isnan(i) else i for i in cor_list]\n    # feature name\n    cor_feature = X.iloc[:,np.argsort(np.abs(cor_list))[-num_features:]].columns.tolist()\n    # feature selection? 0 for not select, 1 for select\n    cor_support = [True if i in cor_feature else False for i in feature_name]\n    return cor_support, cor_feature","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:06.564377Z","iopub.execute_input":"2022-06-27T14:30:06.564762Z","iopub.status.idle":"2022-06-27T14:30:06.573592Z","shell.execute_reply.started":"2022-06-27T14:30:06.564721Z","shell.execute_reply":"2022-06-27T14:30:06.572512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cor_support, cor_feature = cor_selector(X_train, y_train,num_features)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:06.575172Z","iopub.execute_input":"2022-06-27T14:30:06.575987Z","iopub.status.idle":"2022-06-27T14:30:07.092911Z","shell.execute_reply.started":"2022-06-27T14:30:06.575942Z","shell.execute_reply":"2022-06-27T14:30:07.091926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.2 Chi-Squared","metadata":{}},{"cell_type":"code","source":"chi_selector = SelectKBest(chi2, k=num_features)\nchi_selector.fit(X_norm, y_train)\nchi_support = chi_selector.get_support()\nchi_feature = X_train.loc[:,chi_support].columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:07.094325Z","iopub.execute_input":"2022-06-27T14:30:07.094764Z","iopub.status.idle":"2022-06-27T14:30:07.187021Z","shell.execute_reply.started":"2022-06-27T14:30:07.094730Z","shell.execute_reply":"2022-06-27T14:30:07.185828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.3 Recursive Feature Elimination","metadata":{}},{"cell_type":"code","source":"rfe_selector = RFE(estimator=LogisticRegression(), n_features_to_select=num_features, step=20, verbose=5)\nrfe_selector.fit(X_norm, y_train)\nrfe_support = rfe_selector.get_support()\nrfe_feature = X_train.loc[:,rfe_support].columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:30:07.192699Z","iopub.execute_input":"2022-06-27T14:30:07.193526Z","iopub.status.idle":"2022-06-27T14:32:22.655584Z","shell.execute_reply.started":"2022-06-27T14:30:07.193469Z","shell.execute_reply":"2022-06-27T14:32:22.653967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.4 Lasso: SelectFromModel","metadata":{}},{"cell_type":"code","source":"embeded_lr_selector = SelectFromModel(LogisticRegression(penalty=\"l2\"), max_features=num_features)\nembeded_lr_selector.fit(X_norm, y_train)\n\nembeded_lr_support = embeded_lr_selector.get_support()\nembeded_lr_feature = X_train.loc[:,embeded_lr_support].columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:32:22.662322Z","iopub.execute_input":"2022-06-27T14:32:22.663466Z","iopub.status.idle":"2022-06-27T14:32:27.520241Z","shell.execute_reply.started":"2022-06-27T14:32:22.663400Z","shell.execute_reply":"2022-06-27T14:32:27.519218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.5 Tree-based: SelectFromModel","metadata":{}},{"cell_type":"markdown","source":"#### 2.5.1 Random Forest","metadata":{}},{"cell_type":"code","source":"embeded_rf_selector = SelectFromModel(RandomForestClassifier(n_estimators=100), max_features=num_features)\nembeded_rf_selector.fit(X_train, y_train)\n\nembeded_rf_support = embeded_rf_selector.get_support()\nembeded_rf_feature = X_train.loc[:,embeded_rf_support].columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:32:27.523895Z","iopub.execute_input":"2022-06-27T14:32:27.524862Z","iopub.status.idle":"2022-06-27T14:32:37.519398Z","shell.execute_reply.started":"2022-06-27T14:32:27.524795Z","shell.execute_reply":"2022-06-27T14:32:37.518504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 2.5.2 LGBM","metadata":{}},{"cell_type":"code","source":"lgbc=LGBMClassifier(n_estimators=500, learning_rate=0.05, num_leaves=32, colsample_bytree=0.2,\n            reg_alpha=3, reg_lambda=1, min_split_gain=0.01, min_child_weight=40)\n\nembeded_lgb_selector = SelectFromModel(lgbc, max_features=num_features)\nembeded_lgb_selector.fit(X_train, y_train)\n\nembeded_lgb_support = embeded_lgb_selector.get_support()\nembeded_lgb_feature = X_train.loc[:,embeded_lgb_support].columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:32:37.521224Z","iopub.execute_input":"2022-06-27T14:32:37.522004Z","iopub.status.idle":"2022-06-27T14:32:53.936683Z","shell.execute_reply.started":"2022-06-27T14:32:37.521959Z","shell.execute_reply":"2022-06-27T14:32:53.935258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 2.5.3 AdaBoost","metadata":{}},{"cell_type":"code","source":"adaboost = AdaBoostClassifier(n_estimators=500, learning_rate=0.05)\nembeded_adaboost_selector = SelectFromModel(adaboost, max_features=num_features)\nembeded_adaboost_selector.fit(X_train, y_train)\n\nembeded_adaboost_support = embeded_adaboost_selector.get_support()\nembeded_adaboost_feature = X_train.loc[:,embeded_adaboost_support].columns.tolist()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:32:53.938700Z","iopub.execute_input":"2022-06-27T14:32:53.939825Z","iopub.status.idle":"2022-06-27T14:34:50.531897Z","shell.execute_reply.started":"2022-06-27T14:32:53.939775Z","shell.execute_reply":"2022-06-27T14:34:50.530826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.6 All Together","metadata":{}},{"cell_type":"code","source":"feature_name = X_train.columns","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:34:50.533035Z","iopub.execute_input":"2022-06-27T14:34:50.533395Z","iopub.status.idle":"2022-06-27T14:34:50.538243Z","shell.execute_reply.started":"2022-06-27T14:34:50.533364Z","shell.execute_reply":"2022-06-27T14:34:50.537192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_selection_rf_df = pd.DataFrame({'Feature':feature_name, 'Pearson':cor_support, 'Chi-2':chi_support, 'RFE':rfe_support, 'Logistics':embeded_lr_support,\n                                    'Random Forest':embeded_rf_support, 'LightGBM':embeded_lgb_support, 'AdaBoost':embeded_adaboost_support})\n# count the selected times for each feature\nfeature_selection_rf_df['Total'] = np.sum(feature_selection_rf_df, axis=1)\n# display the top 500\nfeature_selection_rf_df = feature_selection_rf_df.sort_values(['Total','Feature'] , ascending=False)\nfeature_selection_rf_df.index = range(1, len(feature_selection_rf_df)+1)\ntop_feature_selection_rf_df = feature_selection_rf_df.head(500)['Feature']\ntop_feature_selection_rf_df","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:34:50.539566Z","iopub.execute_input":"2022-06-27T14:34:50.539980Z","iopub.status.idle":"2022-06-27T14:34:50.573744Z","shell.execute_reply.started":"2022-06-27T14:34:50.539948Z","shell.execute_reply":"2022-06-27T14:34:50.573014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. Transform Data with Top Feature","metadata":{}},{"cell_type":"code","source":"X_train_top_feature_rf = X_train.loc[:,top_feature_selection_rf_df.to_list()]\nX_val_top_feature_rf = X_val.loc[:,top_feature_selection_rf_df.to_list()]\nX_test_top_feature_rf = X_test.loc[:,top_feature_selection_rf_df.to_list()]","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:34:50.574715Z","iopub.execute_input":"2022-06-27T14:34:50.575419Z","iopub.status.idle":"2022-06-27T14:34:50.627417Z","shell.execute_reply.started":"2022-06-27T14:34:50.575385Z","shell.execute_reply":"2022-06-27T14:34:50.626432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. Modeling","metadata":{}},{"cell_type":"code","source":"lvl1= {\n        \"rf1\": RandomForestClassifier(n_estimators=450),\n        \"rf2\": RandomForestClassifier(n_estimators=500),\n        \"rf3\": RandomForestClassifier(n_estimators=550),\n        \"ada1\": AdaBoostClassifier(base_estimator=DecisionTreeClassifier(max_depth=1, min_samples_leaf=1),algorithm=\"SAMME.R\",n_estimators=500, learning_rate=0.5),\n        \"ada2\": AdaBoostClassifier(base_estimator=DecisionTreeClassifier(max_depth=1, min_samples_leaf=1),algorithm=\"SAMME.R\",n_estimators=500, learning_rate=0.9),\n        \"ada3\": AdaBoostClassifier(base_estimator=DecisionTreeClassifier(max_depth=1, min_samples_leaf=1),algorithm=\"SAMME.R\",n_estimators=500, learning_rate=1.2),\n        \"gbc1\": GradientBoostingClassifier(n_estimators=1000, learning_rate=0.5,max_depth=1),\n        \"gbc2\": GradientBoostingClassifier(n_estimators=1000, learning_rate=0.9,max_depth=1),\n        \"gbc3\": GradientBoostingClassifier(n_estimators=1000, learning_rate=1.2,max_depth=1),\n        \"LGBM1\": LGBMClassifier(n_estimators=1000, learning_rate=0.5),\n        \"LGBM2\": LGBMClassifier(n_estimators=1000, learning_rate=0.9),\n        \"LGBM3\": LGBMClassifier(n_estimators=1000, learning_rate=1.2),\n        \"MLP1\" : MLPClassifier(hidden_layer_sizes=(200,), max_iter=1500),\n        \"MLP2\" : MLPClassifier(hidden_layer_sizes=(300,), max_iter=1500),\n        \"MLP3\" : MLPClassifier(hidden_layer_sizes=(400,), max_iter=1500),\n}","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:34:50.628492Z","iopub.execute_input":"2022-06-27T14:34:50.629491Z","iopub.status.idle":"2022-06-27T14:34:50.641253Z","shell.execute_reply.started":"2022-06-27T14:34:50.629448Z","shell.execute_reply":"2022-06-27T14:34:50.639988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"est = [(key,val) for key,val in lvl1.items()]\n\neclf = VotingClassifier(\n    estimators=est,\n    voting='soft')","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:34:50.642630Z","iopub.execute_input":"2022-06-27T14:34:50.643249Z","iopub.status.idle":"2022-06-27T14:34:50.662720Z","shell.execute_reply.started":"2022-06-27T14:34:50.643208Z","shell.execute_reply":"2022-06-27T14:34:50.661872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 4.1 Fit Model","metadata":{}},{"cell_type":"code","source":"eclf.fit(X_train_top_feature_rf,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T14:34:50.664127Z","iopub.execute_input":"2022-06-27T14:34:50.664728Z","iopub.status.idle":"2022-06-27T15:01:40.882318Z","shell.execute_reply.started":"2022-06-27T14:34:50.664696Z","shell.execute_reply":"2022-06-27T15:01:40.881206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 4.2 Predict","metadata":{}},{"cell_type":"code","source":"pred_lvl3 = eclf.predict(X_test_top_feature_rf)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:01:40.883991Z","iopub.execute_input":"2022-06-27T15:01:40.884836Z","iopub.status.idle":"2022-06-27T15:02:27.041760Z","shell.execute_reply.started":"2022-06-27T15:01:40.884779Z","shell.execute_reply":"2022-06-27T15:02:27.040116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 4.3 Save as CSV","metadata":{}},{"cell_type":"code","source":"Y_example = pd.read_csv('/kaggle/input/bgudrugchallenge2022/y_test_submission_example.csv')\nY_example['y_pred'] = pred_lvl3\nprint(Y_example)\nY_example.to_csv('/kaggle/working/my_try_MLP_res.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:02:27.048504Z","iopub.execute_input":"2022-06-27T15:02:27.052192Z","iopub.status.idle":"2022-06-27T15:02:27.150559Z","shell.execute_reply.started":"2022-06-27T15:02:27.052097Z","shell.execute_reply":"2022-06-27T15:02:27.149356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 5. Analyze","metadata":{}},{"cell_type":"markdown","source":"### 5.1 AUC","metadata":{}},{"cell_type":"code","source":"import scikitplot as skplt\nimport matplotlib.pyplot as plt\n\npred_val = eclf.predict(X_val_top_feature_rf)\nmat = []\nfor pred in pred_val:\n    if pred == 0:\n        proba = [1, 0, 0]\n    elif pred == 1:\n        proba = [0, 1, 0]\n    else:\n        proba = [0, 0, 1]\n    mat.append(proba)\n    \nmat = np.array(mat)\nskplt.metrics.plot_roc(y_val, mat)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:02:27.151730Z","iopub.execute_input":"2022-06-27T15:02:27.152257Z","iopub.status.idle":"2022-06-27T15:02:39.748054Z","shell.execute_reply.started":"2022-06-27T15:02:27.152221Z","shell.execute_reply":"2022-06-27T15:02:39.747070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 5.2 Shap","metadata":{}},{"cell_type":"code","source":"# # !pip install shap\nimport shap\neclf_for_shap = LGBMClassifier(n_estimators=1000, learning_rate=0.5)\neclf_for_shap.fit(X_train_top_feature_rf,y_train)\n# Create object that can calculate shap values\nexplainer = shap.TreeExplainer(eclf_for_shap)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:02:39.749636Z","iopub.execute_input":"2022-06-27T15:02:39.750835Z","iopub.status.idle":"2022-06-27T15:03:27.365589Z","shell.execute_reply.started":"2022-06-27T15:02:39.750784Z","shell.execute_reply":"2022-06-27T15:03:27.364445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 5.2.1 Shap Force plots","metadata":{}},{"cell_type":"code","source":"shap.initjs()\ndata_for_pred = X_val_top_feature_rf.iloc[[2]]\nshap_values = explainer.shap_values(data_for_pred)\nshap.force_plot(explainer.expected_value[0], shap_values[0], data_for_pred)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:03:27.366931Z","iopub.execute_input":"2022-06-27T15:03:27.367304Z","iopub.status.idle":"2022-06-27T15:03:27.494690Z","shell.execute_reply.started":"2022-06-27T15:03:27.367272Z","shell.execute_reply":"2022-06-27T15:03:27.493951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shap.initjs()\n##### FORCE PLOT #####\ndata_for_pred = X_val_top_feature_rf.iloc[[4]]\nshap_values = explainer.shap_values(data_for_pred)\nshap.force_plot(explainer.expected_value[0], shap_values[0], data_for_pred)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:03:27.495803Z","iopub.execute_input":"2022-06-27T15:03:27.496800Z","iopub.status.idle":"2022-06-27T15:03:27.628984Z","shell.execute_reply.started":"2022-06-27T15:03:27.496700Z","shell.execute_reply":"2022-06-27T15:03:27.628222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shap.initjs()\n##### FORCE PLOT #####\ndata_for_pred = X_val_top_feature_rf.iloc[[8]]\nshap_values = explainer.shap_values(data_for_pred)\nshap.force_plot(explainer.expected_value[0], shap_values[0], data_for_pred)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:03:27.630076Z","iopub.execute_input":"2022-06-27T15:03:27.630919Z","iopub.status.idle":"2022-06-27T15:03:27.767975Z","shell.execute_reply.started":"2022-06-27T15:03:27.630865Z","shell.execute_reply":"2022-06-27T15:03:27.767180Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 5.2.2 Shap Summary plot top 5","metadata":{}},{"cell_type":"code","source":"# Calculate Shap values\nshap_values = explainer.shap_values(X_val_top_feature_rf)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:03:27.769112Z","iopub.execute_input":"2022-06-27T15:03:27.770026Z","iopub.status.idle":"2022-06-27T15:05:01.387908Z","shell.execute_reply.started":"2022-06-27T15:03:27.769989Z","shell.execute_reply":"2022-06-27T15:05:01.387031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shap.initjs()\nshap.summary_plot(shap_values[0], X_val_top_feature_rf, max_display=5)","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:05:01.389558Z","iopub.execute_input":"2022-06-27T15:05:01.390297Z","iopub.status.idle":"2022-06-27T15:05:01.862804Z","shell.execute_reply.started":"2022-06-27T15:05:01.390247Z","shell.execute_reply":"2022-06-27T15:05:01.862013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 5.2.3 Shap Dependence plot","metadata":{}},{"cell_type":"code","source":"shap.initjs()\nshap.dependence_plot(\"X1146\", shap_values[0], X_val_top_feature_rf, interaction_index=\"X1104\")\nshap.dependence_plot(\"X1104\", shap_values[0], X_val_top_feature_rf, interaction_index=\"X1050\")\nshap.dependence_plot(\"X1050\", shap_values[0], X_val_top_feature_rf, interaction_index=\"X1029\")\nshap.dependence_plot(\"X1029\", shap_values[0], X_val_top_feature_rf, interaction_index=\"X1051\")\nshap.dependence_plot(\"X1051\", shap_values[0], X_val_top_feature_rf, interaction_index=\"X1146\")","metadata":{"execution":{"iopub.status.busy":"2022-06-27T15:12:39.433753Z","iopub.execute_input":"2022-06-27T15:12:39.434232Z","iopub.status.idle":"2022-06-27T15:12:40.969030Z","shell.execute_reply.started":"2022-06-27T15:12:39.434192Z","shell.execute_reply":"2022-06-27T15:12:40.967893Z"},"trusted":true},"execution_count":null,"outputs":[]}]}