0
$\begingroup$

I'm working on a research project with the goal of using a neural network to predict disease outcomes for patients. I've built a neural network using Tensorflow and Keras and I've trained and tested it on my data. It supposedly has great accuracy. The output in the console says that it's getting 90+% accuracy. However, I don't know how to match outputs from the neural network with the original individuals. All I see are the overall statistics.

What I want is to feed data into my neural network for a specific individual and then see what my neural network predicts for that person. I could feed in an array with the data for one patient, and then see what the neural network predicts for that patient, with a binary outcome.

If I just look at my y_pred and y_test arrays, they don't seem to correlate very well with each other. Also, the length of these arrays is longer than my input data. How can input the results for one specific individual and see what the neural network predicts for that individual?

This is what my code looks like:


import tensorflow as tf

from keras.models import Sequential

import pandas as pd

from keras.layers import Dense

data = pd.read_csv('data.csv', delimiter=',')

labels=data['outcome']

features = data.iloc[:,2:33]

import numpy as np

from sklearn.model_selection import train_test_split

X=features

y=np.ravel(labels)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.6, random_state=42)

from sklearn.preprocessing import StandardScaler

scaler = StandardScaler().fit(X_train)

X_train = scaler.transform(X_train)

X_test = scaler.transform(X_test)


model = Sequential()

model.add(Dense(8, activation='relu', input_shape=(31,))) #31 is the number of input variables

model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy',
optimizer='sgd',
metrics=['accuracy'])

model.fit(X_train, y_train,epochs=8, batch_size=1, verbose=1)

y_pred = model.predict(X_test)

score = model.evaluate(X_test, y_test,verbose=1)

print(score)

This gives an overall score for the accuracy of the model.

However, what can I do to input the data for on patient and have the neural network return it's prediction for that one patient?

Trying something like this doesn't work:

testperson = [1,....,0] #data for the person

guess = model.predict(testperson)

print(guess)

Any advice?

$\endgroup$
1
  • 1
    $\begingroup$ The way you're trying to predict for a single sample is correct, however you might need to enclose the list of values in another list so it's batch of data (e.g. model.predict([testperson])). What error do you get using your current code? $\endgroup$
    – Oxbowerce
    Mar 14 at 17:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.