def run_interval(mfts, partitioner, train_data, test_data, window_key=None, **kwargs): """ Run the interval forecasting benchmarks :param mfts: FTS model :param partitioner: Universe of Discourse partitioner :param train_data: data used to train the model :param test_data: ata used to test the model :param window_key: id of the sliding window :param transformation: data transformation :param indexer: seasonal indexer :return: a dictionary with the benchmark results """ import time from pyFTS.models import hofts,ifts,pwfts from pyFTS.partitioners import Grid, Entropy, FCM from pyFTS.benchmarks import Measures, arima, quantreg tmp = [hofts.HighOrderFTS, ifts.IntervalFTS, pwfts.ProbabilisticWeightedFTS] tmp2 = [Grid.GridPartitioner, Entropy.EntropyPartitioner, FCM.FCMPartitioner] tmp4 = [arima.ARIMA, quantreg.QuantileRegression] tmp3 = [Measures.get_interval_statistics] steps_ahead = kwargs.get('steps_ahead', 1) method = kwargs.get('method', None) if mfts.benchmark_only: _key = mfts.shortname + str(mfts.order if mfts.order is not None else "") + str(mfts.alpha) else: pttr = str(partitioner.__module__).split('.')[-1] _key = mfts.shortname + " n = " + str(mfts.order) + " " + pttr + " q = " + str(partitioner.partitions) mfts.partitioner = partitioner mfts.append_transformation(partitioner.transformation) _key += str(steps_ahead) _key += str(method) if method is not None else "" _start = time.time() mfts.fit(train_data, **kwargs) _end = time.time() times = _end - _start _start = time.time() #_sharp, _res, _cov, _q05, _q25, _q75, _q95, _w05, _w25 metrics = Measures.get_interval_statistics(test_data, mfts, **kwargs) _end = time.time() times += _end - _start ret = {'key': _key, 'obj': mfts, 'sharpness': metrics[0], 'resolution': metrics[1], 'coverage': metrics[2], 'time': times,'Q05': metrics[3], 'Q25': metrics[4], 'Q75': metrics[5], 'Q95': metrics[6], 'winkler05': metrics[7], 'winkler25': metrics[8], 'window': window_key,'steps': steps_ahead, 'method': method} return ret
def print_interval_statistics(original, models): ret = "Model & Order & Sharpness & Resolution & Coverage & .05 & .25 & .75 & .95 \\\\ \n" for fts in models: _sharp, _res, _cov, _q5, _q25, _q75, _q95 = Measures.get_interval_statistics( original, fts) ret += fts.shortname + " & " ret += str(fts.order) + " & " ret += str(_sharp) + " & " ret += str(_res) + " & " ret += str(_cov) + " &" ret += str(_q5) + " &" ret += str(_q25) + " &" ret += str(_q75) + " &" ret += str(_q95) + "\\\\ \n" print(ret)
def print_interval_statistics(original, models): """ Run interval benchmarks on given models and data and print the results :param data: test data :param models: a list of FTS models to benchmark :return: """ ret = "Model & Order & Sharpness & Resolution & Coverage & .05 & .25 & .75 & .95 \\\\ \n" for fts in models: _sharp, _res, _cov, _q5, _q25, _q75, _q95 = Measures.get_interval_statistics(original, fts) ret += fts.shortname + " & " ret += str(fts.order) + " & " ret += str(_sharp) + " & " ret += str(_res) + " & " ret += str(_cov) + " &" ret += str(_q5) + " &" ret += str(_q25) + " &" ret += str(_q75) + " &" ret += str(_q95) + "\\\\ \n" print(ret)