Converts a class vector (integers) to binary class matrix. Args: y: class vector to be converted into a matrix (integers from 0 to num_classes). num_classes: total number of classes. Returns: A binary matrix representatio
(y, num_classes)
| 63 | data = np.array([[a, b] for (a, b) in zip(x, y)], dtype=np.float32) |
| 64 | |
| 65 | def to_categorical(y, num_classes): |
| 66 | """ |
| 67 | Converts a class vector (integers) to binary class matrix. |
| 68 | |
| 69 | Args: |
| 70 | y: class vector to be converted into a matrix |
| 71 | (integers from 0 to num_classes). |
| 72 | num_classes: total number of classes. |
| 73 | |
| 74 | Returns: |
| 75 | A binary matrix representation of the input. |
| 76 | """ |
| 77 | y = np.array(y, dtype="int") |
| 78 | n = y.shape[0] |
| 79 | categorical = np.zeros((n, num_classes)) |
| 80 | categorical[np.arange(n), y] = 1 |
| 81 | return categorical |
| 82 | |
| 83 | label = to_categorical(label, 2).astype(np.float32) |
| 84 | print("train_data_shape:", data.shape) |