In [1]:
from keras.utils import np_utils
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Activation
import numpy as np


Using TensorFlow backend.

In [3]:
x_train = ['a','b','c']
y_train = [1,2,3]

In [6]:
x_train = np.array(x_train).reshape(3,1)

In [7]:
x_train


Out[7]:
array([['a'],
       ['b'],
       ['c']],
      dtype='<U1')

In [8]:
y_train = np.array(y_train).reshape(3,1)

In [9]:
y_train


Out[9]:
array([[1],
       [2],
       [3]])

In [16]:
model = Sequential()
model.add(Dense(units= 3, input_dim = 3, activation='relu'))
model.add(Dense(units= 3, activation='softmax'))

In [17]:
model.compile(loss = 'categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])

In [18]:
model.fit(x_train, y_train, epochs=5, batch_size=10)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-a886b73c6ee7> in <module>()
----> 1 model.fit(x_train, y_train, epochs=5, batch_size=10)

/Users/jaegyuhan/anaconda3/lib/python3.5/site-packages/keras/models.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
    958                               initial_epoch=initial_epoch,
    959                               steps_per_epoch=steps_per_epoch,
--> 960                               validation_steps=validation_steps)
    961 
    962     def evaluate(self, x, y, batch_size=32, verbose=1,

/Users/jaegyuhan/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
   1579             class_weight=class_weight,
   1580             check_batch_axis=False,
-> 1581             batch_size=batch_size)
   1582         # Prepare validation data.
   1583         do_validation = False

/Users/jaegyuhan/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size)
   1416                                     output_shapes,
   1417                                     check_batch_axis=False,
-> 1418                                     exception_prefix='target')
   1419         sample_weights = _standardize_sample_weights(sample_weight,
   1420                                                      self._feed_output_names)

/Users/jaegyuhan/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in _standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    151                             ' to have shape ' + str(shapes[i]) +
    152                             ' but got array with shape ' +
--> 153                             str(array.shape))
    154     return arrays
    155 

ValueError: Error when checking target: expected dense_6 to have shape (None, 3) but got array with shape (3, 1)

In [ ]: