| import gradio as gr |
| import pandas as pd |
| from sklearn.datasets import make_classification |
| from sklearn.ensemble import RandomForestClassifier |
| from evidently.report import Report |
| from evidently.metrics import DataDriftTable |
|
|
|
|
| def run_monitoring(): |
| |
| X, y = make_classification( |
| n_samples=2000, |
| n_features=5, |
| weights=[0.95, 0.05], |
| random_state=42 |
| ) |
|
|
| df = pd.DataFrame(X, columns=[f"feature_{i}" for i in range(5)]) |
| df["fraud_flag"] = y |
|
|
| |
| model = RandomForestClassifier() |
| model.fit(df.iloc[:1500, :-1], df.iloc[:1500, -1]) |
|
|
| |
| df_prod = df.iloc[1500:].copy() |
| df_prod["feature_0"] = df_prod["feature_0"] * 3 |
|
|
| |
| report = Report(metrics=[DataDriftTable()]) |
| report.run(reference_data=df.iloc[:1500], current_data=df_prod) |
|
|
| |
| report.save_html("monitoring_report.html") |
|
|
| return "monitoring_report.html" |
|
|
|
|
| with gr.Blocks() as demo: |
| gr.Markdown("# Healthcare Fraud Detection Model Monitoring\nThis example shows data drift monitoring using Evidently.") |
| btn = gr.Button("Run Monitoring") |
| file_output = gr.File() |
|
|
| btn.click(fn=run_monitoring, outputs=file_output) |
|
|
| demo.launch(share=True) |