在神经网络中输入了错误的值

时间:2019-06-13 03:14:32

标签: python tensorflow neural-network

我想使用神经网络学习以下数据并测量天气得分。

但是,如图所示,结果为零,精度为100%。

如何解决问题?

import pandas as pd
import tensorflow as tf
import numpy as np

data = pd.read_csv('weather_data.csv')
tbl = data.drop('CREATE_DT', axis=1)
a = ['high_temp', 'daily_temp', 'Hum', 'prec']
x_data = np.array(tbl[a])
y_data = np.array(tbl['point']).reshape(660, 1)

X = tf.placeholder(tf.float32, shape=[None, 4])
Y = tf.placeholder(tf.float32, shape=[None, 1])

W1 = tf.Variable(tf.random_uniform([4, 4], -1., 1.))

#neural network model pass..

W6 = tf.Variable(tf.random_normal([3, 1]))
b6 = tf.Variable(tf.zeros([1]))

model = tf.add(tf.matmul(L3, W6), b6)

cost = tf.reduce_mean(
    tf.nn.softmax_cross_entropy_with_logits_v2(labels=Y, logits=model))

optimizer = tf.train.AdamOptimizer(learning_rate=0.01)
train_op = optimizer.minimize(cost)

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

for step in range(1000):
    sess.run(train_op, feed_dict={X: x_data, Y: y_data})

    if (step + 1) % 10 == 0:
        print(step + 1, sess.run(cost, feed_dict={X: x_data, Y: y_data}))

prediction = tf.argmax(model, 1)
target = tf.argmax(Y, 1)
print('Predicted value:', sess.run(prediction, feed_dict={X: x_data}))
print('Actual value:', sess.run(target, feed_dict={Y: y_data}))

is_correct = tf.equal(prediction, target)
accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))
print('Accuracy: %.2f' % sess.run(accuracy * 100, feed_dict={X: x_data, Y: y_data}))
sess.close()

enter image description here enter image description here

0 个答案:

没有答案