My MLP code:
# In[1]:
import pandas as pd
from keras.models import Sequential #Sequential Models
from keras.layers import Dense #Dense Fully Connected Layer Type
from keras.optimizers import SGD #Stochastic Gradient Descent Optimizer
from keras.callbacks import EarlyStopping
from keras.callbacks import ModelCheckpoint
# In[2]:
data = pd.read_csv("doom.csv", delimiter=",")
data = data.drop('id', 1)
data = data.drop('cid', 1)
data = data.drop('alerts', 1)
data = data.drop('hsalerts', 1)
data = data.drop('capacity', 1)
data = data.drop('duplicate', 1)
data.shape
# In[3]:
data.selectedoption.value_counts()
# In[4]:
feature = data.drop('selectedoption',axis=1)
label = data[['selectedoption']]
# In[5]:
from sklearn.model_selection import train_test_split
train_feature, test_feature, train_label, test_label= train_test_split(
feature, label, test_size=0.3, random_state=42)
# In[ ]:
# In[ ]:
# In[6]:
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit(train_feature)
train_feature_trans = scaler.transform(train_feature)
test_feature_trans = scaler.transform(test_feature)
# In[7]:
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
import matplotlib.pyplot as plt
def show_train_history(train_history,train,validation):
plt.plot(train_history.history[train])
plt.plot(train_history.history[validation])
plt.title('Train History')
plt.ylabel(train)
plt.xlabel('Epoch')
plt.legend(['train', 'validation'], loc='best')
plt.show()
# In[11]:
from keras import optimizers
model = Sequential()
model.add(Dense(units=32,
input_dim=10,
kernel_initializer='uniform',
activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(units=32,
kernel_initializer='uniform',
activation='sigmoid'))
model.add(Dropout(0.5))
model.add(Dense(units=16,
kernel_initializer='uniform',
activation='softmax'))
model.add(Dropout(0.5))
model.add(Dense(units=1,
kernel_initializer='uniform',
activation='sigmoid'))
print(model.summary())
adam = optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(loss='binary_crossentropy',
optimizer='adam', metrics=['accuracy'])
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=200)
mc = ModelCheckpoint('best_model.h5', monitor='val_acc', mode='max', verbose=1, save_best_only=True)
train_history = model.fit(x=train_feature_trans, y=train_label,
validation_split=0.8, epochs=20000,
batch_size=1000, verbose=2,callbacks=[es, mc])
show_train_history(train_history,'acc','val_acc')
show_train_history(train_history,'loss','val_loss')
# In[9]:
scores = model.evaluate(test_feature_trans, test_label)
print('\n')
print('accuracy=',scores[1])
My dataset is this:
I made a few changes like, changing the optimizer, changing the learning rate, changing activation functions, changing the units. Nothing seems to work. The accuracy isn't going above 80%. Is there something that i can do to improve the accuracy over 90%? I am a newbie to this. Thank you.