I am trying to convert some categorical features into one hot encodings for use in Keras. However, when I try to map these features, I end up receiving an error indicating the shapes are incompatible. Here is my code:
import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import LabelEncoder
from keras.utils import np_utils
# load dataset
dataframe = pandas.read_csv("data/development.csv")
dataset = dataframe.values
X = dataset[:,0:7].astype(int)
encoder = LabelEncoder()
for i in [3,4,5,6]:
col = X[i]
encoder.fit(col)
encoded_col = encoder.transform(col)
X[i] = np_utils.to_categorical(encoded_col) # Error is here
Y = dataset[:,7].astype(int)
And here is the error I'm receiving:
ValueError: could not broadcast input array from shape (7,5) into shape (7)
Is there anything that I should be doing differently here? I am using Python 3.6, with Keras 2.2.2.