Convert N integer class labels into an N×K one-hot matrix. Row i is defined by:
Yij={1,0,j=yij=yiHere, yi is the label for sample i and K is num_classes. When num_classes is None, set K=max(y)+1. Return a floating-point NumPy array.
Input: y = [0, 2, 1], num_classes = None
Output: [[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 0.0]]
Explanation: The largest label implies three columns, and each row marks its label index.
Input: y = [1, 1, 0], num_classes = 4
Output: [[0.0, 1.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0]]
Create np.zeros((y.size, num_classes), dtype=float).
Assign ones with encoded[np.arange(y.size), y] = 1.0.
Sign in to take notes on this problem
Accepts: array
Accepts: any
Convert N integer class labels into an N×K one-hot matrix. Row i is defined by:
Yij={1,0,j=yij=yiHere, yi is the label for sample i and K is num_classes. When num_classes is None, set K=max(y)+1. Return a floating-point NumPy array.
Input: y = [0, 2, 1], num_classes = None
Output: [[1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 0.0]]
Explanation: The largest label implies three columns, and each row marks its label index.
Input: y = [1, 1, 0], num_classes = 4
Output: [[0.0, 1.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0]]
Create np.zeros((y.size, num_classes), dtype=float).
Assign ones with encoded[np.arange(y.size), y] = 1.0.
Sign in to take notes on this problem
Accepts: array
Accepts: any