Commit 875c95ef authored by dinithi1997's avatar dinithi1997

Add the required accuracy graph to the research paper

parent 30f512e9
.idea
\ No newline at end of file
# Default ignored files
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/disease_prediction.iml" filepath="$PROJECT_DIR$/.idea/disease_prediction.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
...@@ -2,6 +2,7 @@ import numpy ...@@ -2,6 +2,7 @@ import numpy
import pandas as pd import pandas as pd
import tensorflow as tf import tensorflow as tf
from sklearn.model_selection import train_test_split from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
model = tf.keras.models.Sequential() model = tf.keras.models.Sequential()
...@@ -9,28 +10,49 @@ def trainModel(model, datasetFilePath): ...@@ -9,28 +10,49 @@ def trainModel(model, datasetFilePath):
model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(256, activation=tf.nn.relu)) model.add(tf.keras.layers.Dense(256, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu)) model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(46, activation=tf.nn.softmax)) model.add(tf.keras.layers.Dense(11, activation=tf.nn.softmax))
model.compile(optimizer='adam', model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy', loss='sparse_categorical_crossentropy',
metrics=['accuracy']) metrics=['accuracy'])
model_df = pd.read_csv(datasetFilePath) model_df = pd.read_csv(datasetFilePath)
X = model_df.values[:,0:15] print(model_df.shape)
y = model_df.values[:,15] X = model_df.values[:,0:18]
y = model_df.values[:,18]
print(y) print(y)
x_train,x_test,y_train,y_test = train_test_split(X,y, stratify=y,test_size=0.2) x_train,x_test,y_train,y_test = train_test_split(X,y, stratify=y,test_size=0.2)
x_train = tf.keras.utils.normalize(x_train, axis=1) x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1) x_test = tf.keras.utils.normalize(x_test, axis=1)
model.fit(x_train, y_train, epochs=3) history = model.fit(x_train, y_train, epochs=50, validation_data=(x_test, y_test))
val_loss, val_acc = model.evaluate(x_test, y_test) val_loss, val_acc = model.evaluate(x_test, y_test)
print(val_loss) print("Loss: ",val_loss)
print(val_acc) print("Accuracy: ",val_acc*100, "%")
model.save('model.h5') model.save('model.h5')
print(history.history)
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
return model return model
def predict(model, data): def predict(model, data):
return model.predict(numpy.array(data)) return model.predict(numpy.array(data))
trainModel(model, "data.csv") trainModel(model, "data.csv")
...@@ -10,7 +10,7 @@ model = tf.keras.models.Sequential() ...@@ -10,7 +10,7 @@ model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(256, activation=tf.nn.relu)) model.add(tf.keras.layers.Dense(256, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu)) model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(46, activation=tf.nn.softmax)) model.add(tf.keras.layers.Dense(11, activation=tf.nn.softmax))
model.compile(optimizer='adam', model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy', loss='sparse_categorical_crossentropy',
...@@ -21,4 +21,6 @@ def predict(data): ...@@ -21,4 +21,6 @@ def predict(data):
return model.predict(numpy.array(data)) return model.predict(numpy.array(data))
# Test prediction # Test prediction
print(numpy.argmax(predict([[1,3,1,1,1,0,0,1,1,0,1,0,0,1,1]]))) print(predict([[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0]]))
print(numpy.argmax(predict([[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0]])))
print(disease_labels[numpy.argmax(predict([[1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0]]))])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment