Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我的准确度总是0.0000e+;00,损失和巨大?_Python_Tensorflow_Machine Learning_Keras - Fatal编程技术网

Python 为什么我的准确度总是0.0000e+;00,损失和巨大?

Python 为什么我的准确度总是0.0000e+;00,损失和巨大?,python,tensorflow,machine-learning,keras,Python,Tensorflow,Machine Learning,Keras,我对机器学习非常陌生,这是我第一个使用tensorflow和keras的项目。我试图预测一个给定数据集的数值,但我的模型是有效的 x_train, x_test, y_train, y_test = train_test_split(dates, prices, test_size=0.33) x_train = np.reshape(x_train,(x_train.shape[0], 1, x_train.shape[1])) model = Sequential() model.add

我对机器学习非常陌生,这是我第一个使用tensorflow和keras的项目。我试图预测一个给定数据集的数值,但我的模型是有效的

x_train, x_test, y_train, y_test = train_test_split(dates, prices, test_size=0.33)


x_train = np.reshape(x_train,(x_train.shape[0], 1, x_train.shape[1]))
model = Sequential()
model.add(LSTM(30, return_sequences=True, input_shape= (x_train.shape[0], 1)))
# model.add(Flatten())
model.add(Dropout(0.25))
model.add(Dense(100,activation = 'relu'))
model.add(Dropout(0.25))
model.add(Dense(1,activation='softmax'))


model.compile(optimizer='adam',loss='mean_squared_error', metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=32, epochs=5)
这是我上面的模型,但无论何时运行,它都会显示以下内容:

Epoch 1/5
WARNING:tensorflow:Model was constructed with shape (None, 1686, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, 1686, 1), dtype=tf.float32, name='lstm_input'), name='lstm_input', description="created by layer 'lstm_input'"), but it was called on an input with incompatible shape (None, 1, 1).
WARNING:tensorflow:Model was constructed with shape (None, 1686, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, 1686, 1), dtype=tf.float32, name='lstm_input'), name='lstm_input', description="created by layer 'lstm_input'"), but it was called on an input with incompatible shape (None, 1, 1).
53/53 [==============================] - 2s 2ms/step - loss: 1314.1159 - accuracy: 0.0000e+00
Epoch 2/5
53/53 [==============================] - 0s 2ms/step - loss: 1332.1348 - accuracy: 0.0000e+00
Epoch 3/5
53/53 [==============================] - 0s 2ms/step - loss: 1307.5851 - accuracy: 0.0000e+00
Epoch 4/5
53/53 [==============================] - 0s 2ms/step - loss: 1327.0625 - accuracy: 0.0000e+00
Epoch 5/5
53/53 [==============================] - 0s 2ms/step - loss: 1314.4220 - accuracy: 0.0000e+00
<tensorflow.python.keras.callbacks.History at 0x7f1cdfc56668>
1/5纪元
警告:tensorflow:为输入KerasTensor(type_spec=TensorSpec(shape=(None,1686,1),dtype=tf.float32,name='lstm_input')、name='lstm_input',description=(由层'lstm_input'创建)构建的模型,但在具有不兼容形状(None,1,1)的输入上调用了该模型。
警告:tensorflow:为输入KerasTensor(type_spec=TensorSpec(shape=(None,1686,1),dtype=tf.float32,name='lstm_input')、name='lstm_input',description=(由层'lstm_input'创建)构建的模型,但在具有不兼容形状(None,1,1)的输入上调用了该模型。
53/53[===================================================2秒/步-损耗:1314.1159-精度:0.0000e+00
纪元2/5
53/53[================================================-0s 2ms/步-损耗:1332.1348-精度:0.0000e+00
纪元3/5
53/53[================================================-0秒/步-损耗:1307.5851-精度:0.0000e+00
纪元4/5
53/53[================================================-0s 2ms/步-损耗:1327.0625-精度:0.0000e+00
纪元5/5
53/53[=============================================-0秒/步-损耗:1314.4220-精度:0.0000e+00
有人知道如何修复此问题并提高准确性和损失吗?
非常感谢您的帮助。

如果您试图预测一个数值,那么您所做的不是分类问题,而是回归问题。因此,含有1个神经元的致密层应该没有激活功能。

用以下内容替换序列模型的最后一层:

model.add(稠密(1,内核初始化器='normal'))

回归任务不需要softmax作为激活函数,因为softmax主要用于多类分类

softmax不会与1个输出神经元匹配,至少2个零精度,因为损耗不会收敛(减少)