Bugfixes and improvements on benchmarking methods
This commit is contained in:
parent
99c36fc5e9
commit
5f667c8680
@ -97,7 +97,7 @@ class QuantileRegression(fts.FTS):
|
|||||||
|
|
||||||
def forecast_ahead_interval(self, ndata, steps, **kwargs):
|
def forecast_ahead_interval(self, ndata, steps, **kwargs):
|
||||||
|
|
||||||
smoothing = kwargs.get("smoothing", 0.1)
|
smoothing = kwargs.get("smoothing", 0.01)
|
||||||
|
|
||||||
l = len(ndata)
|
l = len(ndata)
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class QuantileRegression(fts.FTS):
|
|||||||
|
|
||||||
tmpk = k-self.order
|
tmpk = k-self.order
|
||||||
|
|
||||||
ret.append([intl[0]*(1 + (tmpk*smoothing)), intl[1]*(1 + (tmpk*smoothing))])
|
ret.append([intl[0]*(1 - (tmpk*smoothing)), intl[1]*(1 + (tmpk*smoothing))])
|
||||||
|
|
||||||
return ret[-steps:]
|
return ret[-steps:]
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ class QuantileRegression(fts.FTS):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def forecast_ahead_distribution(self, ndata, steps, **kwargs):
|
def forecast_ahead_distribution(self, ndata, steps, **kwargs):
|
||||||
smoothing = kwargs.get("smoothing", 0.1)
|
smoothing = kwargs.get("smoothing", 0.01)
|
||||||
|
|
||||||
l = len(ndata)
|
l = len(ndata)
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ class QuantileRegression(fts.FTS):
|
|||||||
for qt in self.dist_qt:
|
for qt in self.dist_qt:
|
||||||
intl1 = self.point_to_interval(nmeans[k - self.order: k], qt[0], qt[1])
|
intl1 = self.point_to_interval(nmeans[k - self.order: k], qt[0], qt[1])
|
||||||
tmpk = k - self.order
|
tmpk = k - self.order
|
||||||
intl2 = [intl1[0] * (1 + (tmpk * smoothing)), intl1[1] * (1 + (tmpk * smoothing))]
|
intl2 = [intl1[0] * (1 - (tmpk * smoothing)), intl1[1] * (1 + (tmpk * smoothing))]
|
||||||
intervals.append(intl2)
|
intervals.append(intl2)
|
||||||
dist.append_interval(intervals)
|
dist.append_interval(intervals)
|
||||||
|
|
||||||
|
@ -177,8 +177,6 @@ def plot_distribution2(probabilitydist, data, **kwargs):
|
|||||||
import matplotlib.colorbar as cbar
|
import matplotlib.colorbar as cbar
|
||||||
import matplotlib.cm as cm
|
import matplotlib.cm as cm
|
||||||
|
|
||||||
order = kwargs.get('order', 1)
|
|
||||||
|
|
||||||
ax = kwargs.get('ax',None)
|
ax = kwargs.get('ax',None)
|
||||||
if ax is None:
|
if ax is None:
|
||||||
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[15, 5])
|
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[15, 5])
|
||||||
@ -188,7 +186,7 @@ def plot_distribution2(probabilitydist, data, **kwargs):
|
|||||||
cmap = kwargs.get('cmap','Blues')
|
cmap = kwargs.get('cmap','Blues')
|
||||||
cmap = plt.get_cmap(cmap)
|
cmap = plt.get_cmap(cmap)
|
||||||
|
|
||||||
start_at = kwargs.get('start_at',0) + order - 1
|
start_at = kwargs.get('start_at',0)
|
||||||
|
|
||||||
x = [k + start_at for k in range(l + 1)]
|
x = [k + start_at for k in range(l + 1)]
|
||||||
|
|
||||||
@ -275,7 +273,7 @@ def plot_interval2(intervals, data, **kwargs):
|
|||||||
if ax is None:
|
if ax is None:
|
||||||
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[15, 5])
|
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[15, 5])
|
||||||
|
|
||||||
for k in np.arange(0, start_at-1):
|
for k in np.arange(0, start_at):
|
||||||
intervals.insert(0, [None,None])
|
intervals.insert(0, [None,None])
|
||||||
|
|
||||||
intervals.insert(start_at, [data[start_at], data[start_at]])
|
intervals.insert(start_at, [data[start_at], data[start_at]])
|
||||||
|
@ -303,6 +303,7 @@ class SimpleEnsembleFTS(EnsembleFTS):
|
|||||||
"""Possible variations of number of partitions on internal models"""
|
"""Possible variations of number of partitions on internal models"""
|
||||||
self.orders = kwargs.get('orders', [1,2,3])
|
self.orders = kwargs.get('orders', [1,2,3])
|
||||||
"""Possible variations of order on internal models"""
|
"""Possible variations of order on internal models"""
|
||||||
|
self.uod_clip = False
|
||||||
|
|
||||||
def train(self, data, **kwargs):
|
def train(self, data, **kwargs):
|
||||||
for k in self.partitions:
|
for k in self.partitions:
|
||||||
|
@ -12,6 +12,7 @@ from pyFTS.common import Util as cUtil, FuzzySet
|
|||||||
from pyFTS.partitioners import Grid, Entropy, Util as pUtil, Simple
|
from pyFTS.partitioners import Grid, Entropy, Util as pUtil, Simple
|
||||||
from pyFTS.benchmarks import benchmarks as bchmk, Measures
|
from pyFTS.benchmarks import benchmarks as bchmk, Measures
|
||||||
from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts, tsaur, song, sadaei
|
from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts, tsaur, song, sadaei
|
||||||
|
from pyFTS.models.ensemble import ensemble
|
||||||
from pyFTS.common import Transformations, Membership
|
from pyFTS.common import Transformations, Membership
|
||||||
from pyFTS.benchmarks import arima, quantreg, BSTS
|
from pyFTS.benchmarks import arima, quantreg, BSTS
|
||||||
from pyFTS.fcm import fts, common, GA
|
from pyFTS.fcm import fts, common, GA
|
||||||
@ -20,17 +21,19 @@ from pyFTS.data import Enrollments, TAIEX
|
|||||||
|
|
||||||
data = TAIEX.get_data()
|
data = TAIEX.get_data()
|
||||||
|
|
||||||
train = data[:500]
|
train = data[:800]
|
||||||
test = data[500:1000]
|
test = data[800:1000]
|
||||||
|
|
||||||
model = quantreg.QuantileRegression(order=1, dist=True)
|
model = ensemble.SimpleEnsembleFTS(fts_method=hofts.HighOrderFTS)
|
||||||
|
#model = quantreg.QuantileRegression(order=2, dist=True)
|
||||||
|
#model = arima.ARIMA(order = (2,0,0))
|
||||||
model.fit(train)
|
model.fit(train)
|
||||||
|
|
||||||
horizon=5
|
horizon=5
|
||||||
|
|
||||||
#points = model.predict(test[:10], type='point', steps_ahead=horizon)
|
#points = model.predict(test[:10], type='point', steps_ahead=horizon)
|
||||||
|
|
||||||
intervals = model.predict(test[:10], type='interval', alpha=.05, smoothing=0.01, steps_ahead=horizon)
|
intervals = model.predict(test[:10], type='interval', alpha=.05, steps_ahead=horizon)
|
||||||
print(test[:10])
|
print(test[:10])
|
||||||
print(intervals)
|
print(intervals)
|
||||||
distributions = model.predict(test[:10], type='distribution', steps_ahead=horizon, num_bins=100)
|
distributions = model.predict(test[:10], type='distribution', steps_ahead=horizon, num_bins=100)
|
||||||
@ -39,8 +42,10 @@ distributions = model.predict(test[:10], type='distribution', steps_ahead=horizo
|
|||||||
fig, ax = plt.subplots(nrows=1, ncols=1,figsize=[15,5])
|
fig, ax = plt.subplots(nrows=1, ncols=1,figsize=[15,5])
|
||||||
|
|
||||||
ax.plot(test[:10], label='Original',color='black')
|
ax.plot(test[:10], label='Original',color='black')
|
||||||
cUtil.plot_interval2(intervals, test[:10], start_at=3, ax=ax)
|
cUtil.plot_interval2(intervals, test[:10], start_at=model.order, ax=ax)
|
||||||
cUtil.plot_distribution2(distributions, test[:10], start_at=2, ax=ax, cmap="Blues")
|
cUtil.plot_distribution2(distributions, test[:10], start_at=model.order, ax=ax, cmap="Blues")
|
||||||
|
|
||||||
|
print("")
|
||||||
|
|
||||||
'''
|
'''
|
||||||
model = fts.FCM_FTS(partitioner=fs, order=1)
|
model = fts.FCM_FTS(partitioner=fs, order=1)
|
||||||
|
Loading…
Reference in New Issue
Block a user