我的神经网络试图预测一个人是否患有糖尿病,这是我的数据集
kaggle.com/uciml/pima-indians-diabetes-database。我使用的是 3 层神经网络,我的准确率为 65%。
任何提高准确性的帮助将不胜感激。
这是我的代码---------------------------------- ------------
import numpy as np
import tensorflow as tf
import pandas as pd
df=pd.read_csv(r'C:\Users\manas\Downloads\diabetes.csv')
actualY=df['Outcome']
actualX=df.drop(['Outcome'],axis=1)
actualX=np.array(np.reshape(actualX,newshape=[768,8]))
actualY=np.array(np.reshape(actualY,newshape=[768,1]))
#Y=[768,1]
#X=[768,8]
x=tf.placeholder(dtype=tf.float64,shape=[768,8])
W1=tf.Variable(dtype=np.float64,initial_value=np.random.random((8,500)))
B1=tf.Variable(dtype=np.float64,initial_value=np.random.random((1,1)))
y_prediction1=((tf.add(tf.matmul(x,W1),B1)))
output1=tf.nn.sigmoid(y_prediction1)
W2=tf.Variable(dtype=np.float64,initial_value=np.random.random((500,600)))
B2=tf.Variable(dtype=np.float64,initial_value=np.random.random((1,1)))
y_prediction2=((tf.add(tf.matmul(output1,W2),B2)))
output2=tf.nn.sigmoid(y_prediction2)
W3=tf.Variable(dtype=np.float64,initial_value=np.random.random((600,1)))
B3=tf.Variable(dtype=np.float64,initial_value=np.random.random((1,1)))
y_prediction3=((tf.add(tf.matmul(output2,W3),B3)))
y_true=tf.placeholder(dtype=tf.float64,shape=[768,1])
loss=tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=y_prediction3,labels=y_true))
optimizer=tf.train.GradientDescentOptimizer(0.01).minimize(loss)
sess=tf.Session()
sess.run(tf.global_variables_initializer())
for i in range(200):
(sess.run(optimizer,feed_dict={x:actualX,y_true:actualY}))
print(i,sess.run(loss, feed_dict={x: actualX, y_true: actualY}))
print(i)
prediction = tf.round(tf.sigmoid((y_prediction3)))
correct = tf.cast(tf.equal(prediction, y_true), dtype=np.float64)
accuracy = tf.reduce_mean(correct)
print(sess.run(accuracy,feed_dict={x: actualX, y_true: actualY}))