def cv(method, theme, kind): no_invest = gbs.get_no_invest_set() hdd_pair = get_pair('HDD') print hdd_pair[0] hdd_pair = [x for x in hdd_pair if x[0] in no_invest] print len(hdd_pair) n_par_temp = 2 lines = [] if theme == 'eui_elec': base_temp = '55F' else: base_temp = '65F' lines.append('Building Number,CVRMSE_{0}'.format(method)) for p in hdd_pair: b = p[0] s = p[1] df = pd.read_csv(weatherdir + 'dd_temp_eng/{0}_{1}_{2}.csv'.format(kind, b, s)) if len(df) < 36: continue df = df.tail(n=36) df_pairs = get_partitions(3, df) errs = [] for x in df_pairs: df_train = x[0] if df_train[theme].sum() == 0: continue df_test = x[1] y = np.array(df_test[theme]) if method == 'temperature': x = np.array(df_test[s]) d = ltm.piecewise_reg_one(b, s, n_par_temp, theme, None, df_train) y_hat = d['fun'](x, *(d['regression_par'])) elif method == 'dd': par_list = ld.opt_lireg(b, s, df_train, kind, theme, None) x = df_test[par_list[-1]] fun = lambda x: par_list[0] * x + par_list[1] y_hat = x.map(fun) elif method == 'vv': par_list = vv.lean(b, s, df_train, theme, base_temp) df_temp = df_test.copy() df_temp = df_temp[['month', base_temp]] df_perdd = par_list[0] df_perdd.reset_index(inplace=True) df_mg = pd.merge(df_test, df_perdd, left_on='month', right_index=True) y = df_mg[theme] y_hat = df_mg[base_temp] * df_mg['y_per_dd'] + par_list[-1] cvrmse = util.CVRMSE(y, y_hat, n_par_temp) print cvrmse errs.append(cvrmse) line = '{0},{1}'.format(b, (np.array(errs)).mean()) print line lines.append(line) with open(weatherdir + 'cv_{0}_{1}.csv'.format(method, theme), 'w+') as wt: wt.write('\n'.join(lines)) return
def write_co_sets(): (cap_only, op_only, cap_and_op, cap_or_op) = gbs.get_invest_set() no_invest = gbs.get_no_invest_set() df1 = pd.DataFrame({'Building_Number': list(cap_only)}) df1['status'] = 'Capital Only' df2 = pd.DataFrame({'Building_Number': list(op_only)}) df2['status'] = 'Operational Only' df3 = pd.DataFrame({'Building_Number': list(cap_and_op)}) df3['status'] = 'Capital and Operational' df4 = pd.DataFrame({'Building_Number': list(no_invest)}) df4['status'] = 'No Known Investment' df5 = pd.DataFrame({'Building_Number': list(cap_or_op)}) df5['status'] = 'With Investment' df = pd.concat([df1, df2, df3, df4, df5], ignore_index=True) df.to_csv(r_input + 'cap_op_cnt.csv', index=False) print 'end'