|
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) |
|
|