コード例 #1
0
def test_predict_is_length():
    """
	Tests that the prediction IS dataframe length is equal to the number of steps h
	"""
    model = pf.DAR(data=data, ar=2)
    x = model.fit()
    assert (model.predict_is(h=5).shape[0] == 5)
コード例 #2
0
def test_predict_nans():
    """
	Tests that the predictions are not nans
	"""
    model = pf.DAR(data=data, ar=2)
    x = model.fit()
    x.summary()
    assert (len(
        model.predict(h=5).values[np.isnan(model.predict(h=5).values)]) == 0)
コード例 #3
0
def test_pml():
    """
	Tests a PML model estimated with Laplace approximation and that the length of the 
	latent variable list is correct, and that the estimated latent variables are not nan
	"""
    model = pf.DAR(data=data, ar=1)
    x = model.fit('PML')
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
コード例 #4
0
def test_mh():
    """
	Tests an DAR model estimated with Metropolis-Hastings and that the length of the 
	latent variable list is correct, and that the estimated latent variables are not nan
	"""
    model = pf.DAR(data=data, ar=1)
    x = model.fit('M-H', nsims=300)
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
コード例 #5
0
def test_bbvi():
    """
	Tests an DAR model estimated with BBVI and that the length of the latent variable
	list is correct, and that the estimated latent variables are not nan
	"""
    model = pf.DAR(data=data, ar=1)
    x = model.fit('BBVI', iterations=100)
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
コード例 #6
0
def test_couple_terms_integ():
    """
	Tests an DAR model with 1 AR, integrated once, and that
	the latent variable list length is correct, and that the estimated
	latent variables are not nan
	"""
    model = pf.DAR(data=data, ar=1, integ=1)
    x = model.fit()
    assert (len(model.latent_variables.z_list) == 3)
    lvs = np.array([i.value for i in model.latent_variables.z_list])
    assert (len(lvs[np.isnan(lvs)]) == 0)
コード例 #7
0
ファイル: sohu.py プロジェクト: jsyqrt/nicky
    def get_data_forecasting(data, target='close', method='ARIMA', forward_step=10, fit_method='MLE', **kw):
        #method: {'ARIMA', 'DAR', 'CNN', 'WaveNet'}
        if method == 'ARIMA':

            model = pf.ARIMA(data=data, target=target, **kw)
            fit_info = model.fit(fit_method)
            predict = model.predict(forward_step)
            return [predict, fit_info]
        elif method == 'DAR':
            model = pf.DAR(data=data, target=target, **kw)
            fit_info = model.fit(fit_method)
            predict = model.predict(forward_step)
            return [predict, fit_info]
        else:
            pass
コード例 #8
0
ファイル: DAR.py プロジェクト: JonasBGerth/informatiCup2018
from samples import main
import pyflux as pf

fuelPrice = main.fuelPrice['2016-12']
H = 50

model = pf.DAR(data=fuelPrice, ar=2, integ=0, target=None)
x = model.fit("MLE")
x.summary()

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

model.plot_predict_is(h=H, figsize=(15, 5))
model.plot_predict(h=H, figsize=(15, 5))
コード例 #9
0
import matplotlib.pyplot as plt
import pyflux as pf

filename = "Arun_Valley_export.csv"  #Name of file holding CSV data of stock values and Date

data = pd.read_csv(filename)
data['Date'] = pd.to_datetime(data['Date'])

#Converting Data in mmddyyyy into date_delta integer
data['date_delta'] = (data['Date'] - data['Date'].min()) / np.timedelta64(
    1, 'D')

#Delcaring index of the data
data.index = data['date_delta']

#Formatting the graph and labeling the axis
plt.figure(figsize=(15, 5))
plt.plot(data.index, data['LTP'])
plt.ylabel('Arun Valley Stock Values')
plt.ylabel('Date')
plt.title("Arun Valley Stock prediction using DAR model")
plt.show()

#Using DAR model to forecast the time series
model = pf.DAR(data=data, ar=4, integ=0, target='LTP')
x = model.fit("MLE")
x.summary(transformed=False)
model.plot_fit(figsize=(15, 10))

#Predicting 50 uture values using 100 past values
model.plot_predict(h=50, past_values=100, figsize=(15, 5))