[英]My model doesn't seem to work, as accuracy and loss are 0
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.我尝试使用 keras 设计一个 LSTM 网络,但精度为 0.00,而损失值为 0.05,我编写的代码如下。
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)
my input train and test data set have been imported using the pandas' library.我的输入训练和测试数据集是使用 Pandas 库导入的。 The number of features is 5 and the number of target is 1. All endeavors will be appreciated.
特征数为 5,目标数为 1。所有努力将不胜感激。
From what I see is that you're using a neural network applied for a regression problem.据我所知,您正在使用应用于回归问题的神经网络。
Regression is the task of predicting continuous
values by learning from various independent features.回归是通过学习各种独立特征来预测
continuous
值的任务。
So, in the regression problem we don't have metrics
like accuracy
because this is for classification
branch of the supervised
learning.所以,在回归问题中,我们没有像
accuracy
这样的metrics
因为这是supervised
学习的classification
分支。
The equivalent of accuracy
for regression could be coefficient of determination or R^2 Score
.回归
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])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.