I have a numpy array like this:
[[0. 1. 1. ... 0. 0. 1.]
[0. 0. 0. ... 0. 0. 1.]
[0. 0. 1. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 1.]
[0. 0. 0. ... 0. 0. 1.]
[0. 0. 0. ... 1. 0. 1.]]
I transform it like this to reduce the memory demand:
x_val = x_val.astype(np.int)
resulting in this:
[[0 1 1 ... 0 0 1]
[0 0 0 ... 0 0 1]
[0 0 1 ... 0 0 0]
...
[0 0 0 ... 0 0 1]
[0 0 0 ... 0 0 1]
[0 0 0 ... 1 0 1]]
However, when I do this:
x_val = to_categorical(x_val)
I get:
in to_categorical
categorical = np.zeros((n, num_classes), dtype=np.float32)
MemoryError
Any ideas why? Ultimately, the numpy array contains the labels for a binary classification problem. So far, I have used it as float32 as is in a Keras ANN and it worked fine and I achieved pretty good performance. So is it actually necessary to run to_categorical?
[0. 1. 1. ... 0. 0. 1.], correspond to when interpreted as a label? If you want to perform binary classification the labels should have a shape of(n_samples,). I guess you are doing multi-label classification, i.e. each sample may have multiple labels. In that case the labels are correct as they are and you don't need to useto_categoricalat all. - today