watex.utils.labels_validator#
- watex.utils.labels_validator(t, /, labels, return_bool=False)[source]#
Assert the validity of the label in the target and return the label or the boolean whether all items of label are in the target.
- Parameters:
t – array-like, target that is expected to contain the labels.
labels – int, str or list of (str or int) that is supposed to be in the target t.
return_bool – bool, default=False; returns ‘True’ or ‘False’ rather the labels if set to
True.
- Returns:
bool or labels; ‘True’ or ‘False’ if return_bool is set to
Trueand labels otherwise.- Example:
>>> from watex.datasets import fetch_data >>> from watex.utils.mlutils import cattarget, labels_validator >>> _, y = fetch_data ('bagoue', return_X_y=True, as_frame=True) >>> # binarize target y into [0 , 1] >>> ybin = cattarget(y, labels=2 ) >>> labels_validator (ybin, [0, 1]) ... [0, 1] # all labels exist. >>> labels_validator (y, [0, 1, 3]) ... ValueError: Value '3' is missing in the target. >>> labels_validator (ybin, 0 ) ... [0] >>> labels_validator (ybin, [0, 5], return_bool=True ) # no raise error ... False