การทำให้อนุกรมเวลา Stationary

ARIMA Models ใน Python

James Fulton

Climate informatics researcher

ภาพรวม

  • การทดสอบทางสถิติสำหรับ Stationarity
  • การทำให้ชุดข้อมูลเป็น Stationary
ARIMA Models ใน Python

การทดสอบ Augmented Dickey-Fuller

  • การทดสอบ Non-stationarity จาก Trend
  • Null hypothesis คืออนุกรมเวลาไม่เป็น Stationary
ARIMA Models ใน Python

การใช้การทดสอบ adfuller

from statsmodels.tsa.stattools import adfuller

results = adfuller(df['close'])
ARIMA Models ใน Python

การแปลผลการทดสอบ

print(results)
(-1.34, 0.60, 23, 1235, {'1%': -3.435, '5%': -2.913, '10%': -2.568}, 10782.87)
  • องค์ประกอบที่ 0 คือ Test Statistic (-1.34)
    • ค่ายิ่งติดลบมาก ยิ่งมีแนวโน้มเป็น Stationary
  • องค์ประกอบที่ 1 คือ P-value: (0.60)
    • หาก P-value น้อย $\rightarrow$ ปฏิเสธ Null Hypothesis หมายถึงปฏิเสธ Non-stationary
  • องค์ประกอบที่ 4 คือ Critical Test Statistics
ARIMA Models ใน Python

การแปลผลการทดสอบ

print(results)
(-1.34, 0.60, 23, 1235, {'1%': -3.435, '5%': -2.863, '10%': -2.568}, 10782.87)
  • องค์ประกอบที่ 0 คือ Test Statistic (-1.34)
    • ค่ายิ่งติดลบมาก ยิ่งมีแนวโน้มเป็น Stationary
  • องค์ประกอบที่ 1 คือ P-value: (0.60)
    • หาก P-value น้อย $\rightarrow$ ปฏิเสธ Null Hypothesis หมายถึงปฏิเสธ Non-stationary
  • องค์ประกอบที่ 4 คือ Critical Test Statistics
1 https://www.statsmodels.org/dev/generated/statsmodels.tsa.stattools.adfuller.html
ARIMA Models ใน Python

คุณค่าของการพล็อตกราฟ

  • การพล็อตกราฟอนุกรมเวลาช่วยป้องกันข้อสรุปที่ผิดพลาด
ARIMA Models ใน Python

คุณค่าของการพล็อตกราฟ

ARIMA Models ใน Python

การทำให้อนุกรมเวลาเป็น Stationary

ARIMA Models ใน Python

การหาค่าผลต่าง

ผลต่าง: $\Delta y_t = y_t - y_{t-1}$

ARIMA Models ใน Python

การหาค่าผลต่าง

df_stationary = df.diff()
            city_population
date                       
1969-09-30              NaN
1970-03-31        -0.116156
1970-09-30         0.050850
1971-03-31        -0.153261
1971-09-30         0.108389
ARIMA Models ใน Python

การหาค่าผลต่าง

df_stationary = df.diff().dropna()
            city_population
date                       
1970-03-31        -0.116156
1970-09-30         0.050850
1971-03-31        -0.153261
1971-09-30         0.108389
1972-03-31        -0.029569
ARIMA Models ใน Python

การหาค่าผลต่าง

ARIMA Models ใน Python

Transform แบบอื่น

ตัวอย่าง Transform อื่น ๆ

  • หา Log
    • np.log(df)
  • หารากที่สอง
    • np.sqrt(df)
  • หาการเปลี่ยนแปลงเชิงสัดส่วน
    • df.shift(1)/df
ARIMA Models ใน Python

มาฝึกกันเถอะ!

ARIMA Models ใน Python

Preparing Video For Download...