invalid_target_data_check#
Data check that checks if the target data contains missing or invalid values.
Module Contents#
Classes Summary#
Check if the target data is considered invalid. |
Contents#
- class evalml.data_checks.invalid_target_data_check.InvalidTargetDataCheck(problem_type, objective, n_unique=100)[source]#
Check if the target data is considered invalid.
- Target data is considered invalid if:
Target is None.
Target has NaN or None values.
Target is of an unsupported Woodwork logical type.
Target and features have different lengths or indices.
Target does not have enough instances of a class in a classification problem.
Target does not contain numeric data for regression problems.
- Parameters
problem_type (str or ProblemTypes) – The specific problem type to data check for. e.g. ‘binary’, ‘multiclass’, ‘regression, ‘time series regression’
objective (str or ObjectiveBase) – Name or instance of the objective class.
n_unique (int) – Number of unique target values to store when problem type is binary and target incorrectly has more than 2 unique values. Non-negative integer. If None, stores all unique values. Defaults to 100.
Attributes
multiclass_continuous_threshold
0.05
Methods
Return a name describing the data check.
Check if the target data is considered invalid. If the input features argument is not None, it will be used to check that the target and features have the same dimensions and indices.
- name(cls)#
Return a name describing the data check.
- validate(self, X, y)[source]#
Check if the target data is considered invalid. If the input features argument is not None, it will be used to check that the target and features have the same dimensions and indices.
- Target data is considered invalid if:
Target is None.
Target has NaN or None values.
Target is of an unsupported Woodwork logical type.
Target and features have different lengths or indices.
Target does not have enough instances of a class in a classification problem.
Target does not contain numeric data for regression problems.
- Parameters
X (pd.DataFrame, np.ndarray) – Features. If not None, will be used to check that the target and features have the same dimensions and indices.
y (pd.Series, np.ndarray) – Target data to check for invalid values.
- Returns
List with DataCheckErrors if any invalid values are found in the target data.
- Return type
dict (DataCheckError)
Examples
>>> import pandas as pd
Target values must be integers, doubles, or booleans.
>>> X = pd.DataFrame({"col": [1, 2, 3, 1]}) >>> y = pd.Series(["cat_1", "cat_2", "cat_1", "cat_2"]) >>> target_check = InvalidTargetDataCheck("regression", "R2") >>> assert target_check.validate(X, y) == [ ... { ... "message": "Target is unsupported Unknown type. Valid Woodwork logical types include: integer, double, boolean, integer_nullable, boolean_nullable, age_nullable", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "error", ... "details": {"columns": None, "rows": None, "unsupported_type": "unknown"}, ... "code": "TARGET_UNSUPPORTED_TYPE", ... "action_options": [] ... }, ... { ... "message": "Target data type should be numeric for regression type problems.", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "error", ... "details": {"columns": None, "rows": None}, ... "code": "TARGET_UNSUPPORTED_TYPE", ... "action_options": [] ... } ... ]
The target cannot have null values.
>>> y = pd.Series([None, pd.NA, pd.NaT, None]) >>> assert target_check.validate(X, y) == [ ... { ... "message": "Target is either empty or fully null.", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "error", ... "details": {"columns": None, "rows": None}, ... "code": "TARGET_IS_EMPTY_OR_FULLY_NULL", ... "action_options": [] ... } ... ] ... ... >>> y = pd.Series([1, None, 3, None]) >>> assert target_check.validate(None, y) == [ ... { ... "message": "2 row(s) (50.0%) of target values are null", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "error", ... "details": { ... "columns": None, ... "rows": None, ... "num_null_rows": 2, ... "pct_null_rows": 50.0 ... }, ... "code": "TARGET_HAS_NULL", ... "action_options": [ ... { ... "code": "IMPUTE_COL", ... "data_check_name": "InvalidTargetDataCheck", ... "parameters": { ... "impute_strategy": { ... "parameter_type": "global", ... "type": "category", ... "categories": ["mean", "most_frequent"], ... "default_value": "mean" ... } ... }, ... "metadata": {"columns": None, "rows": None, "is_target": True}, ... } ... ], ... } ... ]
If the target values don’t match the problem type passed, an error will be raised. In this instance, only two values exist in the target column, but multiclass has been passed as the problem type.
>>> X = pd.DataFrame([i for i in range(50)]) >>> y = pd.Series([i%2 for i in range(50)]) >>> target_check = InvalidTargetDataCheck("multiclass", "Log Loss Multiclass") >>> assert target_check.validate(X, y) == [ ... { ... "message": "Target has two or less classes, which is too few for multiclass problems. Consider changing to binary.", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "error", ... "details": {"columns": None, "rows": None, "num_classes": 2}, ... "code": "TARGET_MULTICLASS_NOT_ENOUGH_CLASSES", ... "action_options": [] ... } ... ]
If the length of X and y differ, a warning will be raised. A warning will also be raised for indices that don”t match.
>>> target_check = InvalidTargetDataCheck("regression", "R2") >>> X = pd.DataFrame([i for i in range(5)]) >>> y = pd.Series([1, 2, 4, 3], index=[1, 2, 4, 3]) >>> assert target_check.validate(X, y) == [ ... { ... "message": "Input target and features have different lengths", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "warning", ... "details": {"columns": None, "rows": None, "features_length": 5, "target_length": 4}, ... "code": "MISMATCHED_LENGTHS", ... "action_options": [] ... }, ... { ... "message": "Input target and features have mismatched indices. Details will include the first 10 mismatched indices.", ... "data_check_name": "InvalidTargetDataCheck", ... "level": "warning", ... "details": { ... "columns": None, ... "rows": None, ... "indices_not_in_features": [], ... "indices_not_in_target": [0] ... }, ... "code": "MISMATCHED_INDICES", ... "action_options": [] ... } ... ]