|
46 | 46 | from supervised.utils.jsonencoder import MLJSONEncoder |
47 | 47 | from supervised.utils.leaderboard_plots import LeaderboardPlots |
48 | 48 | from supervised.utils.metric import Metric, UserDefinedEvalMetric |
| 49 | +from supervised.utils.report_structured import ( |
| 50 | + build_structured_report, |
| 51 | + save_structured_report, |
| 52 | + to_markdown, |
| 53 | +) |
49 | 54 | from supervised.utils.utils import dump_data, load_data |
50 | 55 |
|
51 | 56 | logger = logging.getLogger(__name__) |
@@ -2475,6 +2480,34 @@ def _report(self, width=900, height=1200): |
2475 | 2480 |
|
2476 | 2481 | return self._show_report(main_readme_html, width, height) |
2477 | 2482 |
|
| 2483 | + def _report_structured(self, format="markdown", model_details=True): |
| 2484 | + self._results_path = self._get_results_path() |
| 2485 | + if self._fit_level != "finished": |
| 2486 | + self.load(self._results_path) |
| 2487 | + elif self._models is None or len(self._models) == 0: |
| 2488 | + # Handle objects where fit() returned early because results already exist. |
| 2489 | + # In that case, fit_level can be "finished" but models might not be loaded. |
| 2490 | + self.load(self._results_path) |
| 2491 | + |
| 2492 | + if self._models is None or len(self._models) == 0: |
| 2493 | + raise AutoMLException( |
| 2494 | + "This model has not been fitted yet. Please call `fit()` first." |
| 2495 | + ) |
| 2496 | + |
| 2497 | + if format not in ["markdown", "dict", "json"]: |
| 2498 | + raise ValueError( |
| 2499 | + f"Wrong format '{format}'. Allowed formats are: markdown, dict, json." |
| 2500 | + ) |
| 2501 | + |
| 2502 | + payload = build_structured_report(self) |
| 2503 | + save_structured_report(payload, self._results_path) |
| 2504 | + |
| 2505 | + if format == "dict": |
| 2506 | + return payload |
| 2507 | + if format == "json": |
| 2508 | + return json.dumps(payload, indent=4) |
| 2509 | + return to_markdown(payload, model_details) |
| 2510 | + |
2478 | 2511 | def _need_retrain(self, X, y, sample_weight, decrease): |
2479 | 2512 | metric = self._best_model.get_metric() |
2480 | 2513 |
|
|
0 commit comments