基于Keras的LSTM以太坊价格预测:归一化相关问题咨询
Hey there! Let's dive into your Ethereum price prediction workflow with Keras LSTM and work through the issues you're hitting.
First, let's align on your current setup to make sure I'm addressing the right pain points:
- You're building an LSTM to predict 10 future 15-second Ethereum prices (total 2.5 minutes) using 40 historical time steps
- Input features: Open, High, Low, Close prices
- Normalized data to the [0,1] range (smart call, since your dense layer uses linear activation)
- Current approach: Normalizing each sequence independently using its own minimum value
Common Pitfalls with Per-Sequence Normalization (and Fixes)
Chances are your issue ties back to this per-sequence scaling strategy—here's why, and how to adjust:
1. Real-Time Prediction Breakage
When you normalize each sequence separately, your model learns to depend on sequence-specific min values that won't be available in production. For example, when you deploy the model to predict live prices, you can't know the min of the future sequence you're trying to predict. This leads to mismatched scaling and unreliable predictions.
Fix: Use a global scaler fit on your entire training dataset (not per sequence). The MinMaxScaler from scikit-learn is perfect for this:
from sklearn.preprocessing import MinMaxScaler import numpy as np # Fit scaler on ALL training data (all features, all time steps) scaler = MinMaxScaler(feature_range=(0, 1)) scaled_training_data = scaler.fit_transform(your_raw_training_data) # Split scaled data into input (40 steps) and target (10 steps) sequences def create_sequences(data, input_steps=40, output_steps=10): X, y = [], [] for i in range(input_steps, len(data) - output_steps + 1): X.append(data[i-input_steps:i, :]) # 40 steps of 4 features y.append(data[i:i+output_steps, :]) # Next 10 steps of target data return np.array(X), np.array(y) X_train, y_train = create_sequences(scaled_training_data)
When making live predictions, use the same scaler to transform new input data, then inverse_transform the model's output to get actual price values.
2. Misaligned Target Scaling
Don't normalize your target sequences independently! Your model's learning signal will be misaligned if inputs and targets use different scaling rules. Always apply the global scaler to your target data alongside your inputs.
3. Quick LSTM Configuration Checks
If you're still facing issues after fixing normalization, double-check these:
- Ensure your input shape matches LSTM requirements:
(number_of_samples, time_steps, number_of_features)(for your data, that's(samples, 40, 4)since you have 4 features) - Add dropout layers (
Dropout(0.2)) after LSTM layers to combat overfitting—cryptocurrency data is extremely noisy! - For multi-step prediction (10 steps), consider an encoder-decoder LSTM setup if you want the model to learn temporal dependencies between the predicted steps.
If you can share specifics about the exact issue you're seeing (e.g., terrible prediction accuracy, training loss not decreasing, nonsensical output values), I can give even more targeted advice!
内容的提问来源于stack exchange,提问作者J.Tyc




