Commit 9d5d914b authored by Shalitha Deshan Jayasekara's avatar Shalitha Deshan Jayasekara 🏘

Merge branch 'IT18116984_WeerasundaraD.A' into 'master'

Add the required accuracy graph to the research paper

See merge request !16
parents 3905567d 875c95ef
.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
import pandas as pd
import tensorflow as tf
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
model = tf.keras.models.Sequential()
......@@ -9,28 +10,49 @@ def trainModel(model, datasetFilePath):
model.add(tf.keras.layers.Flatten())
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(46, activation=tf.nn.softmax))
model.add(tf.keras.layers.Dense(11, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model_df = pd.read_csv(datasetFilePath)
X = model_df.values[:,0:15]
y = model_df.values[:,15]
print(model_df.shape)
X = model_df.values[:,0:18]
y = model_df.values[:,18]
print(y)
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_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)
print(val_loss)
print(val_acc)
print("Loss: ",val_loss)
print("Accuracy: ",val_acc*100, "%")
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
def predict(model, data):
return model.predict(numpy.array(data))
trainModel(model, "data.csv")
......@@ -10,7 +10,7 @@ model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
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(46, activation=tf.nn.softmax))
model.add(tf.keras.layers.Dense(11, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
......@@ -21,4 +21,6 @@ def predict(data):
return model.predict(numpy.array(data))
# 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