为什么我的Keras神经网络的精度为零?

时间:2019-07-08 04:25:16

标签: machine-learning neural-network feed-forward

我正在尝试训练神经网络以执行简单的映射,即X到Y。在这种情况下,我试图将值映射到其相应的错误。 X和Y均为大小为1077的数组。

数据有很多噪音,并且这种关系基本上是不存在的。因此,我决定选择分类而不是回归。如果使用MSE(如下所示),则精度永远不会超过零,并且损失是巨大且不变的。

# Data preprocessing
from sklearn.model_selection import train_test_split

A_train, A_test, Aerror_train, Aerror_test = train_test_split(A, A_error, 
test_size=0.33, random_state=42)

# Defining and compiling the model
model = Sequential() # initializing a sequential model
model.add(Dense(1, activation = 'relu', input_shape = (1,))) #first layer 
model.add(Dropout(0.2)) 
model.add(Dense(1, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation ='softmax'))

model.summary()
model.compile(loss = 'mean_squared_error', optimizer = 'sgd', 
metrics = ['accuracy'] ) #sgd = stochastic gradient descent, cat_ce = 
probability that increases as the predicted and actual values diverge

如果我尝试使用损失函数稀疏分类交叉熵,因为我想进行多标签分类

我收到以下错误:

InvalidArgumentError (see above for traceback): Received a label value of 
15614 which is outside the valid range of [0, 1).

0 个答案:

没有答案
相关问题