def gen(): sys_path = sys.path[:] if len(sys.argv) < 3: raise LookupError('Please specify model result to transfer.') elif len(sys.argv) > 3: raise UserWarning('Only one model result can be transfered.') model_path = os.path.join(current_dir, sys.argv[2]) sys.path.append(model_path) import pred pred_result, _ = get_pred(pred.get_model(), all_data, prep.date(8, 15)) pred_stats = stats(pred_result, all_data) print('| TOTAL VISITED BOUGHT FAVO CART NEW') print('| Pred # {:<8}{:<8}{:<8}{:<8}{:<8}{:<8}'.format(*pred_stats)) print('| % {:<8.0%}{:<8.3%}{:<8.3%}{:<8.3%}{:<8.3%}{:<8.3%}'.format(*[i*1./pred_stats[0] for i in pred_stats])) from datetime import date target_path = os.path.join(current_dir, 'result%02d.txt'%date.today().day) output(target_path, pred_result) sys.path = sys_path
def gen(): sys_path = sys.path[:] if len(sys.argv) < 3: raise LookupError('Please specify model result to transfer.') elif len(sys.argv) > 3: raise UserWarning('Only one model result can be transfered.') model_path = os.path.join(current_dir, sys.argv[2]) sys.path.append(model_path) import pred pred_result, _ = get_pred(pred.get_model(), all_data, prep.date(8, 15)) pred_stats = stats(pred_result, all_data) print('| TOTAL VISITED BOUGHT FAVO CART NEW') print('| Pred # {:<8}{:<8}{:<8}{:<8}{:<8}{:<8}'.format(*pred_stats)) print('| % {:<8.0%}{:<8.3%}{:<8.3%}{:<8.3%}{:<8.3%}{:<8.3%}'.format( *[i * 1. / pred_stats[0] for i in pred_stats])) from datetime import date target_path = os.path.join(current_dir, 'result%02d.txt' % date.today().day) output(target_path, pred_result) sys.path = sys_path
def on_press_button(self, instance): import pred model = pred.get_model('mobclass.pkl') data = pred.get_value( self.bataryInput, self.blueInput, self.csInput, self.dsInput, self.fcInput, self.four_gInput, self.int_memoryInput, self.m_depInput, self.mobile_wtInput, self.n_coresInput, self.pcInput, self.px_heightInput, self.px_widthInput, self.ramInput, self.sc_hInput, self.sc_wInput, self.talk_timeInput, self.three_gInput, self.touch_screenInput, self.wifiInput) # predict model predictVal = pred.get_predict(model, data) if (predictVal == 0): predictVal = "Düşük Fiyatlı" if (predictVal == 1): predictVal = "Orta Fiyatlı" if (predictVal == 2): predictVal = "Yüksek Fiyatlı" if (predictVal == 3): predictVal = "Çok Yüksek Fiyatlı" # if you want follow value uncomment this rows #print(predictVal) phone.popUp(self=None, value=predictVal)
def val(): if len(sys.argv) < 3: raise LookupError('Please specify model to val.') val_cases = [ (prep.date(5, 18), prep.date(6, 17), 'predicts 5/18 to 6/17', '5/18'), (prep.date(6, 17), prep.date(7, 17), 'predicts 6/17 to 7/17', '6/17'), (prep.date(7, 17), prep.date(8, 16), 'predicts 7/17 to 8/16', '7/17'), ] for model_name in sys.argv[2:]: sys_path = sys.path[:] model_path = os.path.join(current_dir, model_name) sys.path.append(model_path) import pred reload(pred) print_model_header(model_name) Ps = [] Rs = [] Fs = [] for TRAIN_DATE, VAL_DATE, DESC, _ in val_cases: train_data = all_data[all_data[:, 3] < TRAIN_DATE] val_data = all_data[np.logical_and(all_data[:, 3] >= TRAIN_DATE, all_data[:, 3] < VAL_DATE)] all_userids = np.unique(train_data[:, 0]) pred_result, raw = get_pred(pred.get_model(), train_data, TRAIN_DATE - 1) val_result = get_val(val_data, all_userids) p, r, f, pred_ratings, hit_ratings = f1(pred_result, val_result, all_userids, raw) Ps.append(p) Rs.append(r) Fs.append(f) print_result_header(DESC) print_result_stats(stats(pred_result, train_data), stats(val_result, train_data), p) print_basic_result(p, r, f, pred_ratings, hit_ratings) plot_result(model_name, val_cases, Ps, Rs, Fs) sys.path = sys_path
def val(): if len(sys.argv) < 3: raise LookupError('Please specify model to val.') val_cases = [ (prep.date(5, 18), prep.date(6, 17), 'predicts 5/18 to 6/17', '5/18'), (prep.date(6, 17), prep.date(7, 17), 'predicts 6/17 to 7/17', '6/17'), (prep.date(7, 17), prep.date(8, 16), 'predicts 7/17 to 8/16', '7/17'), ] for model_name in sys.argv[2:]: sys_path = sys.path[:] model_path = os.path.join(current_dir, model_name) sys.path.append(model_path) import pred reload(pred) print_model_header(model_name) Ps = [] Rs = [] Fs = [] for TRAIN_DATE, VAL_DATE, DESC, _ in val_cases: train_data = all_data[all_data[:, 3] < TRAIN_DATE] val_data = all_data[np.logical_and( all_data[:, 3] >= TRAIN_DATE, all_data[:, 3] < VAL_DATE )] all_userids = np.unique(train_data[:, 0]) pred_result, raw = get_pred(pred.get_model(), train_data, TRAIN_DATE-1) val_result = get_val(val_data, all_userids) p, r, f, pred_ratings, hit_ratings = f1(pred_result, val_result, all_userids, raw) Ps.append(p) Rs.append(r) Fs.append(f) print_result_header(DESC) print_result_stats(stats(pred_result, train_data), stats(val_result, train_data), p) print_basic_result(p, r, f, pred_ratings, hit_ratings) plot_result(model_name, val_cases, Ps, Rs, Fs) sys.path = sys_path