[英]Binary time series forecasting with LSTM in python
您好,我正在使用二進制時間序列的表達式數據,如下所示:
0: decrease expression
1: increase expression
我正在訓練一個雙向 LSTM 網絡來預測下一個值,但它沒有給我 0 或 1 的值,而是返回如下值:
0.564
0.456
0.423
0.58
我怎樣才能讓它返回 0 或 1?
這是我的代碼:
ventana = 10
n_features = 1
neurons = 256 #155
activacion = 'softmax'
perdida = 0.25
batch_size = 32 # 32
epochs = 100 # 200
X, y = split_sequence(cierres, ventana)
X = X.reshape((X.shape[0], X.shape[1], n_features))
# define model
model = Sequential()
model.add(Bidirectional(LSTM(neurons, activation=activacion), input_shape=(ventana, n_features)))
model.add(Dropout(perdida))
model.add(Dense(1))
model.compile(optimizer='adam', loss='binary_crossentropy')
# fit model
model.fit(X, y, epochs=epochs, batch_size=batch_size, verbose=1, shuffle=False)
網絡有效地對數據執行回歸,並沒有給出精確的 0 或 1。通過給出介於兩者之間的數字,它產生了一定程度的置信度,數字更接近 1 更可信地為 1。要轉換它,您可以應用thresholding ,將 output 舍入為 0 或 1。
import numpy as np
y_out = model.fit(...)
y_pred = np.round(y_out)
話雖如此,這實際上並沒有最小化某些損失函數。 如果您在像 MSE 這樣的 function 上得分,最好保持數字不變。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.