in Education by
I am trying to make an app that can get the patient's symptoms as inputs and outputs the three most likely diseases. x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.4) inputs = keras.Input(shape=(9,)) hidden_1 = keras.layers.Dense(12, activation='selu')(inputs) hidden_2 = keras.layers.Dense(12, activation='relu')(hidden_1) outputs = keras.layers.Dense(32, activation='sigmoid')(hidden_2) model = keras.Model(inputs=inputs, outputs=outputs) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['categorical_accuracy']) model.summary() model.fit(x_train, y_train, epochs=200) # starts training prediction = model.predict(x_test) print(prediction) scores = model.evaluate(x_test, y_test, verbose=0) print(scores) print(prediction[0]) print(y_test[0]) model.save("modeldisease.h5") but when i save and load this model into another python file, the outputs list looks like this: [[0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00 0.000000e+00 0.000000e+00 1.842211e-21 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00 0.000000e+00]] 100.0 100.0 100.0 HEPATITE A HEPATITE_ALCOOLICA REFLUXO_GASTROESOFAGICO Process finished with exit code 0 What am I doing wrong? shouldn't it just return me this prediction list with all the values adding up to 1? full code: ` from tensorflow import keras import numpy as np import sklearn from sklearn import preprocessing import pandas as pd data = pd.read_csv("DATA.csv", sep=";") obj_data = data.select_dtypes(include=["object"]).copy() obj_data_names = [] for col in obj_data.columns: obj_data_names.append(col) for col_name in obj_data_names: data[col_name] = data[col_name].astype('category') data[col_name + "_cat"] = data[col_name].cat.codes data[col_name] = data[col_name + "_cat"] data.drop(col_name + "_cat", 1, inplace=True) print(data) data.fillna(0, inplace=True) x = np.array(data.drop(["Doenca"], 1)) y = np.array(data["Doenca"]) x = preprocessing.normalize(x) y = keras.utils.to_categorical(y) x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.4) inputs = keras.Input(shape=(9,)) hidden_1 = keras.layers.Dense(12, activation='selu')(inputs) hidden_2 = keras.layers.Dense(12, activation='relu')(hidden_1) outputs = keras.layers.Dense(32, activation='sigmoid')(hidden_2) model = keras.Model(inputs=inputs, outputs=outputs) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['categorical_accuracy']) model.summary() model.fit(x_train, y_train, epochs=200) # starts training prediction = model.predict(x_test) print(prediction) scores = model.evaluate(x_test, y_test, verbose=0) print(scores) print(prediction[0]) print(y_test[0]) model.save("modeldisease.h5") for i in range(len(y_test)): max_expected = np.amax(y_test[i]) #print(max_expected) y_expected = np.where(y_test[i] == max_expected) print(y_expected[0]) max_predicted = np.amax(prediction[i]) #print(max_predicted) y_predicted = np.where(prediction[i] == max_predicted) print(y_predicted[0]) classes = ["ACNE", "AIDS", "ALERGIA", "ARTRITE", "ARTROSE", "CATAPORA", "COLESTASE", "DENGUE", "DIABETES", "ENXAQUECA", "ESPONDILOSE", "FEBRE_TIFOIDE", "GASTROENTERITE", "GRIPE", "HEPATITE_ALCOOLICA", "HEPATITE A", "HEPATITE B", "HEPATITE C", '"HEPATITE D', "HEPATITE E", "HIPERTENSAO", "HIPERTENSAO", "HIPERTIROIDISMO", "HIPOGLICEMIA", "HIPOTIREODISMO", "IMPETIGO", "INFECCA_URINA", "MALARIA", "PNEUMONIA", "PSORIASE", "REFLUXO_GASTROESOFAGICO", 'TUBERCULOSE', "ULCERA GASTRICA"] print(f"Valor esperado: {classes[int(y_expected[0])]}, Valor previsto: {classes[int(y_predicted[0])]}") # print(prediction[0][0]) # print(round(prediction[0][0])) # print(classes[round(int(prediction[0][0]))]) #print(y_test) #print(prediction) load code: from tensorflow import keras model = keras.models.load_model("modeldisease.h5") result = model.predict([(12, 40, 39, 17, 0, 0, 0, 0, 0)]) print(result) sortedshit = result[0].argsort()[-3:][::-1] p1 = result[0][sortedshit[0]] p2 = result[0][sortedshit[1]] p3 = result[0][sortedshit[2]] classes = ["ACNE", "AIDS", "ALERGIA", "ARTRITE", "ARTROSE", "CATAPORA", "COLESTASE", "DENGUE", "DIABETES", "ENXAQUECA", "ESPONDILOSE", "FEBRE_TIFOIDE", "GASTROENTERITE", "GRIPE", "HEPATITE_ALCOOLICA", "HEPATITE A", "HEPATITE B", "HEPATITE C", '"HEPATITE D', "HEPATITE E", "HIPERTENSAO", "HIPERTENSAO", "HIPERTIROIDISMO", "HIPOGLICEMIA", "HIPOTIREODISMO", "IMPETIGO", "INFECCA_URINA", "MALARIA", "PNEUMONIA", "PSORIASE", "REFLUXO_GASTROESOFAGICO", 'TUBERCULOSE', "ULCERA GASTRICA"] print(p1*100, p2*100, p3*100) print(classes[sortedshit[0]], classes[sortedshit[1]], classes[sortedshit[2]]) Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Apply softmax activation function instead of sigmoid: outputs = keras.Dense(32,activation='softmax')(hidden_2) Do check out Data Science with Python course which helps you understand from scratch

Related questions

0 votes
    I am receiving the error: ValueError: Wrong number of items passed 3, placement implies 1, and I am struggling to ... 'sigma'] = sigma Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I am totally new to Machine Learning and I have been working with unsupervised learning technique. Image shows my ... 3 were given Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I know a little of Python and more than a year ago I wrote a small script, using pipenv to manage the ... 3.0 should work. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I had some Python 2 code as follows (pardon the indentation): def getZacksRating(symbol): c = httplib.HTTPSConnection("www. ... data.split(' ')[1] result = ratingPart.partition("...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I used the pyhton: for m in regex.findall(r"\X", 'ल्लील्ली', regex.UNICODE): for i in m: print(i, i.encode(' ... कृ','प','या','ल्ली' Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have just built my first model using Keras and this is the output. It looks like the standard output you get ... - loss: 0.1928 Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I'm starting with input data like this df1 = pandas.DataFrame( { "Name" : ["Alice", "Bob", "Mallory", ... Any hints would be welcome. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    This is my code that displays output that I would like to alter: import json from collections import OrderedDict ... find anything. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have the dataset that has the no_employees column that is the str object. whats is a best way to create the new ... 1-5 |Very Small Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am new to python, I have this code: # columns are [0]title [1]year [2]rating [3]length(min) [4]genre ... make that int into a list? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    This is my code it's just starting the scan but it is not completing ,where is the error in it. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I want to save files for each result from the loop. For example, I wrote the code but it only saves one file ... do I modify my code? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
...