Explainable AI in Python
Fouad Trad
Machine Learning Engineer


| GRE Score | TOEFL Score | University Rating | SOP | LOR | CGPA | Accept |
|---|---|---|---|---|---|---|
| 337 | 118 | 4 | 4.5 | 4.5 | 9.65 | 1 |
| 324 | 107 | 4 | 4 | 4.5 | 8.87 | 1 |
| 316 | 104 | 3 | 3 | 3.5 | 8.00 | 1 |
| 322 | 110 | 3 | 3.5 | 2.5 | 8.67 | 1 |
| 314 | 103 | 2 | 2 | 3 | 8.21 | 0 |
X_train = data.drop(['Accept'], axis=1)
y_train = data['Accept']
from sklearn.tree import DecisionTreeClassifiertree_model = DecisionTreeClassifier() tree_model.fit(X_train, y_train)print(tree_model.feature_importances_)
[0.17936982 0.08878744 0.04388924
0.0532897 0.07130751 0.56335628]
from sklearn.ensemble import RandomForestClassifierforest_model = RandomForestClassifier() forest_model.fit(X_train, y_train)print(forest_model.feature_importances_)
[0.25347149 0.17518662 0.06551317
0.06758647 0.07866478 0.35957747]
import matplotlib.pyplot as plt
plt.barh(X_train.columns,
tree_model.feature_importances_)
plt.title('Feature Importance - Decision Tree')
plt.show()

import matplotlib.pyplot as plt
plt.barh(X_train.columns,
forest_model.feature_importances_)
plt.title('Feature Importance - Random Forest')
plt.show()

Explainable AI in Python