Skip to content

Infer target type

sklearo.utils.infer_target_type(y)

Infer the type of target variable based on the input series.

This function determines the type of target variable based on the unique values and data type of the input series.

Parameters:

  • y (Series) –

    The target variable series.

Returns:

  • str ( str ) –

    The inferred type of target variable, which can be one of the following:

    • "binary": Returned when the target variable contains exactly two unique values and is of an integer, boolean, string or categorical data type or it's floating point with no decimal digits (e.g. [0.0, 1.0]).
    • "multiclass": Returned when the target variable has more than two unique values and is of an integer, boolean, string or categorical data type or it's floating point with no decimal digits (e.g. [0.0, 1.0, 2.0]). In case of floating point data type, the unique values should be consecutive integers.
    • "continuous": Returned when the target variable is of a floating-point data type and contains at least one non-integer value or the unique values are not consecutive integers.
    • "unknown": Returned when the input series is none of the above types.

Examples:

>>> infer_target_type(pd.Series([1, 2, 3])
"multiclass"
>>> infer_target_type(pd.Series([1, 2, 1])
"binary"
>>> infer_target_type(pd.Series([1, 2, 4])
"multiclass"
>>> infer_target_type(pd.Series(["a", "b", "c"])
"multiclass"
>>> infer_target_type(pd.Series(["a", "b", "a"])
"binary"
>>> infer_target_type(pd.Series([1.0, 2.0, 3.5])
"continuous"
>>> infer_target_type(pd.Series([1.0, 3.5, 3.5])
"continuous"
>>> infer_target_type(pd.Series([1.0, 2.0, 4.0])
"continuous"
>>> infer_target_type(pd.Series([1.0, 4.0, 4.0])
"binary"
>>> infer_target_type(pd.Series([1.0, 2.0, 3.0])
"multiclass"
>>> infer_target_type(pd.Series([1.0, 2.0, 1.0])
"binary"