<jupyter_start><jupyter_text>1.1. Преобразование Бокса-Кокса<jupyter_code>from scipy.stats import boxcox
boxcox_data, boxcox_lambda = boxcox(prod['prod_index'].values)
plt.plot(boxcox_data)
plt.plot(prod['prod_index'].values)<jupyter_output><empty_output><jupyter_text>1.2. Дифференцирование<jupyter_code>transformationDF = pd.DataFrame(prod['prod_index'].values, columns = ['initial'])
transformationDF['boxcox'] = boxcox_data
transformationDF['seasonal_diff'] = transformationDF['boxcox'].diff(12)
transformationDF['seasonal_diff'].plot()
transformationDF['lag1_diff'] = transformationDF['seasonal_diff'].diff(1)
transformationDF['lag1_diff'].plot()
from statsmodels.tsa.stattools import adfuller
print("<NAME>: p=%f" % adfuller(transformationDF['lag1_diff'].dropna())[1])<jupyter_output><NAME>: p=0.004653<jupyter_text>p-value меньше 0.05, то есть ряд, скорее всего, можно считать стационарным  Аппроксимация тренда + наивная сезонная модель<jupyter_code>y0 = transformationDF['lag1_diff'][0]
yt = transformationDF['lag1_diff'][-1]
coeff = (yt - y0) / (transformationDF.dropna().shape[0] - 1)<jupyter_output><empty_output><jupyter_text>Приведём ряд к исходному<jupyter_code>transformationDF.head(20)
transformationDF['unlag1_diff'] = transformationDF['lag1_diff'] + transformationDF['seasonal_diff'].shift()
transformationDF.iloc[13]['seasonal_diff'] == transformationDF.iloc[13]['unlag1_diff']
transformationDF['unseasonal_diff'] = transformationDF['unlag1_diff'] + transformationDF['boxcox'].shift(12)
transformationDF.iloc[13]['boxcox'] == transformationDF.iloc[13]['unseasonal_diff']
from scipy.special import inv_boxcox
transformationDF['unboxcox'] = inv_boxcox(transformationDF['unseasonal_diff'].values, boxcox_lambda)
transformationDF.iloc[13]
plt.plot(transformationDF['initial'])
plt.plot(transformationDF['unboxcox'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14991939817302524, 'fraction_numerical': 0.02525523911875336, 'mean_word_length': 12.39568345323741, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '423231', 'license': 'MIT', 'n_tokens_mistral': 704, 'n_tokens_neox': 688, 'n_words': 77, 'path': 'Forecasting-Methods/3.1 Autoregressive models/3.1 Autoregressive models HW.ipynb', 'repo_name': 'cmlimm/uni-projects', 'size': '1891'}