Skip to content

criteria

Criteria.

Classes:

Name Description
NumericalCriterion

Choose max and min values to keep.

CategoricalCriterion

Choose which categories to keep.

MultivariateCriterion

Choose samples that got max or min value in the given target_channel, which is interpreted as an array index.

TimeseriesBoxCriterion

Defines a 2D box area that should include aggregation results of chosen times series subpart.

NumericalCriterion(feature: ExplainableFeature, *, min_: float | None = None, max_: float | None = None) #

Choose max and min values to keep.

Parameters:

Name Type Description Default

type_ #

Literal['NUMERICAL']
required

min_ #

None | float
required

max_ #

None | float
required

Attributes:

Name Type Description
additional_properties dict[str, Any]

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Numerical Criterion initialization.

Parameters:

Name Type Description Default

feature #

NumericalFeature

The feature type to use with the criterion.

required

min_ #

int | None

Filter's minimum value.

None

max_ #

int | None

Filter's maximum value.

None

Methods:

Name Description
to_model

Convert to CriterionInsert instance.

Source code in src/xpdeep/filtering/criteria.py
def __init__(self, feature: ExplainableFeature, *, min_: float | None = None, max_: float | None = None) -> None:
    """
    Numerical Criterion initialization.

    Parameters
    ----------
    feature : NumericalFeature
        The feature type to use with the criterion.
    min_ : int | None, default None
        Filter's minimum value.
    max_ : int | None, default None
        Filter's maximum value.
    """
    if not isinstance(feature.feature_type, NumericalFeature):
        message = "feature.feature_type must be NumericalFeature"
        raise TypeError(message)

    if min_ is None and max_ is None:
        message = "Either `min_` or `max_` must be specified."
        raise ValueError(message)

    super().__init__(
        type_="NUMERICAL",
        min_=min_,
        max_=max_,
    )

    self.feature = feature

feature = feature #

to_model() -> CriterionInsert #

Convert to CriterionInsert instance.

Source code in src/xpdeep/filtering/criteria.py
def to_model(self) -> CriterionInsert:
    """Convert to CriterionInsert instance."""
    feature_id = self.feature.id
    if feature_id is None:
        msg = (
            "You are trying to define a criterion on a feature that has not been saved yet. This feature "
            "should belong to a fitted schema that has been saved after being user for a train or an explain"
        )
        raise NotSavedError(msg)

    return CriterionInsert(
        column_id=feature_id,
        value=NumericalCriterionValue(
            type_="NUMERICAL",
            min_=self.min_,
            max_=self.max_,
        ),
    )

CategoricalCriterion(feature: ExplainableFeature, *, categories: list[str] | list[int]) #

Choose which categories to keep.

Parameters:

Name Type Description Default

type_ #

Literal['CATEGORICAL']
required

categories #

list[int] | list[str]
required

Attributes:

Name Type Description
additional_properties dict[str, Any]

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Categorical Criterion initialization.

Parameters:

Name Type Description Default

feature #

ExplainableFeature

The feature on which apply on the criterion.

required

categories #

list[str | int | bool]

List on categories to keep.

required

Methods:

Name Description
to_model

Convert to CriterionInsert instance.

Source code in src/xpdeep/filtering/criteria.py
def __init__(self, feature: ExplainableFeature, *, categories: list[str] | list[int]) -> None:
    """
    Categorical Criterion initialization.

    Parameters
    ----------
    feature : ExplainableFeature
        The feature on which apply on the criterion.
    categories : list[str | int | bool]
        List on categories to keep.
    """
    if not isinstance(feature.feature_type, CategoricalFeature):
        message = "feature.feature_type must be CategoricalFeature"
        raise TypeError(message)

    # Map to string prior to filter as filter is performed on string only.
    super().__init__(
        type_="CATEGORICAL",
        categories=categories,
    )

    self.feature = feature

feature = feature #

to_model() -> CriterionInsert #

Convert to CriterionInsert instance.

Source code in src/xpdeep/filtering/criteria.py
def to_model(self) -> CriterionInsert:
    """Convert to CriterionInsert instance."""
    feature_id = self.feature.id
    if feature_id is None:
        msg = (
            "You are trying to define a criterion on a feature that has not been saved yet. This feature "
            "should belong to a fitted schema that has been saved after being user for a train or an explain"
        )
        raise NotSavedError(msg)

    return CriterionInsert(
        column_id=feature_id,
        value=CategoricalCriterionValue(
            type_="CATEGORICAL",
            categories=self.categories,
        ),
    )

MultivariateCriterion(feature: ExplainableFeature, *, target_channel: int = 0, mode: Literal['MIN', 'MAX']) #

Choose samples that got max or min value in the given target_channel, which is interpreted as an array index.

Only for 1D arrays.

Parameters:

Name Type Description Default

type_ #

Literal['MULTIVARIATE']
required

target_channel #

int
required

mode #

MultivariateFilterMode
required

Attributes:

Name Type Description
additional_properties dict[str, Any]

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Multivariate Criterion initialization.

Parameters:

Name Type Description Default

feature #

MultivariateNumericalFeature

The feature on which apply on the criterion.

required

target_channel #

int

An array's index value (starts from 0 to array size), so the resulting samples will have this dimension as their greatest or lowest value, depending on the modeparameter.

1

mode #

Literal['MIN', 'MAX']

If MAX, the filter returns sample which has the defined target_channel as their greatest value. If MIN, it considers the lowest value.

required

Methods:

Name Description
to_model

Convert to CriterionInsert instance.

Source code in src/xpdeep/filtering/criteria.py
def __init__(
    self,
    feature: ExplainableFeature,
    *,
    target_channel: int = 0,
    mode: Literal["MIN", "MAX"],
) -> None:
    """
    Multivariate Criterion initialization.

    Parameters
    ----------
    feature : MultivariateNumericalFeature
        The feature on which apply on the criterion.
    target_channel : int, default 1
        An array's index value (starts from 0 to array size),
        so the resulting samples will have this dimension as their greatest
        or lowest value, depending on the `mode`parameter.
    mode : Literal["MIN", "MAX"]
        If `MAX`, the filter returns sample which has the defined `target_channel` as their greatest value.
        If `MIN`, it considers the lowest value.
    """
    if not isinstance(feature.feature_type, MultivariateNumericalFeature):
        message = "feature.feature_type must be MultivariateNumericalFeature"
        raise TypeError(message)

    if mode not in {"MIN", "MAX"}:
        message = "Only `MIN` and `MAX` values are accepted for `mode` parameter."
        raise ValueError(message)

    super().__init__(
        type_="MULTIVARIATE",
        target_channel=target_channel,
        mode=MultivariateFilterMode(mode),
    )

    self.feature = feature

feature = feature #

to_model() -> CriterionInsert #

Convert to CriterionInsert instance.

Source code in src/xpdeep/filtering/criteria.py
def to_model(self) -> CriterionInsert:
    """Convert to CriterionInsert instance."""
    feature_id = self.feature.id
    if feature_id is None:
        msg = (
            "You are trying to define a criterion on a feature that has not been saved yet. This feature "
            "should belong to a fitted schema that has been saved after being user for a train or an explain"
        )
        raise NotSavedError(msg)

    return CriterionInsert(
        column_id=feature_id,
        value=MultivariateCriterionValue(type_="MULTIVARIATE", target_channel=self.target_channel, mode=self.mode),
    )

TimeseriesBoxCriterion(feature: ExplainableFeature, *, target_channel: int = 0, min_: float | None = None, max_: float | None = None, start: int | None = None, end: int | None = None, aggregators: list[Literal['MAX', 'MIN', 'AVG']]) #

Defines a 2D box area that should include aggregation results of chosen times series subpart.

Parameters:

Name Type Description Default

type_ #

Literal['TIMESERIES_BOX']
required

aggregators #

list[Aggregator]
required

target_channel #

int
required

min_ #

None | float
required

max_ #

None | float
required

start #

None | int
required

end #

None | int
required

Attributes:

Name Type Description
additional_properties dict[str, Any]

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Time series Box Criterion initialization.

Parameters:

Name Type Description Default

feature #

UnivariateTimeSeries | MultivariateTimeSeries

The feature on which apply on the criterion.

required

target_channel #

Literal['min', 'max']

Time series dimension to filter.

"max"

min_ #

float | None

The aggregation result of chosen time serie subpart should be greater than this value. Default as None, which means no limit.

None

max_ #

float | None

The aggregation result of chosen time serie subpart should be lower than this value. Default as None, which means no limit.

None

start #

int | None

Array's index from where starts the chosen time serie subpart. Default as None, which means start from index 0. Negative index values are not supported.

None

end #

int | None

Array's index where ends the chosen time serie subpart. Default as None, which means goes to index (last index). Negative index values are not supported.

None

aggregators #

list[Literal['MIN', 'MAX', 'AVG']]

Used aggregators to compute resulting values that will be projected to verify if they are included in the defined box.

required

Methods:

Name Description
to_model

As CriterionInsert.

Source code in src/xpdeep/filtering/criteria.py
def __init__(  # noqa: PLR0913
    self,
    feature: ExplainableFeature,
    *,
    target_channel: int = 0,
    min_: float | None = None,
    max_: float | None = None,
    start: int | None = None,
    end: int | None = None,
    aggregators: list[Literal["MAX", "MIN", "AVG"]],
) -> None:
    """
    Time series Box Criterion initialization.

    Parameters
    ----------
    feature : UnivariateTimeSeries | MultivariateTimeSeries
        The feature on which apply on the criterion.
    target_channel : Literal["min", "max"], default "max"
        Time series dimension to filter.
    min_ : float | None, default None
        The aggregation result of chosen time serie subpart should be greater than this value.
        Default as None, which means no limit.
    max_ : float | None, default None
        The aggregation result of chosen time serie subpart should be lower than this value.
        Default as None, which means no limit.
    start : int | None, default None
        Array's index from where starts the chosen time serie subpart.
        Default as None, which means start from index 0.
        Negative index values are not supported.
    end : int | None, default None
        Array's index where ends the chosen time serie subpart.
        Default as None, which means goes to index (last index).
        Negative index values are not supported.
    aggregators : list[Literal["MIN", "MAX", "AVG"]]
        Used aggregators to compute resulting values that will be projected to verify if they are included in
        the defined box.
    """
    if not isinstance(feature.feature_type, UnivariateTimeSeriesFeature | MultivariateTimeSeriesFeature):
        message = "feature.feature_type must be UnivariateTimeSeriesFeature or MultivariateTimeSeriesFeature"
        raise TypeError(message)

    for aggregator in aggregators:
        if aggregator not in {"MIN", "MAX", "AVG"}:
            message = "Only `MIN`, `MAX` and `AVG` values are accepted for elements of `aggregators` parameter."
            raise ValueError(message)

    super().__init__(
        type_="TIMESERIES_BOX",
        aggregators=list({Aggregator(aggregator) for aggregator in aggregators}),
        target_channel=target_channel,
        min_=min_,
        max_=max_,
        start=start,
        end=end,
    )

    self.feature = feature

feature = feature #

to_model() -> CriterionInsert #

As CriterionInsert.

Source code in src/xpdeep/filtering/criteria.py
def to_model(self) -> CriterionInsert:
    """As CriterionInsert."""
    feature_id = self.feature.id
    if feature_id is None:
        msg = (
            "You are trying to define a criterion on a feature that has not been saved yet. This feature "
            "should belong to a fitted schema that has been saved after being user for a train or an explain"
        )
        raise NotSavedError(msg)

    return CriterionInsert(
        column_id=feature_id,
        value=TimeseriesBoxCriterionValue(
            type_="TIMESERIES_BOX",
            aggregators=self.aggregators,
            target_channel=self.target_channel,
            min_=self.min_,
            max_=self.max_,
            start=self.start,
            end=self.end,
        ),
    )