我有一个大小为(5,5)的矩阵A,也有一个大小为(5,5)的矩阵C.矩阵A和矩阵C满足以下关系C = np.dot(A,B) 。
我假装矩阵B是未知的。实际上,B也是大小为(5,5)的固定矩阵。如果我有100个A和C样本,并且我想在有A'个使用角点的情况下预测矩阵C'。 以下是我的喀拉拉邦代码:
x_train, y_train = x_data[:90], y_data[:90] # x_data and y_data is my data . the shape of x_train and y_train :(90,25),I have reshape the input A (100,5,5)into (100,25)
x_test, y_test = x_data[90:], y_data[90:] #the shape of x_test and y_test :(10,25)
model = Sequential ()
model.add(layers.Dense(64,activation='relu', input_dim=25))
model.add(layers.Dense(64,activation='relu'))
model.add(layers.Dense(25))
model.compile(optimizer='rmsprop',
loss='mse',
metrics=['accuracy'])
for step in range(1001):
cost=model.fit(x_train,y_train,epochs=20,batch_size=32)
if step % 100 == 0:
print('train cost: ', cost)
输出为
Epoch 13/20
90/90 [==============================] - 0s 66us/step - loss: 6.7246 - accuracy: 1.0000
Epoch 14/20
90/90 [==============================] - 0s 55us/step - loss: 8.5773 - accuracy: 1.0000
Epoch 15/20
90/90 [==============================] - 0s 66us/step - loss: 6.8627 - accuracy: 1.0000
Epoch 16/20
90/90 [==============================] - 0s 55us/step - loss: 7.6821 - accuracy: 1.0000
Epoch 17/20
90/90 [==============================] - 0s 66us/step - loss: 13.0541 - accuracy: 1.0000
Epoch 18/20
90/90 [==============================] - 0s 44us/step - loss: 12.1049 - accuracy: 1.0000
Epoch 19/20
90/90 [==============================] - 0s 44us/step - loss: 6.2855 - accuracy: 1.0000
Epoch 20/20
90/90 [==============================] - 0s 55us/step - loss: 6.8535 - accuracy: 1.0000
没有错误, 损失是6.8535。
当我输入矩阵A'并通过C''= np.dot(A',B)将预测的C'与计算的C''进行比较时, 我发现它们完全不同。
我不知道为什么以及如何减少损失。 我对机器学习和keras非常陌生。我希望有一个人可以帮助我 。 非常感谢。