type_of_target
- sklearn.utils.multiclass.type_of_target(y, input_name='', raise_unknown=False)[source]
-
Determine the type of data indicated by the target.
Note that this type is the most specific type that can be inferred. For example:
-
binaryis more specific but compatible withmulticlass. -
multiclassof integers is more specific but compatible withcontinuous. -
multilabel-indicatoris more specific but compatible withmulticlass-multioutput.
- Parameters:
-
- y{array-like, sparse matrix}
-
Target values. If a sparse matrix,
yis expected to be a CSR/CSC matrix. - input_namestr, default=””
-
The data name used to construct the error message.
Added in version 1.1.0.
- raise_unknownbool, default=False
-
If
True, raise an error when the type of target returned bytype_of_targetis"unknown".Added in version 1.6.
- Returns:
-
- target_typestr
-
One of:
- ‘continuous’:
yis an array-like of floats that are not all integers, and is 1d or a column vector. - ‘continuous-multioutput’:
yis a 2d array of floats that are not all integers, and both dimensions are of size > 1. - ‘binary’:
ycontains <= 2 discrete values and is 1d or a column vector. - ‘multiclass’:
ycontains more than two discrete values, is not a sequence of sequences, and is 1d or a column vector. - ‘multiclass-multioutput’:
yis a 2d array that contains more than two discrete values, is not a sequence of sequences, and both dimensions are of size > 1. - ‘multilabel-indicator’:
yis a label indicator matrix, an array of two dimensions with at least two columns, and at most 2 unique values. - ‘unknown’:
yis array-like but none of the above, such as a 3d array, sequence of sequences, or an array of non-sequence objects.
- ‘continuous’:
Examples
>>> from sklearn.utils.multiclass import type_of_target >>> import numpy as np >>> type_of_target([0.1, 0.6]) 'continuous' >>> type_of_target([1, -1, -1, 1]) 'binary' >>> type_of_target(['a', 'b', 'a']) 'binary' >>> type_of_target([1.0, 2.0]) 'binary' >>> type_of_target([1, 0, 2]) 'multiclass' >>> type_of_target([1.0, 0.0, 3.0]) 'multiclass' >>> type_of_target(['a', 'b', 'c']) 'multiclass' >>> type_of_target(np.array([[1, 2], [3, 1]])) 'multiclass-multioutput' >>> type_of_target([[1, 2]]) 'multilabel-indicator' >>> type_of_target(np.array([[1.5, 2.0], [3.0, 1.6]])) 'continuous-multioutput' >>> type_of_target(np.array([[0, 1], [1, 1]])) 'multilabel-indicator'
-
© 2007–2026 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.9/modules/generated/sklearn.utils.multiclass.type_of_target.html