コード例 #1
0
def pftsExploreOrderAndPartitions(data, save=False, file=None):
    fig, axes = plt.subplots(nrows=4, ncols=1, figsize=[6, 8])
    data_fs1 = Grid.GridPartitioner(data=data, npart=10).sets
    mi = []
    ma = []

    axes[0].set_title('Point Forecasts by Order')
    axes[2].set_title('Interval Forecasts by Order')

    for order in np.arange(1, 6):
        fts = pwfts.ProbabilisticWeightedFTS("")
        fts.shortname = "n = " + str(order)
        fts.train(data, sets=data_fs1.sets, order=order)
        point_forecasts = fts.forecast(data)
        interval_forecasts = fts.forecast_interval(data)
        lower = [kk[0] for kk in interval_forecasts]
        upper = [kk[1] for kk in interval_forecasts]
        mi.append(min(lower) * 0.95)
        ma.append(max(upper) * 1.05)
        for k in np.arange(0, order):
            point_forecasts.insert(0, None)
            lower.insert(0, None)
            upper.insert(0, None)
        axes[0].plot(point_forecasts, label=fts.shortname)
        axes[2].plot(lower, label=fts.shortname)
        axes[2].plot(upper)

    axes[1].set_title('Point Forecasts by Number of Partitions')
    axes[3].set_title('Interval Forecasts by Number of Partitions')

    for partitions in np.arange(5, 11):
        data_fs = Grid.GridPartitioner(data=data, npart=partitions).sets
        fts = pwfts.ProbabilisticWeightedFTS("")
        fts.shortname = "q = " + str(partitions)
        fts.train(data, sets=data_fs.sets, order=1)
        point_forecasts = fts.forecast(data)
        interval_forecasts = fts.forecast_interval(data)
        lower = [kk[0] for kk in interval_forecasts]
        upper = [kk[1] for kk in interval_forecasts]
        mi.append(min(lower) * 0.95)
        ma.append(max(upper) * 1.05)
        point_forecasts.insert(0, None)
        lower.insert(0, None)
        upper.insert(0, None)
        axes[1].plot(point_forecasts, label=fts.shortname)
        axes[3].plot(lower, label=fts.shortname)
        axes[3].plot(upper)

    for ax in axes:
        ax.set_ylabel('F(T)')
        ax.set_xlabel('T')
        ax.plot(data, label="Original", color="black", linewidth=1.5)
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles, labels, loc=2, bbox_to_anchor=(1, 1))
        ax.set_ylim([min(mi), max(ma)])
        ax.set_xlim([0, len(data)])

    plt.tight_layout()

    cUtil.show_and_save_image(fig, file, save)
コード例 #2
0
ファイル: general.py プロジェクト: felipenv/pyFTS
#df = pd.read_csv('https://query.data.world/s/z2xo3t32pkl4mdzp63x6lyne53obmi')
#dados = df.iloc[2710:2960 , 0:1].values # somente a 1 coluna sera usada
#dados = df['temperature'].values
#dados = dados.flatten().tolist()

dados = Enrollments.get_data()

l = len(dados)

#dados_treino = dados[:int(l*.7)]
#dados_teste = dados[int(l*.7):]

particionador = Grid.GridPartitioner(data = dados, npart = 10, func = Membership.trimf)

modelo = pwfts.ProbabilisticWeightedFTS(partitioner = particionador, order = 1, standard_horizon=3)
#modelo = hofts.WeightedHighOrderFTS(partitioner = particionador, order = 1, standard_horizon=2)
#modelo = chen.ConventionalFTS(partitioner = particionador, standard_horizon=3)

modelo.fit(dados)

print(modelo)

# Todo o procedimento de inferência é feito pelo método predict
predicoes = modelo.predict(dados)

print(predicoes)


'''
from pyFTS.data import TAIEX, NASDAQ, SP500
コード例 #3
0
ttr = list(range(len(dados_treino)))

ordem = 1  # ordem do modelo, indica quantos ultimos valores serao usados

dados_teste = dados[qtde_dt_tr - ordem:250]
tts = list(
    range(
        len(dados_treino) - ordem,
        len(dados_treino) + len(dados_teste) - ordem))

particionador = Grid.GridPartitioner(data=dados_treino,
                                     npart=30,
                                     func=Membership.trimf)

modelo = pwfts.ProbabilisticWeightedFTS(partitioner=particionador, order=ordem)

modelo.fit(dados_treino)

print(modelo)

# Todo o procedimento de inferência é feito pelo método predict
predicoes = modelo.predict(dados_teste[38:40])

print(predicoes)
'''
from pyFTS.data import TAIEX, NASDAQ, SP500
from pyFTS.common import Util

train = TAIEX.get_data()[1000:1800]
test = TAIEX.get_data()[1800:2000]
コード例 #4
0
model.fit(y)
forecasts = model.predict(y)
plt_fc = np.insert(forecasts, 0, y[0])
ax.plot(plt_fc, label="HOFTS")
rmse, mape, u = Measures.get_point_statistics(y, model)
rows.append(["HOFTS", rmse, mape, u])

model = hofts.WeightedHighOrderFTS(order=2, partitioner=part)
model.fit(y)
forecasts = model.predict(y)
plt_fc = np.insert(forecasts, 0, y[0])
ax.plot(plt_fc, label="WHOFTS")
rmse, mape, u = Measures.get_point_statistics(y, model)
rows.append(["WHOFTS", rmse, mape, u])

model = pwfts.ProbabilisticWeightedFTS(order=2, partitioner=part)
model.fit(y)
forecasts = model.predict(y)
plt_fc = np.insert(forecasts, 0, y[0])
ax.plot(plt_fc, label="PWFTS")
rmse, mape, u = Measures.get_point_statistics(y, model)
rows.append(["PWFTS", rmse, mape, u])

handles, labels = ax.get_legend_handles_labels()
lgd = ax.legend(handles, labels, loc=2, bbox_to_anchor=(1, 1))

df = pd.DataFrame(rows, columns=['Algorithms','RMSE','MAPE','U'])
print(df)


コード例 #5
0
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

from pyFTS.common import Util
from pyFTS.benchmarks import benchmarks as bchmk, Measures
from pyFTS.models import pwfts, hofts, ifts
from pyFTS.models.multivariate import granular, grid
from pyFTS.partitioners import Grid, Util as pUtil

from pyFTS.models.multivariate import common, variable, mvfts, wmvfts
from pyFTS.models.seasonal import partitioner as seasonal
from pyFTS.models.seasonal.common import DateTime
from pyFTS.common import Membership

from pyFTS.data import SONDA

data = [
    k for k in SONDA.get_data('ws_10m')
    if k > 0.1 and k != np.nan and k is not None
]
data = [np.nanmean(data[k:k + 60]) for k in np.arange(0, len(data), 60)]

train = data[:9000]
test = data[9000:10000]

fs = Grid.GridPartitioner(data=train, npart=95)

model = pwfts.ProbabilisticWeightedFTS(partitioner=fs, order=3)

model.fit(train)

model.predict(test)
コード例 #6
0
ファイル: pwfts.py プロジェクト: yashhguptaa1/pyFTS
train = taiex[:3000]
test = taiex[3000:3200]

from pyFTS.common import Transformations
tdiff = Transformations.Differential(1)

from pyFTS.benchmarks import benchmarks as bchmk, Measures
from pyFTS.models import pwfts, hofts, ifts
from pyFTS.partitioners import Grid, Util as pUtil

fs = Grid.GridPartitioner(data=train, npart=30)  #, transformation=tdiff)

model1 = hofts.HighOrderFTS(partitioner=fs, lags=[1, 2])  #lags=[0,1])
model1.shortname = "1"
model2 = pwfts.ProbabilisticWeightedFTS(partitioner=fs, lags=[1, 2])
#model2.append_transformation(tdiff)
model2.shortname = "2"
#model = pwfts.ProbabilisticWeightedFTS(partitioner=fs, order=2)# lags=[1,2])

model1.fit(train)
model2.fit(train)

#print(model1)

#print(model2)

for model in [model1, model2]:
    #forecasts = model.predict(test)
    print(model.shortname)
    print(Measures.get_point_statistics(test, model))