Spaces:
Sleeping
Sleeping
Create SHAP.py
Browse files
SHAP.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Example: Add SHAP explanation (requires SHAP library)
|
| 2 |
+
import shap
|
| 3 |
+
|
| 4 |
+
class FraudDetection:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.explainer = shap.TreeExplainer(model) # Replace with your model
|
| 7 |
+
|
| 8 |
+
def predict(self, transaction_amount, time_of_day, role, keystroke_speed, error_rate):
|
| 9 |
+
# Your existing prediction logic
|
| 10 |
+
fraud_prob = 0.1 # Replace with your model's prediction
|
| 11 |
+
explanation = "No fraud detected." # Replace with your model's explanation
|
| 12 |
+
G = nx.Graph()
|
| 13 |
+
G.add_node("Transaction")
|
| 14 |
+
G.add_node("User")
|
| 15 |
+
G.add_edge("Transaction", "User")
|
| 16 |
+
image = self.plot_graph(G)
|
| 17 |
+
# Generate SHAP explanation
|
| 18 |
+
shap_values = self.explainer.shap_values(X)
|
| 19 |
+
explanation = "SHAP values: " + str(shap_values)
|
| 20 |
+
return fraud_prob, image, explanation
|