Exemple #1
0
def hofts_forecast(train_df, test_df, params):
    _partitioner = params['partitioner']
    _npartitions = params['npartitions']
    _order = params['order']
    _input = params['input']
    _step = params.get('step', 1)

    fuzzy_sets = _partitioner(data=train_df[_input].values, npart=_npartitions)
    model = hofts.HighOrderFTS(order=_order)

    model.fit(train_df[_input].values, order=_order, partitioner=fuzzy_sets)
    forecast = model.predict(test_df[_input].values, steps_ahead=_step)

    return forecast
Exemple #2
0
y = [np.sin(k) for k in x]

from pyFTS.models import hofts
from pyFTS.partitioners import Grid, FCM, CMeans, Entropy
from pyFTS.benchmarks import Measures

metodos = [FCM.FCMPartitioner]

k = 35

rows = []

for contador, metodo in enumerate(metodos):
    print(metodo)
    part = metodo(data=y, npart=k)
    model = hofts.HighOrderFTS(order=2, partitioner=part)
    model.fit(y)
    forecasts = model.predict(y)
    for o in range(model.order):
        forecasts.insert(0, None)
'''
model = fts.FCM_FTS(partitioner=fs, order=1)

model.fcm.weights = np.array([
    [1, 1, 0, -1, -1],
    [1, 1, 1, 0, -1],
    [0, 1, 1, 1, 0],
    [-1, 0, 1, 1, 1],
    [-1, -1, 0, 1, 1]
])
Exemple #3
0
taiex = TAIEX.get_data()

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)
Exemple #4
0
from pyFTS.partitioners import Grid, Util as pUtil

partitioner = Grid.GridPartitioner(data=dataset[:2000],
                                   npart=20)  #, transformation=tdiff)

from pyFTS.common import Util as cUtil
from pyFTS.benchmarks import benchmarks as bchmk, Util as bUtil, Measures, knn, quantreg, arima, naive

from pyFTS.models import pwfts, song, chen, ifts, hofts
from pyFTS.models.ensemble import ensemble

print(partitioner)

#model = chen.ConventionalFTS(partitioner=partitioner)
model = hofts.HighOrderFTS(partitioner=partitioner, order=2)
#model.append_transformation(tdiff)
model.fit(dataset[:2000])

print(model)

print(model.predict([3500, 7000], steps_ahead=5))

#cUtil.plot_rules(model, size=[20,20], rules_by_axis=5, columns=1)

#

print("fim")
'''
model = knn.KNearestNeighbors(order=3)
#model = ensemble.AllMethodEnsembleFTS("", partitioner=partitioner)
Exemple #5
0
test = stock[init_os:end_os]

close = variable.Variable("close",
                          data_label='Adj Close',
                          partitioner=Grid.GridPartitioner,
                          npart=20,
                          data=train)
polarity = variable.Variable("polarity",
                             data_label='sentiment_bert',
                             partitioner=Grid.GridPartitioner,
                             npart=50,
                             data=train)

from pyFTS.models import hofts
#mpolarity = mvfts.MVFTS(explanatory_variables=[close, polarity], target_variable=polarity)
mpolarity = hofts.HighOrderFTS(partitioner=polarity.partitioner)
mpolarity.fit(train['sentiment_bert'].values)

mclose = mvfts.MVFTS(explanatory_variables=[close, polarity],
                     target_variable=close)
mclose.fit(train)

forecasts = mclose.predict(train[-1:],
                           steps_ahead=2,
                           generators={'sentiment_bert': mpolarity})
'''
df = Malaysia.get_dataframe()
df['time'] = pd.to_datetime(df["time"], format='%m/%d/%y %I:%M %p')

train_mv = df.iloc[:1800]
test_mv = df.iloc[1800:2000]