cascade.utils.sklearn#
- class cascade.utils.sklearn.SkMetric(name: str, *args: Any, value: Optional[SupportsFloat] = None, dataset: Optional[str] = None, split: Optional[str] = None, direction: Optional[Literal['up', 'down']] = None, interval: Optional[Tuple[SupportsFloat, SupportsFloat]] = None, extra: Optional[Dict[str, SupportsFloat]] = None, **kwargs: Any)[source]#
-
- __init__(name: str, *args: Any, value: Optional[SupportsFloat] = None, dataset: Optional[str] = None, split: Optional[str] = None, direction: Optional[Literal['up', 'down']] = None, interval: Optional[Tuple[SupportsFloat, SupportsFloat]] = None, extra: Optional[Dict[str, SupportsFloat]] = None, **kwargs: Any) None[source]#
-
Cascade Metric wrapper for sklearn.metrics
- Parameters:
-
-
name (str) – name of the metric, should be an exact match of the members of sklearn.metrics, but you can also use the aliases from the example
-
value (Optional[MetricType], optional) – Can assign value to the metric if already computed, by default None
-
dataset (Optional[str], optional) – Name of the dataset metric was computed on, by default None
-
split (Optional[str], optional) – Name of the dataset split like train, test or eval, by default None
-
direction (Optional[Literal["up", "down"]], optional) – Select up if greater the better or down if worse the better, by default None
-
interval (Optional[Tuple[MetricType, MetricType]], optional) – Confidence interval, by default None
-
extra (Optional[Dict[str, MetricType]], optional) – Extra metadata for a metric, by default None
-
Example
Here the aliases are demonstrated. You can also use any names from sklearn.metrics
from cascade.utils.sklearn import SkMetric acc = SkMetric("acc") precision = SkMetric("precision") recall = SkMetric("recall") mse = SkMetric("mse") gt_pred = ([0, 0], [0, 1]) acc.compute(*gt_pred) precision.compute(*gt_pred) recall.compute(*gt_pred) mse.compute(*gt_pred)
>>> from pprint import pprint >>> from cascade.utils.sklearn.sk_metric import METRIC_ALIASES >>> pprint(METRIC_ALIASES) {'acc': 'accuracy_score', 'accuracy': 'accuracy_score', 'f1': 'f1_score', 'mae': 'mean_absolute_error', 'mse': 'mean_squared_error', 'precision': 'precision_score', 'recall': 'recall_score'}
- compute(*args: Any, **kwargs: Any) SupportsFloat[source]#
-
The method to compute metric’s value. Should always populate the internal
self.valuefield and return it.
- class cascade.utils.sklearn.SkModel(*args: Any, blocks: Optional[List[Any]] = None, **kwargs: Any)[source]#
-
Wrapper for sklearn models. Accepts the name and block to form pipeline. Can fit, evaluate, predict save and load out of the box.
- __init__(*args: Any, blocks: Optional[List[Any]] = None, **kwargs: Any) None[source]#
-
- Parameters:
-
blocks (list, optional) – List of sklearn transformers to make a pipeline from
- get_meta() List[Dict[Any, Any]][source]#
-
- Returns:
-
meta – A list where first element is this object’s metadata. All other elements represent the other stages of pipeline if present.
Meta can be anything that is worth to document about the object and its properties.
Meta is a list (see Meta type alias) to allow the formation of pipelines.
- Return type:
-
Meta
- load_artifact(path: str, *args: Any, **kwargs: Any) None[source]#
-
Loads sklearn pipeline
Args and kwargs are passed into pickle.load
- Parameters:
-
path (str) – the folder from which to load pipeline.pkl
- Raises:
-
ValueError – if the path is not a valid directory