def one_forecast(self, trainingdata, testdata, start_forecast, end_forecast, period_errors): #electrical_forecast = DayTypeForecast(BaseEnvironment(start_forecast, False, False), trainingdata, samples_per_hour=1) #forecast = [electrical_forecast.get_forecast_at(timestamp) for timestamp in range(start_forecast,end_forecast,3600)] forecast_nodaysplit, (alpha, beta, gamma, delta, autocorr), insample = double_seasonal( trainingdata, 24, 24 * 7, len(testdata), optimization_type="RMSE") for day, length in enumerate(range(24, 14 * 24, 24)): period_errors[day][0] += self.rmse(forecast_nodaysplit[:length], testdata[:length]) period_errors[day][1] += StatisticalForecast.MASE( trainingdata, forecast_nodaysplit[:length], testdata[:length])
def strom_real(self): sep = os.path.sep t0 = time() path = os.path.join( BASE_DIR, "server" + sep + "forecasting" + sep + "devices" + sep + "data" + sep + "Electricity_2012Neuendorf.csv") raw_dataset1 = DataLoader.load_from_file( path, "Strom - Verbrauchertotal (Aktuell)", "\t") dates1 = DataLoader.load_from_file(path, "Datum", "\t") path2 = os.path.join( BASE_DIR, "server" + sep + "forecasting" + sep + "devices" + sep + "data" + sep + "Electricity_2013.csv") raw_dataset2 = DataLoader.load_from_file( path2, "Strom - Verbrauchertotal (Aktuell)", "\t") dates2 = DataLoader.load_from_file(path2, "Datum", "\t") t1 = time() dates1 = StatisticalForecast.make_hourly([int(d) for d in dates1], 6) dates2 = StatisticalForecast.make_hourly([int(d) for d in dates2], 6) demand1 = StatisticalForecast.make_hourly( [float(val) / 1000.0 for val in raw_dataset1], 6) demand2 = StatisticalForecast.make_hourly( [float(val) / 1000.0 for val in raw_dataset2], 6) t2 = time() rm = StatisticalForecast.MASE(demand1, demand1[:len(demand2)], demand2) #split_testdata1 = DayTypeForecast.split_weekdata(demand1,samples_per_hour=1,start_date=datetime.fromtimestamp(dates1[0])) #split_testdata2 = DayTypeForecast.split_weekdata(demand2,samples_per_hour=1,start_date=datetime.fromtimestamp(dates2[0])) #for index, dataset in enumerate(split_testdata1): # print self.rmse(split_testdata2[index], dataset)#StatisticalForecast.MASE(dataset, dataset[:len(split_testdata2[index])],split_testdata2[index][:len(dataset)]) t3 = time() print "t0 ", t1 - t0, "t1 ", t2 - t1, "t3 ", t3 - t2 print rm