def inner_optimization_result_accuracy_test(self): """Test for the correct result of a GridSearch optimization.""" fm = ExponentialSmoothing() startingPercentage = 0.0 endPercentage = 100.0 # manually select the best alpha self.timeSeries.normalize("second") results = [] for smoothingFactor in [alpha / 100.0 for alpha in xrange(1, 100)]: # pragma: no cover fm.set_parameter("smoothingFactor", smoothingFactor) resultTS = self.timeSeries.apply(fm) error = SMAPE() error.initialize(self.timeSeries, resultTS) results.append([error, smoothingFactor]) bestManualResult = min(results, key=lambda item: item[0].get_error(startingPercentage, endPercentage)) # automatically determine the best alpha using GridSearch gridSearch = GridSearch(SMAPE, precision=-4) # used, because we test a submethod here gridSearch._startingPercentage = startingPercentage gridSearch._endPercentage = endPercentage result = gridSearch.optimize_forecasting_method(self.timeSeries, fm) # the grid search should have determined the same alpha bestManualAlpha = bestManualResult[1] errorManualResult = bestManualResult[0].get_error() bestGridSearchAlpha = result[1]["smoothingFactor"] errorGridSearchResult = result[0].get_error() assert errorManualResult > errorGridSearchResult
def local_error_test(self): """Test SymmetricMeanAbsolutePercentageError.local_error.""" localErrors = [18.182, 13.953, 200, 28.571, 40, 200, 200, 200, 200, 200, 0] smape = SymmetricMeanAbsolutePercentageError() for i in xrange(len(self.dataOrg)): calc_local_error = smape.local_error([self.dataOrg[i]], [self.dataCalc[i]]) self.assertEquals("%.3f" % calc_local_error,"%.3f" % localErrors[i])
def error_calculation_test(self): """Test the calculation of the SymmetricMeanAbsolutePercentageError.""" tsOrg = TimeSeries() tsCalc = TimeSeries() for idx in xrange(len(self.dataOrg)): tsOrg.add_entry(float(idx), self.dataOrg[idx]) tsCalc.add_entry(float(idx), self.dataCalc[idx]) smape = SymmetricMeanAbsolutePercentageError() smape.initialize(tsOrg, tsCalc) self.assertEquals("118.24", str(smape.get_error())[:6])