关联时序数据集降维:最优深度学习架构选型咨询
Hey there! Let's tackle your problem step by step.
Since your data is time-series with both inter-variable and temporal dependencies, the best fit here is an LSTM (Long Short-Term Memory) network. LSTMs are designed explicitly to capture long-term and short-term temporal patterns in sequential data, while naturally handling multi-variable inputs.
If you wanted a more compact alternative, you could also consider GRUs (Gated Recurrent Units), but LSTMs are more robust for capturing complex temporal relationships. For pure dimensionality reduction with sequence preservation, a time-series autoencoder (using LSTMs in encoder/decoder) works too—but since you're targeting a direct reduction to 1 dimension, an LSTM followed by a dense layer is simpler and more direct.
First, let's fix the input shape (Keras expects LSTM inputs in (batch_size, timesteps, features) format) and complete the model definition:
import numpy as np from keras.models import Sequential from keras.layers import LSTM, Dense # Your original dataset: 100 timesteps, 10 variables dataset = np.arange(1000).reshape(100, 10) # Reshape for LSTM: add batch dimension (here, we treat the entire sequence as 1 batch) X = dataset.reshape(1, 100, 10) # Define the model model = Sequential() # Add LSTM layer: 32 hidden units (adjust based on your needs), input shape matches (timesteps, features) model.add(LSTM(units=32, input_shape=(100, 10), return_sequences=False)) # Dense layer to reduce to 1 dimension model.add(Dense(units=1)) # Optional: Compile the model if you plan to train it (you'll need a target y for training) model.compile(optimizer='adam', loss='mse') # Print model summary to verify model.summary()
Key Notes:
- We reshape
Xto(1, 100, 10)because Keras requires a batch dimension. If you had multiple independent sequences, you'd adjust the batch size accordingly. - The
units=32in LSTM is a hyperparameter—you can tune this (try 16, 64, etc.) based on how much temporal information you need to capture. return_sequences=Falsemeans we only output the final hidden state of the LSTM (perfect for reducing the entire sequence to a single vector before the dense layer).- If you have a target value to train against (e.g., a label for each sequence), you'd need to define a
yarray and usemodel.fit(X, y, ...)to train the model.
内容的提问来源于stack exchange,提问作者Roman

