cascade.utils.sklearn#

class cascade.utils.sklearn.SkMetric(name: str, *args: Any, value: SupportsFloat | None = None, dataset: str | None = None, split: str | None = None, direction: Literal['up', 'down'] | None = None, interval: Tuple[SupportsFloat, SupportsFloat] | None = None, extra: Dict[str, SupportsFloat] | None = None, **kwargs: Any)[source]#
__init__(name: str, *args: Any, value: SupportsFloat | None = None, dataset: str | None = None, split: str | None = None, direction: Literal['up', 'down'] | None = None, interval: Tuple[SupportsFloat, SupportsFloat] | None = None, extra: Dict[str, SupportsFloat] | None = None, **kwargs: Any) None[source]#

Creates Metric

Parameters:
  • name (str) – Name of the metric

  • value (Optional[MetricType]) – Scalar value of the metric, by default None

  • dataset (Optional[str]) – Dataset on which metric was computed, by default None

  • split (Optional[str]) – The split of the dataset for example train or test, by default None

  • direction (Literal["up", "down", None]) – Is metric better when it is greater or less, by default None

  • interval (Optional[Tuple[MetricType, MetricType]]) – Upper and lower boundaries of value, by default None

  • extra (Optional[Dict[str, Any]]) – Extra values that needs to be stored with metric, by default None

compute(*args: Any, **kwargs: Any) SupportsFloat[source]#

The method to compute metric’s value. Should always populate the internal self.value field and return it.

class cascade.utils.sklearn.SkModel(*args: Any, blocks: List[Any] | None = 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: List[Any] | None = None, **kwargs: Any) None[source]#
Parameters:

blocks (list, optional) – List of sklearn transformers to make a pipeline from

fit(*args: Any, **kwargs: Any) None[source]#

Wrapper for pipeline.fit

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

predict(*args: Any, **kwargs: Any) Any[source]#

Wrapper for pipeline.predict

save(path: str) None[source]#

Saves model to the path provided. Path should be a folder. Creates it if not exists and saves there as model.pkl

When saving using this method only wrapper is saved if you want to save sklearn model use save_artifact

save_artifact(path: str, *args: Any, **kwargs: Any) None[source]#

Saves sklearn pipeline

Args and kwargs are passed into pickle.dump

Parameters:

path (str) – the folder in which to save pipeline.pkl