我试图在我的数据上运行此代码以进行回归。看起来网络可以预测第一个测试数据,但所有其他预测与第一个测试数据相同。第一个函数为初始化生成随机权重。预测变量的数量是54,输出的数量是4.这里是我的代码:我的DNN对所有测试数据(tensorflow)返回相同的预测结果
def init_weights(shape):
weights = tf.random_uniform(shape, -2,2)
return tf.Variable(weights)
def forwardprop(X, w, b, sig):
if sig==1:
yhat = tf.sigmoid(tf.add(tf.matmul(X, w),b))
else:
yhat = tf.add(tf.matmul(X, w),0.)
return yhat
def main(itr,starter_learning_rate):
x_size = train_X.shape[1]
h_size = 4
y_size = train_y.shape[1]
X = tf.placeholder("float", shape = [None, x_size])
y = tf.placeholder("float", shape = [None, y_size])
w_1 = init_weights((x_size, h_size))
b_1 = tf.constant(1.)
w_2 = init_weights((h_size, y_size))
b_2 = tf.constant(1.)
yhat_1 = forwardprop(X, w_1, b_1, 1)
yhat = forwardprop(yhat_1, w_2, b_2, 0)
n_samples = train_X.shape[

在尝试使用TensorFlow进行回归预测时,作者发现DNN模型只能正确预测首个测试数据,其余预测均与首个结果相同。代码中定义了权重初始化、前向传播函数,并使用梯度下降优化器进行训练。尽管模型能处理输入和输出维度,但在多次迭代后,测试集上的预测准确率并未提升。
最低0.47元/天 解锁文章
992

被折叠的 条评论
为什么被折叠?



