TensorFlow RNN历史预测图与训练集差异及历史曲线变化原因咨询
Hey there! Let's break down why you're seeing those discrepancies in the historical curves and how the past_history parameter affects them—this is a common gotcha when working with time series tutorials, so you're not alone here.
1. Historical curves are likely normalized/standardized (not raw sample data)
TensorFlow's official time series tutorial almost certainly applies data normalization before training (neural networks perform far better with scaled input values). The "historical curves" you see in the tutorial's plots are this scaled version of the data, while your raw sample observations are in their original range. That's the primary reason they look different at first glance.
Double-check your preprocessing code: if you're using tf.keras.layers.Normalization, or manually scaling data with mean/std values, the visualized history will reflect these transformed values—not the raw numbers you might be comparing against.
2. past_history directly defines the scope of the historical window
The past_history parameter sets how many time steps the model uses as input to generate predictions. When you adjust this value (you’re using 4000 vs. the tutorial’s 720), the visualization will only show that specific window of historical data for each prediction sample—not the entire dataset’s full history.
For example:
- With
past_history=720, each plot displays the 720 most recent time steps before the prediction point. - With
past_history=4000, each plot shows the 4000 most recent steps instead.
This is exactly why historical curves change across different plots or when you tweak past_history—each plot focuses on a unique sliding window of your data.
3. Sliding window logic and data splits add variation
Your step_size=1 (vs. the tutorial’s 30) means your data generator creates sliding windows that move 1 step at a time, whereas the tutorial uses larger 30-step jumps. This leads to far more overlapping windows, and when visualizing random samples from the dataset, each plot will pick a distinct window (hence different historical curves).
Additionally, your 80/20 train/validation split means visualizations might pull samples from either segment of your dataset—another source of variation in the displayed history.
Quick checks to confirm this
- Print a handful of raw data points and compare them to the values in your visualized history. If they’re scaled (e.g., between 0 and 1, or centered around 0), normalization is the cause.
- Modify your visualization code to plot raw historical data and scaled data side by side—this will make the difference immediately clear.
- Test with
past_history=720(matching the tutorial) and see if the historical curve length aligns with what’s shown in the tutorial’s plots.
If you share snippets of your preprocessing and visualization code, we can dig even deeper into the exact mismatch!
内容的提问来源于stack exchange,提问作者notacorn




