ob = data.BME.head(1440) hmm = IterativeKmeansHMM(ob, max_k=10, std_thres=1) centers = hmm.iterative_kmeans() # showing the first day # data.WHE.iloc[0:1440].plot() # whole house current profile for day 1 # data.iloc[0:1440, 1:n_appliance+1].sum(1).plot() # defining problem days = 3 # as the same length in SparseNILM demo length = 1440 * days # 1 minute interval, 7 days aggregate = data.WHE.tail(36 * 1440) # test on the last 36 days hmms = collections.OrderedDict() app_ids = list(data)[1:-1] for app_id in app_ids: hmm = IterativeKmeansHMM(data[app_id].head(length), max_k=4, std_thres=1) hmm.fit() hmms[app_id] = hmm solver = nilm.SIQP(aggregate, hmms=hmms, step_thr=2) solver.solve() ground_truth = data[app_ids].tail(36 * 1440) evaluator = Evaluator(ground_truth, solver.estimate, solver.aggregate) print(evaluator.report) evaluator.report.to_csv( os.path.join('data', 'AMPdsR1_report_%i_appliances_for_train_%i_days_test_36_days.csv' % (n_appliance, days))) sol_times.loc[n_appliance, 'sol_time'] = solver.sol_time sol_times.to_csv(os.path.join('data', 'sol_time_vs_number_appliances.csv')) # evaluator.show() sol_times.to_csv(os.path.join('data', 'sol_time_vs_number_appliances.csv'))
load_train.fillna(0, inplace=True) load_train = load_train.resample('1min', np.median) load_test = test.buildings[building].elec[app].load().next() load_test.fillna(0, inplace=True) load_test = load_test.resample('1min', np.median) data_train[app] = load_train.loc[data_train.index, :].values data_test[app] = load_test.loc[data_test.index, :].values hmm = IterativeKmeansHMM(data_train[app].copy().dropna(), max_k=max_states, std_thres=step_thres) hmm.fit() hmms[app] = hmm data_test.dropna(axis=0, inplace=True) aggregate = data_test.sum(axis=1) solver = nilm.SIQP(aggregate, hmms, step_thr=step_thres) solver.solve() ground_truth = data_test[apps] evaluator = Evaluator(ground_truth, solver.estimate, solver.aggregate, standby=10) print evaluator.report evaluator.show() evaluator.report.to_csv( os.path.join( 'data', 'REDD_report_house_%i_one_step_at_a_time_split_train_test_max_hmm_states_%i_all_apps.csv' % (building, max_states)))