我正在尝试训练神经网络进行简单的映射,即 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).