OneHotEncoder#
Domain:
ai.onnx.mlSince version: 1
Replace each input element with an array of ones and zeros, where a single
one is placed at the index of the category that was passed in. The total category count
will determine the size of the extra dimension of the output array Y.
For example, if we pass a tensor with a single value of 4, and a category count of 8,
the output will be a tensor with `[0,0,0,0,1,0,0,0]`.
This operator assumes every input feature is from the same set of categories.
If the input is a tensor of float, int32, or double, the data will be cast
to integers and the cats_int64s category list will be used for the lookups.
Inputs
X (T): Data to be encoded.
Outputs
Y (tensor(float)): Encoded output data, having one more dimension than X.
Type Constraints
T: The input must be a tensor of a numeric type. Allowed types: tensor(double), tensor(float), tensor(int32), tensor(int64), tensor(string).
Examples#
test_cc_one_hot_encoder_int64
Node:
ai.onnx.ml.OneHotEncoder(x) -> (y)
Attributes:
cats_int64s = [0, 1, 2, 3]
zeros = 1
Inputs:
x: shape=(3,), dtype=int64
[0, 2, 7]
Outputs:
y: shape=(3, 4), dtype=float32
[[1., 0., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 0.]]
test_cc_one_hot_encoder_string
Node:
ai.onnx.ml.OneHotEncoder(x) -> (y)
Attributes:
cats_strings = ['a', 'b', 'c']
zeros = 1
Inputs:
x: shape=(4,), dtype=object
['a', 'b', 'd', 'c']
Outputs:
y: shape=(4, 3), dtype=float32
[[1., 0., 0.],
[0., 1., 0.],
[0., 0., 0.],
[0., 0., 1.]]