Explainable AI in Python
Fouad Trad
Machine Learning Engineer




![Image showing that one feature is shuffled where in the original dataset its values were [1, 2, 3, 4] and in the shuffled one they became [4, 2, 1, 3]. The shuffled dataset is fed to the ML model to obtain the shuffled performance.](https://assets.datacamp.com/production/repositories/6745/datasets/8941afd8450944dd95675cf114c800a0de3d511c/PI_2.png)


| GRE Score | TOEFL Score | University Rating | SOP | LOR | CGPA | Chance of Admit | Accept |
|---|---|---|---|---|---|---|---|
| 337 | 118 | 4 | 4.5 | 4.5 | 9.65 | 0.92 | 1 |
| 324 | 107 | 4 | 4 | 4.5 | 8.87 | 0.76 | 1 |
| 316 | 104 | 3 | 3 | 3.5 | 8 | 0.72 | 1 |
| 322 | 110 | 3 | 3.5 | 2.5 | 8.67 | 0.8 | 1 |
| 314 | 103 | 2 | 2 | 3 | 8.21 | 0.45 | 0 |
The data exists in:
X_train, y_train
from sklearn.neural_network import MLPClassifier model = MLPClassifier(hidden_layer_sizes=(10,10))model.fit(X_train, y_train)
from sklearn.inspection import permutation_importanceresult = permutation_importance(model,X_train, y_train,n_repeats=10,random_state=42,scoring='accuracy')print(result.importances_mean)
[0.16213568 0.13831658 0.10575377 0.10522613 0.11741206 0.20072864]
import matplotlib.pyplot as plt
plt.bar(X_train.columns,
result.importances_mean)

import matplotlib.pyplot as plt
plt.bar(X_train.columns,
result.importances_mean)

plt.bar(X_train.columns, np.abs(log_reg.coef_[0]))

Explainable AI in Python