我想从给定的向量(大小=250,二进制元素)中预测标量值(介于0和100之间)。我有一个数据集,它包含1000个x值和1000个y值:
>>>in_.shape
(1000, 250)
>>>in_[0]
array([1, 0, 1, 1, 1, 1, 1, 1, ...])
>>>out.shape
(1000,)
>>>out[0]
64.46677867594474
我写了一个模型,但它似乎不工作。下面是代码片段,您可以在这里找到数据集https://ufile.io/f/yt61u:
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
in_ = np.load('input.npy')
out = np.load('output.npy')
model = keras.Sequential([
keras.Input(shape=(250,)),
layers.Dense(1000, activation='relu'),
layers.Dense(1000, activation='relu'),
layers.Dense(250, activation='relu'),
layers.Dense(1, activation='linear')])
model.compile(loss='binary_crossentropy', optimizer='adam',
metrics=['accuracy'])
model.fit(in_, out, batch_size=100, epochs=5, validation_split=0.1)
如何改善这一点?
Epoch 1/5
9/9 [==============================] - 2s 54ms/step - loss: -240.3843 - accuracy: 0.0000e+00 - val_loss: -54.9291 - val_accuracy: 0.0000e+00
Epoch 2/5
9/9 [==============================] - 0s 18ms/step - loss: -311.0255 - accuracy: 0.0000e+00 - val_loss: -54.9291 - val_accuracy: 0.0000e+00
Epoch 3/5
9/9 [==============================] - 0s 20ms/step - loss: -311.0255 - accuracy: 0.0000e+00 - val_loss: -54.9291 - val_accuracy: 0.0000e+00
Epoch 4/5
9/9 [==============================] - 0s 18ms/step - loss: -311.0254 - accuracy: 0.0000e+00 - val_loss: -54.9291 - val_accuracy: 0.0000e+00
Epoch 5/5
9/9 [==============================] - 0s 18ms/step - loss: -311.0255 - accuracy: 0.0000e+00 - val_loss: -54.9291 - val_accuracy: 0.0000e+00
1条答案
按热度按时间zbq4xfa01#
这是可行的: