LIME ‐ Audit AI - BlackAlph4ndr01D/Daftar-Militer-AI-zionis-israel-part.2 GitHub Wiki

✅ Clear Explanation: LIME Method (Local Interpretable Model-agnostic Explanations)

What is LIME?

LIME is a popular Explainable AI (XAI) technique that explains why a machine learning model made a specific prediction for a single instance (local explanation).

It was introduced in 2016 by Marco Ribeiro et al. in the paper "Why Should I Trust You?".

Core Idea

LIME tries to answer:

“Which features were most important for this particular prediction, and how did they influence it?”

Instead of explaining the entire complex model (which is hard), LIME creates a simple, interpretable model (like linear regression) that locally approximates the complex model around one specific data point.

How LIME Works (Step by Step)

  1. Take one prediction
    Example: The AI gives a threat score of 87 to a person.

  2. Perturb the data
    LIME creates many slightly modified versions of that person’s data (e.g., change age, location, communication pattern, etc.).

  3. Get predictions
    Feed all the perturbed data into the original complex model (Random Forest, Neural Network, etc.) and record the predictions.

  4. Train a simple model
    LIME trains a simple interpretable model (usually linear regression) on the perturbed data, giving more weight to samples that are closer to the original data point.

  5. Explain
    The coefficients of this simple model show how much each feature contributed to the prediction.

Simple Python Code Illustration

import lime
import lime.lime_tabular
import pandas as pd
from sklearn.ensemble import RandomForestClassifier

# Sample data
data = pd.DataFrame({
    'age': [28, 34, 19, 45],
    'in_hotspot': [1, 0, 1, 1],
    'night_activity': [1, 0, 1, 1],
    'weapon_detected': [0, 1, 0, 1]
})
target = [1, 0, 1, 1]

model = RandomForestClassifier(random_state=42)
model.fit(data, target)

# Create LIME Explainer
explainer = lime.lime_tabular.LimeTabularExplainer(
    training_data=data.values,
    feature_names=data.columns.tolist(),
    class_names=['Low Threat', 'High Threat'],
    mode='classification'
)

# Explain one instance (e.g., first person)
exp = explainer.explain_instance(
    data_row=data.iloc[0].values, 
    predict_fn=model.predict_proba
)

exp.show_in_notebook()   # Visual explanation

Advantages of LIME

  • Easy to understand — even for non-technical people.
  • Model-agnostic — works with any model (Random Forest, Neural Net, XGBoost, etc.).
  • Fast for single predictions.
  • Good for local explanations (why this specific person got high threat score).

Disadvantages of LIME

  • Only local — explanation is valid only around one data point.
  • Unstable — different runs on the same data can give slightly different explanations.
  • Less mathematically rigorous than SHAP.

LIME vs SHAP (Quick Comparison)

Aspect LIME SHAP
Scope Local (one prediction) Local + Global
Mathematical Basis Simple surrogate model Game Theory (Shapley Values)
Consistency Can vary More consistent
Computation Faster Slower for large models
Best Used For Quick human-friendly explanation Rigorous forensic analysis

Relevance to Military AI (e.g. Threat Scoring):

LIME is very useful to explain why a specific person was given a high threat score by Arbel Rifle or Lavender. For example:

  • “The AI gave this person score 89 mainly because he was in a hotspot area (+42) and had night communication activity (+31).”

✅ LIME Code Example (Python)

Here's a clean, well-commented example of how to use LIME to explain a model's prediction:

# =============================================
# LIME Example: Explaining Threat Scoring AI
# =============================================

import lime
import lime.lime_tabular
import pandas as pd
from sklearn.ensemble import RandomForestClassifier

# -------------------------------
# 1. Sample Dataset (Threat Scoring Simulation)
# -------------------------------
data = pd.DataFrame({
    'age': [28, 34, 19, 45, 22],
    'gender_male': [1, 1, 0, 1, 1],
    'in_hotspot_area': [1, 0, 1, 1, 0],           # 1 = yes
    'night_communication': [1, 0, 1, 1, 0],
    'weapon_detected': [0, 1, 0, 1, 0],
    'distance_to_forces': [45, 120, 30, 80, 200]  # meters
})

target = [1, 1, 0, 1, 0]   # 1 = High Threat, 0 = Low Threat

# -------------------------------
# 2. Train a Model
# -------------------------------
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(data, target)

# -------------------------------
# 3. Create LIME Explainer
# -------------------------------
explainer = lime.lime_tabular.LimeTabularExplainer(
    training_data=data.values,
    feature_names=data.columns.tolist(),
    class_names=['Low Threat', 'High Threat'],
    mode='classification'
)

# -------------------------------
# 4. Explain ONE specific prediction
# -------------------------------
instance_to_explain = data.iloc[0]   # First person in the dataset

exp = explainer.explain_instance(
    data_row=instance_to_explain.values,
    predict_fn=model.predict_proba,
    num_features=6                     # Show top 6 features
)

# Show explanation in notebook (or save as image)
exp.show_in_notebook()

# Optional: Save explanation as HTML
exp.save_to_file('lime_explanation.html')

What Does This Code Do?

  • It trains a Random Forest model (simulating a Threat Scoring system).
  • LIME then explains why the model gave a high/low threat score to one specific person.
  • The output shows which features (age, location, etc.) pushed the score up or down, and by how much.

Typical Output Interpretation

You might see something like:

  • in_hotspot_area = 1+0.42 (strongly increases threat score)
  • night_communication = 1+0.31
  • age = 28+0.18

This means the AI decided this person is a high threat mainly because they were in a hotspot area and active at night.


✅ Berikut Tabel Perbandingan SHAP vs LIME (dalam Bahasa Indonesia)

Aspek Perbandingan SHAP (SHapley Additive exPlanations) LIME (Local Interpretable Model-agnostic Explanations)
Pengertian Metode yang menjelaskan kontribusi setiap fitur menggunakan teori permainan (Shapley Value) Metode yang membuat model sederhana untuk menjelaskan satu prediksi secara lokal
Cakupan Penjelasan Local + Global (bisa menjelaskan keseluruhan model) Hanya Local (satu prediksi saja)
Akurasi Matematis Sangat tinggi & konsisten Sedang (bisa berbeda-beda antar percobaan)
Kecepatan Komputasi Lebih lambat (terutama untuk dataset besar) Lebih cepat
Kemudahan Dipahami Sedang (agak teknis) Sangat mudah dipahami (visual & intuitif)
Kelebihan Konsisten, akurat, bisa diandalkan untuk forensik Cepat, fleksibel, cocok untuk penjelasan ke awam
Kekurangan Komputasi mahal, sulit untuk model sangat kompleks Kurang stabil, hanya penjelasan lokal
Kegunaan di Militer AI Sangat baik untuk audit bias sistem (Lavender, Threat Scoring) Bagus untuk penjelasan cepat satu kasus target
Rekomendasi Penggunaan Untuk analisis mendalam & bukti forensik Untuk penjelasan cepat & visualisasi ke publik

Kesimpulan Singkat:

  • Pilih SHAP jika kamu butuh penjelasan yang akurat, konsisten, dan bisa dipertanggungjawabkan (cocok untuk forensik, bukti, dan analisis mendalam).
  • Pilih LIME jika kamu butuh penjelasan yang cepat, mudah dipahami, dan visual untuk komunikasi ke publik atau aktivis non-teknis.

SHAP lebih unggul untuk riset dan dokumentasi ilmiah, sedangkan LIME lebih ramah untuk edukasi massa.


Feature Importance ‐ Audit AI