Skip to content

Commit a613048

Browse files
committed
feat: simplify structured report with model-specific details (#808)
1 parent 6470dd6 commit a613048

8 files changed

Lines changed: 509 additions & 262 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,14 @@ Each call creates/updates:
493493
<results_path>/report_structured.json
494494
```
495495

496-
Use the `model_details` argument to control markdown verbosity:
496+
Use `model_name` to display detailed metrics for one selected model:
497497

498498
```python
499-
compact = automl.report_structured(model_details=False)
500-
detailed = automl.report_structured(model_details=True)
499+
compact = automl.report_structured()
500+
detailed = automl.report_structured(model_name="3_Linear")
501501
```
502502

503-
The detailed markdown includes per-model metric tables, fairness details (if used), and feature importance summaries when importance files are available.
503+
When `model_name` is provided, the markdown includes detailed metrics, fairness details (if used), and feature importance summaries for that model.
504504

505505
# Installation
506506

examples/scripts/report_structured_classification.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
"""
2+
Example: structured report for binary classification.
3+
4+
What this script does:
5+
- Trains AutoML on synthetic classification data.
6+
- Prints the compact structured report (leaderboard + global feature summary).
7+
- Selects one model name from the leaderboard and prints detailed report output
8+
for that single model with `report_structured(model_name=...)`.
9+
10+
Why this helps:
11+
- The compact report is easy to inspect in notebooks and by LLMs.
12+
- The on-demand model details keep output short unless deeper analysis is needed.
13+
"""
14+
115
import os
216

317
from sklearn.datasets import make_classification
@@ -24,15 +38,22 @@ def main():
2438
)
2539
automl.fit(X, y)
2640

27-
print("\n=== report_structured(model_details=False) ===\n")
28-
print(automl.report_structured(model_details=False))
41+
print("\n=== report_structured() ===\n")
42+
print(automl.report_structured())
2943

30-
print("\n=== report_structured(model_details=True) ===\n")
31-
print(automl.report_structured(model_details=True))
32-
33-
payload = automl.report_structured(format="dict", model_details=False)
44+
payload = automl.report_structured(format="dict")
3445
print("\nTop-level keys:", sorted(payload.keys()))
35-
print("Number of models in report:", len(payload.get("models", [])))
46+
selected_model_name = None
47+
leaderboard = payload.get("leaderboard", [])
48+
if len(leaderboard) > 1:
49+
selected_model_name = leaderboard[1].get("name")
50+
elif leaderboard:
51+
selected_model_name = leaderboard[0].get("name")
52+
print("Selected model:", selected_model_name)
53+
54+
if selected_model_name:
55+
print(f"\n=== report_structured(model_name='{selected_model_name}') ===\n")
56+
print(automl.report_structured(model_name=selected_model_name))
3657

3758
report_path = os.path.join(results_path, "report_structured.json")
3859
print("Structured report JSON:", report_path)

examples/scripts/report_structured_fairness.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
Example: structured report for fairness-aware classification.
3+
4+
What this script does:
5+
- Trains AutoML with sensitive features and fairness constraints.
6+
- Prints the compact structured report output.
7+
- Selects one model from leaderboard and prints detailed output for that model.
8+
9+
Why this helps:
10+
- Keeps default report concise.
11+
- Allows targeted fairness/metrics inspection only for a chosen model.
12+
"""
13+
114
import os
215

316
import pandas as pd
@@ -37,16 +50,22 @@ def main():
3750
)
3851
automl.fit(X, y, sensitive_features=sensitive_features)
3952

40-
print("\n=== report_structured(model_details=False) ===\n")
41-
print(automl.report_structured(model_details=False))
53+
print("\n=== report_structured() ===\n")
54+
print(automl.report_structured())
4255

43-
print("\n=== report_structured(model_details=True) ===\n")
44-
print(automl.report_structured(model_details=True))
45-
46-
payload = automl.report_structured(format="dict", model_details=False)
56+
payload = automl.report_structured(format="dict")
4757
print("\nTop-level keys:", sorted(payload.keys()))
48-
print("Number of models in report:", len(payload.get("models", [])))
49-
print("Fairness summary available:", payload.get("fairness_summary") is not None)
58+
selected_model_name = None
59+
leaderboard = payload.get("leaderboard", [])
60+
if len(leaderboard) > 1:
61+
selected_model_name = leaderboard[1].get("name")
62+
elif leaderboard:
63+
selected_model_name = leaderboard[0].get("name")
64+
print("Selected model:", selected_model_name)
65+
66+
if selected_model_name:
67+
print(f"\n=== report_structured(model_name='{selected_model_name}') ===\n")
68+
print(automl.report_structured(model_name=selected_model_name))
5069

5170
report_path = os.path.join(results_path, "report_structured.json")
5271
print("Structured report JSON:", report_path)

examples/scripts/report_structured_regression.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
Example: structured report for regression.
3+
4+
What this script does:
5+
- Trains AutoML on synthetic regression data.
6+
- Prints compact structured report output.
7+
- Selects one model from the leaderboard and prints on-demand details for that model.
8+
9+
Why this helps:
10+
- Shows the default short report flow.
11+
- Demonstrates how to inspect one model deeply without printing all model details.
12+
"""
13+
114
import os
215

316
from sklearn.datasets import make_regression
@@ -24,15 +37,22 @@ def main():
2437
)
2538
automl.fit(X, y)
2639

27-
print("\n=== report_structured(model_details=False) ===\n")
28-
print(automl.report_structured(model_details=False))
29-
30-
print("\n=== report_structured(model_details=True) ===\n")
31-
print(automl.report_structured(model_details=True))
40+
print("\n=== report_structured() ===\n")
41+
print(automl.report_structured())
3242

33-
payload = automl.report_structured(format="dict", model_details=False)
43+
payload = automl.report_structured(format="dict")
3444
print("\nTop-level keys:", sorted(payload.keys()))
35-
print("Number of models in report:", len(payload.get("models", [])))
45+
selected_model_name = None
46+
leaderboard = payload.get("leaderboard", [])
47+
if len(leaderboard) > 1:
48+
selected_model_name = leaderboard[1].get("name")
49+
elif leaderboard:
50+
selected_model_name = leaderboard[0].get("name")
51+
print("Selected model:", selected_model_name)
52+
53+
if selected_model_name:
54+
print(f"\n=== report_structured(model_name='{selected_model_name}') ===\n")
55+
print(automl.report_structured(model_name=selected_model_name))
3656

3757
report_path = os.path.join(results_path, "report_structured.json")
3858
print("Structured report JSON:", report_path)

supervised/automl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ def score(
535535
def report(self, width=900, height=1200):
536536
return self._report(width, height)
537537

538-
def report_structured(self, format="markdown", model_details=True):
539-
return self._report_structured(format, model_details)
538+
def report_structured(self, format="markdown", model_name=None):
539+
return self._report_structured(format, model_name)
540540

541541
def need_retrain(
542542
self,

supervised/base_automl.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from supervised.utils.leaderboard_plots import LeaderboardPlots
4848
from supervised.utils.metric import Metric, UserDefinedEvalMetric
4949
from supervised.utils.report_structured import (
50+
build_compact_view,
5051
build_structured_report,
5152
save_structured_report,
5253
to_markdown,
@@ -2480,7 +2481,7 @@ def _report(self, width=900, height=1200):
24802481

24812482
return self._show_report(main_readme_html, width, height)
24822483

2483-
def _report_structured(self, format="markdown", model_details=True):
2484+
def _report_structured(self, format="markdown", model_name=None):
24842485
self._results_path = self._get_results_path()
24852486
if self._fit_level != "finished":
24862487
self.load(self._results_path)
@@ -2502,11 +2503,16 @@ def _report_structured(self, format="markdown", model_details=True):
25022503
payload = build_structured_report(self)
25032504
save_structured_report(payload, self._results_path)
25042505

2506+
try:
2507+
output_payload = build_compact_view(payload, model_name)
2508+
except ValueError as e:
2509+
raise AutoMLException(str(e))
2510+
25052511
if format == "dict":
2506-
return payload
2512+
return output_payload
25072513
if format == "json":
2508-
return json.dumps(payload, indent=4)
2509-
return to_markdown(payload, model_details)
2514+
return json.dumps(output_payload, indent=4)
2515+
return to_markdown(output_payload, model_name)
25102516

25112517
def _need_retrain(self, X, y, sample_weight, decrease):
25122518
metric = self._best_model.get_metric()

0 commit comments

Comments
 (0)