| Hosted by CoCalc | Download

PyFlux on SMC

Say hello to PyFlux on SageMathCloud!

import pyflux as pf pf.__version__
Error in lines 1-1 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/pyflux/__init__.py", line 17, in <module> from .other import * ImportError: No module named other
import numpy as np import pandas as pd import pyflux as pf from datetime import datetime import matplotlib.pyplot as plt data = pd.read_csv('https://vincentarelbundock.github.io/Rdatasets/csv/datasets/sunspot.year.csv') data.index = data['time'].values _=plt.figure(figsize=(15,5)) _=plt.plot(data.index,data['sunspot.year']) _=plt.ylabel('Sunspots') _=plt.title('Yearly Sunspot Data') plt.show()
Error in lines 3-3 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/pyflux/__init__.py", line 3, in <module> from . import __check_build ImportError: cannot import name __check_build
model = pf.ARIMA(data=data, ar=4, ma=4, target='sunspot.year', family=pf.Normal())
Error in lines 1-1 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'pf' is not defined
x = model.fit("MLE") x.summary()
Normal ARIMA(4,0,4) ======================================================= ================================================== Dependent Variable: sunspot.year Method: MLE Start Date: 1704 Log Likelihood: -1191.3335 End Date: 1988 AIC: 2402.6669 Number of observations: 285 BIC: 2439.1918 ========================================================================================================== Latent Variable Estimate Std Error z P>|z| 95% C.I. ======================================== ========== ========== ======== ======== ========================= Constant 10.9013 2.5712 4.2397 0.0 (5.8617 | 15.9409) AR(1) 1.5132 0.0415 36.4212 0.0 (1.4318 | 1.5947) AR(2) -0.3377 0.2406 -1.4036 0.1604 (-0.8093 | 0.1339) AR(3) -0.8512 0.2357 -3.6111 0.0003 (-1.3133 | -0.3892) AR(4) 0.452 0.0629 7.186 0.0 (0.3287 | 0.5753) MA(1) -0.3643 0.0385 -9.4559 0.0 (-0.4399 | -0.2888) MA(2) -0.4585 0.1362 -3.3669 0.0008 (-0.7254 | -0.1916) MA(3) 0.2186 0.1121 1.9495 0.0512 (-0.0012 | 0.4383) MA(4) 0.2996 0.0813 3.6831 0.0002 (0.1401 | 0.459) Normal Scale 15.8542 ==========================================================================================================

Latent variables ...

model.plot_z(figsize=(15,5))

In-sample fit

model.plot_fit(figsize=(15,10))

Prediction

model.plot_predict(h=20,past_values=20,figsize=(15,5))