File size: 648 Bytes
aa35b87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import pandas as pd
from datetime import datetime

def init_log():
    return pd.DataFrame(columns=[
        "Timestamp", "Patient_ID", "Model", "Prediction", "Top_Features", "Explanation"
    ])

def log_explanation(df_log, patient_id, model_name, prediction, shap_summary, explanation):
    timestamp = datetime.now().isoformat()
    new_log = {
        "Timestamp": timestamp,
        "Patient_ID": patient_id,
        "Model": model_name,
        "Prediction": round(float(prediction), 4),
        "Top_Features": shap_summary,
        "Explanation": explanation
    }
    return pd.concat([df_log, pd.DataFrame([new_log])], ignore_index=True)