I have tried using keras to one-hot encode my categorical variables from a string into a dummy variable. My dataset looks like this below:
Region Location Price
North Region Green wood city 150
West Region Pebble hill 200
North Region Green wood city 160
West Region Pebble hill 250
South Region Astoria 220
I was converted my categorical features to an array using numpy
and one-hot encode using from keras.utils import to_categorical
. as shown below:
data = np.array(df1[['Region', 'Location']])
encoded = to_categorical(data)
However, i got the error
ValueError: invalid literal for int() with base 10: 'North Region'.
I looked at the traceback error and this is what it said.
---> 43 y = np.array(y, dtype='int')
44 input_shape = y.shape
Any help is appreciated. Thanks!
Edit:
to_categorical keras.utils.to_categorical(y, num_classes=None, dtype='float32') Converts a class vector (integers) to binary class matrix.
E.g. for use with categorical_crossentropy.
Arguments
y: class vector to be converted into a matrix (integers from 0 to num_classes). num_classes: total number of classes. dtype: The data type expected by the input, as a string (float32, float64, int32...) Returns