-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (48 loc) · 1.86 KB
/
Copy pathmain.py
File metadata and controls
59 lines (48 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path
from src.llm.llm_explainer import UNAVAILABLE_MESSAGE, generate_explanation_result
from src.monitoring.service import (
DEFAULT_REFERENCE_DATA_PATH,
build_monitoring_result,
build_rca_prompt,
load_reference_data,
simulate_incoming_batch,
)
def main() -> None:
age_threshold = 35
p_threshold = 0.05
reference_df = load_reference_data(DEFAULT_REFERENCE_DATA_PATH)
incoming_df = simulate_incoming_batch(reference_df, age_threshold)
monitoring_result = build_monitoring_result(reference_df, incoming_df, p_threshold)
print("Drift Detection Results:")
print(monitoring_result.display_df.to_string(index=False))
if monitoring_result.drifted_features:
print("\nDrift detected in features:", monitoring_result.drifted_features)
else:
print("\nNo drift detected in monitored features.")
focus_feature = (
monitoring_result.drifted_features[0]
if monitoring_result.drifted_features
else monitoring_result.monitored_columns[0]
)
incoming_source_description = (
f"Simulated batch created by filtering the dataset to rows where age < {age_threshold}."
)
prompt = build_rca_prompt(
monitoring_result.drift_df,
focus_feature,
incoming_source_description,
)
explanation = generate_explanation_result(prompt)
if explanation.available:
print(f"\nLLM Explanation for {focus_feature}:\n{explanation.content}")
else:
print(f"\n{UNAVAILABLE_MESSAGE}")
if explanation.error:
print(f"Details: {explanation.error}")
reports_dir = Path("reports")
reports_dir.mkdir(exist_ok=True)
output_path = reports_dir / "drift_report.csv"
monitoring_result.drift_df.to_csv(output_path, index=False)
print(f"\nDrift report saved to {output_path}")
if __name__ == "__main__":
main()