sparsity_data_check#

检查输入中是否存在包含稀疏填充值的列的数据检查。

模块内容#

类摘要#

SparsityDataCheck

检查输入中是否存在包含稀疏填充值的列。

属性摘要#

内容#

class evalml.data_checks.sparsity_data_check.SparsityDataCheck(problem_type, threshold, unique_count_threshold=10)[source]#

检查输入中是否存在包含稀疏填充值的列。

参数
  • problem_type (str or ProblemTypes) – 要进行数据检查的特定问题类型。只接受 ‘multiclass’ 或 ‘time series multiclass’ 问题类型。

  • threshold (float) – 阈值,即每列唯一值的百分比,低于此百分比时,列显示稀疏性。应介于 0 和 1 之间。

  • unique_count_threshold (int) – 一个唯一值在一列中必须出现的最小次数,否则被视为“稀疏”。默认为 10。

方法

name

返回描述数据检查的名称。

sparsity_score

通过计算超过 count_threshold 的唯一值的百分比,为给定的值计数计算稀疏度得分。

validate

计算每列唯一值超过计数阈值的百分比,并将该百分比与存储在类实例中的稀疏度阈值进行比较。

name(cls)#

返回描述数据检查的名称。

static sparsity_score(col, count_threshold=10)[source]#

通过计算超过 count_threshold 的唯一值的百分比,为给定的值计数计算稀疏度得分。

参数
  • col (pd.Series) – 特征值。

  • count_threshold (int) – 值低于此实例数时被视为稀疏。默认为 10。

返回值

稀疏度得分,即超过 count_threshold 的唯一值的百分比。

返回值类型

(float)

validate(self, X, y=None)[source]#

计算每列唯一值超过计数阈值的百分比,并将该百分比与存储在类实例中的稀疏度阈值进行比较。

参数
  • X (pd.DataFrame, np.ndarray) – 特征。

  • y (pd.Series, np.ndarray) – 被忽略。

返回值

如果存在任何稀疏列,则返回包含 DataCheckWarning 的字典。

返回值类型

dict

示例

>>> import pandas as pd

对于多类问题,如果一列没有足够数量的唯一值表示,则会被视为稀疏。

>>> df = pd.DataFrame({
...    "sparse": [float(x) for x in range(100)],
...    "not_sparse": [float(1) for x in range(100)]
... })
...
>>> sparsity_check = SparsityDataCheck(problem_type="multiclass", threshold=0.5, unique_count_threshold=10)
>>> assert sparsity_check.validate(df) == [
...     {
...         "message": "Input columns ('sparse') for multiclass problem type are too sparse.",
...         "data_check_name": "SparsityDataCheck",
...         "level": "warning",
...         "code": "TOO_SPARSE",
...         "details": {
...             "columns": ["sparse"],
...             "sparsity_score": {"sparse": 0.0},
...             "rows": None
...         },
...         "action_options": [
...             {
...                 "code": "DROP_COL",
...                  "data_check_name": "SparsityDataCheck",
...                  "parameters": {},
...                  "metadata": {"columns": ["sparse"], "rows": None}
...             }
...         ]
...     }
... ]

… >>> df[“sparse”] = [float(x % 10) for x in range(100)] >>> sparsity_check = SparsityDataCheck(problem_type=”multiclass”, threshold=1, unique_count_threshold=5) >>> assert sparsity_check.validate(df) == [] … >>> sparse_array = pd.Series([1, 1, 1, 2, 2, 3] * 3) >>> assert SparsityDataCheck.sparsity_score(sparse_array, count_threshold=5) == 0.6666666666666666

evalml.data_checks.sparsity_data_check.warning_too_unique = Input columns ({}) for {} problem type are too sparse.#