title: MLP classifier_for multi class
body: <p>I am newbie on keras,</p>
  
  <p>I try to follow the Keras tutorial for Multilayer Perceptron (MLP) for multi-class softmax classification, using my data set.
  My data has 3 classes and only one feature, but I don't understand why the result always show just 0,3 of accuracy and the model predicted all training data as first class. then the confusion matrix is like this. </p>
  
  <p><a href="https://i.stack.imgur.com/2lo9e.jpg" rel="nofollow noreferrer">Confusion matrix</a></p>
  
  
  
  <p>Here the coding:</p>
  
  <pre class="lang-python prettyprint-override"><code>import keras
  from keras.models import Sequential
  from keras.layers import Dense, Dropout, Activation
  from keras.optimizers import SGD
  import pandas as pd
  import numpy as np
  
  
  
  # Importing the dataset
  dataset = pd.read_csv('StatusAll.csv')
  X = dataset.iloc[:, 1:].values
  y = dataset.iloc[:, 0:1].values
  
  
  # Splitting the dataset into the Training set and Test set
  from sklearn.model_selection import train_test_split
  x_train, x_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
  
  from keras.utils import to_categorical
  y_train = to_categorical(y_train)
  y_test = to_categorical(y_test)
  
  model = Sequential()
  
  # Dense(64) is a fully-connected layer with 64 hidden units.
  # in the first layer, you must specify the expected input data shape:
  # here, 20-dimensional vectors.
  model.add(Dense(64, activation='tanh', input_dim=1))
  model.add(Dropout(0.5))
  model.add(Dense(64, activation='tanh'))
  model.add(Dropout(0.5))
  model.add(Dense(4, activation='softmax'))
  
  sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
  
  model.compile(loss='categorical_crossentropy',
                optimizer=sgd,
                metrics=['accuracy'])
  
  history = model.fit(x_train, y_train,
            epochs=100,
            batch_size=128)
  score = model.evaluate(x_test, y_test, batch_size=128)
  print('Test score:', score[0])
  print('Test accuracy:', score[1])
  
  
  from sklearn import metrics
  
  prediction = model.predict(x_test)
  prediction = np.around(prediction)
  
  y_test_non_category = [ np.argmax(t) for t in y_test ]
  y_predict_non_category = [ np.argmax(t) for t in prediction ]
  
  from sklearn.metrics import confusion_matrix
  conf_mat = confusion_matrix(y_test_non_category, y_predict_non_category)
  
  print (conf_mat)         
  </code></pre>
  
  <p>I hope I can get some advice, thanksss.</p>
  
  <p>The x_train example
  <a href="https://i.stack.imgur.com/4ErV4.jpg" rel="nofollow noreferrer">x_train</a></p>
  
  <p><a href="https://i.stack.imgur.com/ZMpqL.jpg" rel="nofollow noreferrer">y_train before converted to categorical</a></p>
  
  <p><a href="https://i.stack.imgur.com/eqMM3.jpg" rel="nofollow noreferrer">enter image description here</a></p>