Explainable AI in Python
Fouad Trad
Machine Learning Engineer
Basic models are:
Complex models are:
Show decision path based on conditions
Show decision path based on conditions
Show decision path based on conditions
Not inherently transparent
Show decision path based on conditions
Not inherently transparent
GRE Score | TOEFL Score | University Rating | SOP | LOR | CGPA | Accept |
---|---|---|---|---|---|---|
337 | 118 | 4 | 4.5 | 4.5 | 9.65 | 1 |
316 | 104 | 3 | 3 | 3.5 | 8.00 | 1 |
314 | 103 | 2 | 2 | 3 | 8.21 | 0 |
from sklearn.tree import DecisionTreeClassifier model = DecisionTreeClassifier(max_depth=5)
model.fit(X_train, y_train)
y_pred = model.predict(y_test)
acc = accuracy_score(y_test, y_pred) print(f"Accuracy of Decision Tree: {acc}")
Accuracy of Decision Tree: 0.82
from sklearn.neural_network import MLPClassifier model = MLPClassifier(hidden_layer_sizes=(1000,1000))
model.fit(X_train, y_train)
y_pred = model.predict(y_test)
acc = accuracy_score(y_test, y_pred) print(f"Accuracy of Neural Network: {acc}")
Accuracy of Neural Network: 0.9
from sklearn.tree export_text rules = export_text(model, feature_names=list(X_train.columns))
print(rules)
|--- CGPA <= 8.34 | |--- GRE Score <= 320.50 | | |--- class: 0
| |--- GRE Score > 320.50 | | |--- class: 1
|--- CGPA > 8.34 | |--- GRE Score <= 319.50 | | |--- class: 1 ...
Apply to particular model
Apply to particular model
Apply to any model
Explainable AI in Python