Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge 1 | Non-Stationary Models
Time Series Analysis

book
Challenge 1

Uppgift

Swipe to start coding

Time for new challenges! Here is the first challenge, the idea of which is to process the pr_HH Spot Price.csv dataset to turn it from non-stationary to stationary:

  1. Read the dataset.
  2. Test for data stationarity (use adfuller) and display results.
  3. Visualize the initial values of the "Price" column.
  4. Transform data (the "Price" column of the df DataFrame) from non-stationary to stationary using the difference method (using the .diff() method with periods = 1 parameter). Drop NA values. Assign the result to the new_diff variable.
  5. Visualize the modified data (new_diff).
  6. Rerun the ADF test for updated data (new_diff).

Lösning

# Importing libraries
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.stattools import adfuller

# Reading dataset
df = pd.read_csv("https://codefinity-content-media.s3.eu-west-1.amazonaws.com/943e906e-4de6-4694-a1df-313ceed7cfe7/pr_HH+Spot+Price.csv")

# Make ADF Test
result = adfuller(df['Price'].values, autolag="AIC")
print("ADF Statistic: %f" % (result[0]))
print("p-value: %f" % (result[1]))

# Visualizing dataset
plt.plot(df["Price"])
plt.show()

# Use differencing method
new_diff = df["Price"].diff(periods=1).dropna()

# Plot stationary data
plt.plot(new_diff)
plt.show()

# Remake ADF test
new_result = adfuller(new_diff.values, autolag="AIC")
print("ADF Statistic: %f" % (new_result[0]))
print("p-value: %f" % (new_result[1]))

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 5. Kapitel 3
# Importing libraries
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.stattools import adfuller

# Reading dataset
df = pd.___("https://codefinity-content-media.s3.eu-west-1.amazonaws.com/943e906e-4de6-4694-a1df-313ceed7cfe7/pr_HH+Spot+Price.csv")

# Make ADF Test
result = ___(df["___"].values, autolag="AIC")
print("ADF Statistic: %f" % (result[0]))
print("p-value: %f" % (result[1]))

# Visualizing dataset
plt.___(___)
plt.___()

# Use differencing method
new_diff = df["___"].___(periods=___).___()

# Plot stationary data
plt.plot(___)
plt.show()

# Remake ADF test
new_result = adfuller(___.values, autolag="AIC")
print("ADF Statistic: %f" % (new_result[0]))
print("p-value: %f" % (new_result[1]))

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

some-alt