22
33from __future__ import annotations
44
5+ import itertools
56import re
67from functools import cached_property , wraps
78from operator import itemgetter
@@ -23,13 +24,19 @@ class Metadata(TypedDict): # noqa: D101
2324 key : str
2425 date : str
2526 learner : str
26- dataset : str
2727 ml_task : str
28+ report_type : str
29+ dataset : str
2830 rmse : float | None
2931 log_loss : float | None
3032 roc_auc : float | None
31- fit_time : float
32- predict_time : float
33+ fit_time : float | None
34+ predict_time : float | None
35+ rmse_mean : float | None
36+ log_loss_mean : float | None
37+ roc_auc_mean : float | None
38+ fit_time_mean : float | None
39+ predict_time_mean : float | None
3340
3441
3542def ensure_project_is_created (method ):
@@ -215,6 +222,57 @@ def get(self, urn: str) -> EstimatorReport | CrossValidationReport:
215222
216223 return joblib .load (tmpfile )
217224
225+ @ensure_project_is_created
226+ def summarize (self ) -> list [Metadata ]:
227+ """Obtain metadata/metrics for all persisted reports in insertion order."""
228+
229+ def dto (response ):
230+ report_type , summary = response
231+ metrics = {
232+ metric ["name" ]: metric ["value" ]
233+ for metric in summary ["metrics" ]
234+ if metric ["data_source" ] in (None , "test" )
235+ }
236+
237+ return {
238+ "id" : summary ["urn" ],
239+ "run_id" : summary ["run_id" ],
240+ "key" : summary ["key" ],
241+ "date" : summary ["created_at" ],
242+ "learner" : summary ["estimator_class_name" ],
243+ "ml_task" : summary ["ml_task" ],
244+ "report_type" : report_type ,
245+ "dataset" : summary ["dataset_fingerprint" ],
246+ "rmse" : metrics .get ("rmse" ),
247+ "log_loss" : metrics .get ("log_loss" ),
248+ "roc_auc" : metrics .get ("roc_auc" ),
249+ "fit_time" : metrics .get ("fit_time" ),
250+ "predict_time" : metrics .get ("predict_time" ),
251+ "rmse_mean" : metrics .get ("rmse_mean" ),
252+ "log_loss_mean" : metrics .get ("log_loss_mean" ),
253+ "roc_auc_mean" : metrics .get ("roc_auc_mean" ),
254+ "fit_time_mean" : metrics .get ("fit_time_mean" ),
255+ "predict_time_mean" : metrics .get ("predict_time_mean" ),
256+ }
257+
258+ with HUBClient () as client :
259+ responses = itertools .chain (
260+ zip (
261+ itertools .repeat ("estimator" ),
262+ client .get (
263+ f"projects/{ self .tenant } /{ self .name } /estimator-reports/"
264+ ).json (),
265+ ),
266+ zip (
267+ itertools .repeat ("cross-validation" ),
268+ client .get (
269+ f"projects/{ self .tenant } /{ self .name } /cross-validation-reports/"
270+ ).json (),
271+ ),
272+ )
273+
274+ return sorted (map (dto , responses ), key = itemgetter ("date" ))
275+
218276 @property
219277 @ensure_project_is_created
220278 def reports (self ):
@@ -231,36 +289,14 @@ def get(urn: str) -> EstimatorReport | CrossValidationReport:
231289 return self .get (urn )
232290
233291 def metadata () -> list [Metadata ]:
234- """Obtain metadata for all persisted reports regardless of their run."""
235-
236- def dto (summary ):
237- metrics = {
238- metric ["name" ]: metric ["value" ]
239- for metric in summary ["metrics" ]
240- if metric ["data_source" ] in (None , "test" )
241- }
242-
243- return {
244- "id" : summary ["id" ],
245- "run_id" : summary ["run_id" ],
246- "key" : summary ["key" ],
247- "date" : summary ["created_at" ],
248- "learner" : summary ["estimator_class_name" ],
249- "dataset" : summary ["dataset_fingerprint" ],
250- "ml_task" : summary ["ml_task" ],
251- "rmse" : metrics .get ("rmse" ),
252- "log_loss" : metrics .get ("log_loss" ),
253- "roc_auc" : metrics .get ("roc_auc" ),
254- "fit_time" : metrics .get ("fit_time" ),
255- "predict_time" : metrics .get ("predict_time" ),
256- }
257-
258- with HUBClient () as client :
259- response = client .get (
260- f"projects/{ self .tenant } /{ self .name } /experiments/estimator-reports"
261- )
262-
263- return sorted (map (dto , response .json ()), key = itemgetter ("date" ))
292+ """
293+ Obtain metadata/metrics for all persisted reports in insertion order.
294+
295+ .. deprecated
296+ The ``Project.reports.metadata`` function will be removed in favor of
297+ ``Project.summarize`` in a near future.
298+ """
299+ return self .summarize ()
264300
265301 return SimpleNamespace (get = get , metadata = metadata )
266302
0 commit comments