Coverage for mlos_viz/mlos_viz/dabl.py: 100%
23 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-06 00:35 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Small wrapper functions for dabl plotting functions via mlos_bench data.
7"""
8from typing import Dict, Optional, Literal
10import warnings
12import dabl
13import pandas
15from mlos_bench.storage.base_experiment_data import ExperimentData
17from mlos_viz.util import expand_results_data_args
20def plot(exp_data: Optional[ExperimentData] = None, *,
21 results_df: Optional[pandas.DataFrame] = None,
22 objectives: Optional[Dict[str, Literal["min", "max"]]] = None,
23 ) -> None:
24 """
25 Plots the Experiment results data using dabl.
27 Parameters
28 ----------
29 exp_data : ExperimentData
30 The ExperimentData (e.g., obtained from the storage layer) to plot.
31 results_df : Optional["pandas.DataFrame"]
32 Optional results_df to plot.
33 If not provided, defaults to exp_data.results_df property.
34 objectives : Optional[Dict[str, Literal["min", "max"]]]
35 Optional objectives to plot.
36 If not provided, defaults to exp_data.objectives property.
37 """
38 (results_df, obj_cols) = expand_results_data_args(exp_data, results_df, objectives)
39 for obj_col in obj_cols:
40 dabl.plot(X=results_df, target_col=obj_col)
43def ignore_plotter_warnings() -> None:
44 """
45 Add some filters to ignore warnings from the plotter.
46 """
47 # pylint: disable=import-outside-toplevel
48 warnings.filterwarnings("ignore", category=FutureWarning)
49 warnings.filterwarnings("ignore", module="dabl", category=UserWarning, message="Could not infer format")
50 warnings.filterwarnings("ignore", module="dabl", category=UserWarning, message="(Dropped|Discarding) .* outliers")
51 warnings.filterwarnings("ignore", module="dabl", category=UserWarning, message="Not plotting highly correlated")
52 warnings.filterwarnings("ignore", module="dabl", category=UserWarning,
53 message="Missing values in target_col have been removed for regression")
54 from sklearn.exceptions import UndefinedMetricWarning
55 warnings.filterwarnings("ignore", module="sklearn", category=UndefinedMetricWarning, message="Recall is ill-defined")
56 warnings.filterwarnings("ignore", category=DeprecationWarning,
57 message="is_categorical_dtype is deprecated and will be removed in a future version.")
58 warnings.filterwarnings("ignore", category=DeprecationWarning, module="sklearn",
59 message="is_sparse is deprecated and will be removed in a future version.")
60 from matplotlib._api.deprecation import MatplotlibDeprecationWarning
61 warnings.filterwarnings("ignore", category=MatplotlibDeprecationWarning, module="dabl",
62 message="The legendHandles attribute was deprecated in Matplotlib 3.7 and will be removed")