File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import numpy as np
import pandas as pd
from statsmodels.tsa.statespace.sarimax import SARIMAX
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
import plotly.graph_objects as go
from scipy import signal
from datetime import datetime
import plotly.express as px
from tools.algo.humidity import absolute_humidity
if __name__ == "__main__":
df = pd.read_csv("/home/juni/PycharmProjects/failure_analysis/data/weather/202007010000_202308310000_f.csv")
ah = absolute_humidity(df["상대습도"], df["기온"])
df['관측시각'] = df['관측시각'].apply(lambda x: datetime.strptime(f"{x}", '%Y%m%d%H%M'))
df["절대습도"] = ah
# fig = go.Figure()
#
# fig.add_trace(
# go.Scatter(x=df["관측시각"], y=df["절대습도"])
# )
# fig.add_trace(
# go.Scatter(x=df["관측시각"], y=signal.savgol_filter(
# df["절대습도"],72,3)
# ))
# fig.show()
# log_df = np.log(df["절대습도"])
diff_1 = (df["절대습도"].diff(periods=1).iloc[1:])
diff_2 = diff_1.diff(periods=1).iloc[1:]
# plot_acf(diff_2)
# plot_pacf(diff_2)
plt.show()
model = SARIMAX(df["절대습도"], order=(1,0,2), seasonal_order=(0,1,2,24))
model_fit = model.fit()
# ARIMA_model = pm.auto_arima(df['절대습도'],
# start_p=1,
# start_q=1,
# test='adf', # use adftest to find optimal 'd'
# max_p=3, max_q=3, # maximum p and q
# m=24, # frequency of series (if m==1, seasonal is set to FALSE automatically)
# d=None, # let model determine 'd'
# D=2, #order of the seasonal differencing
# seasonal=True, # No Seasonality for standard ARIMA
# trace=False, # logs
# error_action='warn', # shows errors ('ignore' silences these)
# suppress_warnings=False,
# stepwise=True)
print(model_fit.summary())
df['forecast'] = model_fit.predict(start=-100, end=-1, dynamic=True)
# df[['절대습도', 'forecast']].plot(figsize=(12, 8))
fig = px.line(df[['절대습도', 'forecast']])
fig.show()