title: Multi-class classification using keras
body: <p>I am developing a neural network in order to classify with classes pre-calculated with k-means.</p>
  
  <p>Dataset looks like:</p>
  
  <pre><code>50,12500,2,1,5
  50,8500,2,1,15
  50,6000,2,1,9
  50,8500,2,1,15
  </code></pre>
  
  <p>Where resulting row is the last row.
  Here is the code on Python with <strong>Keras</strong> I am trying to get working:</p>
  
  <pre><code>import numpy
  import pandas
  from keras.models import Sequential
  from keras.layers import Dense,Dropout
  from keras.wrappers.scikit_learn import KerasClassifier
  from keras.utils import np_utils
  from sklearn.model_selection import cross_val_score
  from sklearn.model_selection import KFold
  from sklearn.preprocessing import LabelEncoder
  from sklearn.pipeline import Pipeline
  
  # fix random seed for reproducibility
  seed = 7
  numpy.random.seed(seed)
  
  # load dataset
  dataset = numpy.genfromtxt ('../r-calculations/k-means/output16.csv', delimiter=",")
  X = dataset[:,0:4].astype(float)
  Y = dataset[:,4]
  print(Y[0])
  Y = np_utils.to_categorical(Y)
  
  model = Sequential()
  model.add(Dense(5, activation='tanh', input_dim=4))
  #model.add(Dropout(0.25))
  model.add(Dense(10, activation='tanh'))
  #model.add(Dropout(0.25))
  model.add(Dense(10, activation='relu'))
  #model.add(Dropout(0.25))
  model.add(Dense(17, activation='softmax'))
  
  model.compile(optimizer='adam',
                loss='categorical_crossentropy',
                metrics=['accuracy'])
  
  model.fit(X,Y, epochs=10, batch_size=10)
  #print( model.predict(numpy.array([2,36,2,5,2384,1,2,4,3,1,1,4,33,3,1,1,2,1,1,1]).reshape((1,20))) )
  #print( model.predict(numpy.array(X[0]).reshape((1,4))) )
  #print( model.predict(numpy.array(X[1]).reshape((1,4))) )
  #print( model.predict(numpy.array(X[2]).reshape((1,4))) )
  result = model.predict(numpy.array(X[0]).reshape((1,4)))
  for res in result[0]:
      print res
  </code></pre>
  
  <p>If I get it right, now I am getting a probability for each class as an output. How can I retrieve labels back after I have called "to_categorical" on it?</p>
  
  <p>Is there a way to get a class number, instead of probability for each class?</p>
  
  <p>For now it does not seem to be working right, big loss ~2, accuracy ~0.29 and I cannot make it to converge. What am I doing wrong?</p>
  
  <p><strong>UPDATE Mar 19</strong>
  So far I have solved my problem, I changed my model a lot of times and finally found working configuration.</p>