Finestre mobili e lag
Smussamento e feature lag.
Finestre mobili e lag è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Smoothing Out the Bumps
Raw time series can be jumpy. A rolling window averages nearby points so the underlying signal becomes easy to see. 🌊
What a Window Really Is
A window is a fixed number of recent points. It slides forward one step at a time, recomputing a summary at each position.
The Rolling Mean
The most common move is a rolling mean: average the last few values to smooth the line. pandas makes it a one-liner.
sales.rolling(window=7).mean()Window Size Is a Trade-Off
A larger window smooths more but reacts slowly; a smaller one stays responsive but noisy. You tune it to the question.
The First Values Are NaN
A window of 7 needs 7 points before it can compute. So the first rows come back as NaN until enough history exists.
Beyond the Mean
Rolling works with more than averages. A rolling std reveals how volatility changes over time, which trends alone hide.
sales.rolling(window=30).std()Meet the Lag
A lag is simply the value from an earlier time step. Yesterday's sales as a column is a lag-1 feature.
Shift Creates Lags
pandas builds lags with shift. Calling shift(1) pushes every value down one row so each row sees its past.
df['lag_1'] = sales.shift(1)Why Lags Power Forecasts
Most series depend on their own recent past. Feeding a model good lag features lets it learn that yesterday predicts today.
Differencing Is a Lag Too
Subtracting the previous value, value minus its lag, gives the change between steps. It is the seed of differencing.
df['change'] = sales - sales.shift(1)Combine Rolling and Lags
Strong feature sets often mix both: a few lags plus a rolling mean. Together they capture recent level and direction.
Quick Check
Which pandas method shifts values to their previous time step to build a lag feature?
Recap: Past as Features
You used rolling windows to smooth and lags via shift to bring the past forward, the two staples of time series features.
Domande Frequenti
La lezione «Finestre mobili e lag» è gratuita?
Sì — il testo completo di «Finestre mobili e lag» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.
Cosa imparerò in «Finestre mobili e lag»?
Smussamento e feature lag. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Data Science Academy?
Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Finestre mobili e lag»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Data Science Academy?
Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Trend, stagionalità e rumore
- Finestre mobili e lag
- Stazionarietà e differenziazione
- Una prima previsione di riferimento