I am trying to perform classification task using Keras and tensorflow. However, the learning converges after achieving an accuracy of 57%. All my inputs and outputs are categorical data. Am I using the correct approach to train? Are there any other example in the web which is trying to solve the similar problem?
data.csv
religion,caste,qualification,marital_status,sex,nature_activity
2,20,5,1,1,10
2,20,5,1,1,10
2,20,5,1,1,10
2,20,5,1,1,10
1,3,5,1,1,13
1,4,4,1,2,3
1,3,4,2,1,1
1,3,3,2,1,1
Source code
from keras.models import Sequential
from keras.layers import Dense
import pandas
from sklearn.metrics import classification_report
from sklearn.preprocessing import LabelEncoder
from keras.utils import np_utils
import numpy
from sklearn.model_selection import train_test_split
from keras.wrappers.scikit_learn import KerasClassifier
import sys
import matplotlib.pyplot as plt
# fix random seed for reproducibility
numpy.random.seed(7)
# load pima indians dataset
dataframe = pandas.read_csv("data.csv",header=None)
dataset=dataframe.values
# split into input (X) and output (Y) variables
X = dataset[:,0:4].astype(float)
Y = dataset[:,4]
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.0015, random_state=42)
encoder = LabelEncoder()
encoder.fit(Y_train)
encoded_Y = encoder.transform(Y_train)
one_hot_enc_Y=np_utils.to_categorical(encoded_Y)
model=Sequential()
model.add(Dense(500,input_dim=4,activation='relu'))
model.add(Dense(100,activation='relu'))
model.add(Dense(50,activation='relu'))
model.add(Dense(3,activation='softmax'))
# Compile model
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
# Fit the model
history=model.fit(X_train, one_hot_enc_Y, validation_split=0.33,epochs=300, batch_size=5)
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
# summarize history for loss
plt.plot(history.history['loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train'], loc='upper right')
plt.show()
# evaluate the model
scores = model.evaluate(X_train, one_hot_enc_Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
sys.exit()