1
我正在訓練一個包含標籤總是等於0的數據集的簡單模型,並且獲得0.0的準確性。簡單模型得到0.0的準確性
的模型是如下:
import csv
import numpy as np
import pandas as pd
import tensorflow as tf
labelsReader = pd.read_csv('data.csv',usecols = [12],header=None)
dataReader = pd.read_csv('data.csv',usecols = [1,2,3,4,5,6,7,8,9,10,11],header=None)
labels_ = labelsReader.values
data_ = dataReader.values
labels = np.float32(labels_)
data = np.float32(data_)
x = tf.placeholder(tf.float32, [None, 11])
W = tf.Variable(tf.truncated_normal([11, 1], stddev=1./11.))
b = tf.Variable(tf.zeros([1]))
y = tf.matmul(x, W) + b
# Define loss and optimizer
y_ = tf.placeholder(tf.float32, [None, 1])
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
for i in range(0, 1000):
train_step.run(feed_dict={x: data, y_: labels})
correct_prediction = tf.equal(y, y_)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: data, y_: labels}))
這裏是數據集:
444444,0,0,0.9993089149965446,0,0,0.000691085003455425,0,0,0,0,0,0
作爲模型火車,上面示出的數據Y的減小,並達到-1000 1000之後迭代。
未能培訓模型的原因是什麼?
謝謝您的回答,價值444444不實際使用,它是而不是在「usecols」中,對於交叉熵,精度始終爲0,模型預測隨着訓練的進行而減少的負數。 – awpsoleet