Introduction to explainable AI

Explainable AI in Python

Fouad Trad

Machine Learning Engineer

About me

fouadtrad.jpg

Fouad Trad
  • Machine learning engineer
  • PhD Candidate
  • Specializing in AI for Cybersecurity
LinkedIn

mylinkedin.jpg

Explainable AI in Python

Artificial intelligence

  • AI enables machines to perform human-like tasks

Image showing a human playing chess with a machine.

Explainable AI in Python

The need for explainability

 

Image showing a closed black box system receiving an input and generating an output.

 

  • Black box AI: no understanding of decision-making
Explainable AI in Python

The need for explainability

 

Image showing a open box system receiving an input and generating an output.

 

  • Black box AI: no understanding of decision-making
  • Explainable AI: understand model's inner workings
Explainable AI in Python

Explainability vs. accuracy

  • Basic models are:

    • More explainable
    • Less precise
  • Complex models are:

    • More precise
    • Less explainable

Image showing AI models on a graph from basic models to complex ones (rule-based, linear models, decision trees, k-NN, SVMs, and neural networks), and highlighting that basic models are often more explainable but less precise, while complex models are highly precise but harder to interpret.

Explainable AI in Python

Decision trees vs. neural networks

Decision trees

Show decision path based on conditions

Representation of a decision tree showing how predictions are made based on multiple conditions

Explainable AI in Python

Decision trees vs. neural networks

Decision trees

Show decision path based on conditions

Decision tree for the admission example showing that if a student does not have undergraduate degree, they are rejected. Otherwise, they are only accepted if their grade is higher than 8.5

Explainable AI in Python

Decision trees vs. neural networks

Decision trees

Show decision path based on conditions

Decision tree for the admission example showing that if a student does not have undergraduate degree, they are rejected. Otherwise, they are only accepted if their grade is higher than 8.5

Neural networks

Not inherently transparent

Image showing the structure of neural network: a collection of hidden layers, each having multiple neurons.

Explainable AI in Python

Decision trees vs. neural networks

Decision trees

Show decision path based on conditions

Decision tree for the admission example showing that if a student does not have undergraduate degree, they are rejected. Otherwise, they are only accepted if their grade is higher than 8.5

Neural networks

Not inherently transparent

Image showing the same neural network receiving student features and predicting whether they should be accepted or rejected.

Explainable AI in Python

Student admission prediction

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

 

  • Test scores: GRE and TOEFL
  • University rating
  • SOP: statement of purpose
  • LOR: letter of recommendation
  • CGPA: cumulative grade point average
Explainable AI in Python

Student admission prediction

Decision Tree
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
Neural Network
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
Explainable AI in Python

Decision tree rules

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 ...
Explainable AI in Python

Model-specific vs. model-agnostic techniques

Model-specific

Apply to particular model

Image showing a key designed for a specific lock

Explainable AI in Python

Model-specific vs. model-agnostic techniques

Model-specific

Apply to particular model

Image showing a key designed for a specific lock

Model-agnostic

Apply to any model

Image showing a master key that can open multiple locks

Explainable AI in Python

What's next?

  • Model-specific and model-agnostic techniques
  • Local and global methods
  • Advanced topics:
    • Explainability metrics
    • Unsupervised explainability
    • Generative AI explainability

Logos for the following libraries: SHAP, LIME, and Scikit-learn

Explainable AI in Python

Let's practice!

Explainable AI in Python

Preparing Video For Download...