我的模型似乎不起作用,因为准确度和损失均为0 [英] My model doesn't seem to work, as accuracy and loss are 0

查看:347
本文介绍了我的模型似乎不起作用,因为准确度和损失均为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用keras设计LSTM网络,但精度为0.00,而损失值为0.05,我编写的代码如下.

I tried to design an LSTM network using keras but the accuracy is 0.00 while the loss value is 0.05 the code which I wrote is below.

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation = tf.nn.relu))
model.add(tf.keras.layers.Dense(1, activation = tf.nn.relu))



def percentage_difference(y_true, y_pred):
    return K.mean(abs(y_pred/y_true - 1) * 100)



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

model.fit(x_train, y_train.values, epochs = 10)


我的输入火车和测试数据集已使用熊猫的库导入.功能数量为5,目标数量为1.所有努力将不胜感激.

my input train and test data set have been imported using the pandas' library. The number of features is 5 and the number of target is 1. All endeavors will be appreciated.

推荐答案

据我所知,您正在使用应用于回归问题的神经网络.

From what I see is that you're using a neural network applied for a regression problem.

回归是通过学习各种独立功能来预测 continuous值的任务.

Regression is the task of predicting continuous values by learning from various independent features.

因此,在回归问题中,我们没有像accuracy这样的metrics,因为这是supervised学习的classification分支.

So, in the regression problem we don't have metrics like accuracy because this is for classification branch of the supervised learning.

回归accuracy等效值可以是确定系数R^2 Score.

from keras import backend as K

def coeff_determination(y_true, y_pred):
    SS_res =  K.sum(K.square( y_true-y_pred ))
    SS_tot = K.sum(K.square( y_true - K.mean(y_true) ) )
    return ( 1 - SS_res/(SS_tot + K.epsilon()) )

model.compile(optimizer='sgd', 
         loss='mse',
         metrics = [coeff_determination])

这篇关于我的模型似乎不起作用,因为准确度和损失均为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆