x_train, y_train_c, y_train_r, x_dev, y_dev_c, y_dev_r, x_test = load_data_v4( data_path='data') print('Training Multi-Task MLP model ...') check_pointer = ModelCheckpoint(filepath='models/multi_task_mlp.hdf5', verbose=1, save_best_only=True, save_weights_only=True) early_stopping = EarlyStopping(patience=3) csv_logger = CSVLogger('logs/multi_task_mlp.log') mt_model = multi_task_mlp(sample_dim=x_train.shape[1]) mt_model.fit({'mlp_input': x_train}, { 'r_output': y_train_r, 'c_output': y_train_c }, validation_data=([x_dev], [y_dev_r, y_dev_c]), batch_size=128, epochs=50, verbose=1, callbacks=[check_pointer, early_stopping, csv_logger]) if submit_flag: print('Generate submission ...') mt_model.load_weights(filepath='models/multi_task_mlp.hdf5') results = mt_model.predict([x_test])[0].reshape(-1, 1) make_submission(result_path='submissions', results=results, model_name='Multi_Task_MLP') print('***** End UAI-CUP-2017 *****')
csv_logger = CSVLogger('logs/embedding_mlp.log') embedding_mlp_model = embedding_mlp( cont_feature_dim=x_train_cont_features.shape[1]) embedding_mlp_model.fit( [ x_train_day_of_week, x_train_create_hour, x_train_poi_points, x_train_cont_features ], y_train, batch_size=128, epochs=100, verbose=1, validation_data=([ x_dev_day_of_week, x_dev_create_hour, x_dev_poi_points, x_dev_cont_features ], y_dev), callbacks=[check_pointer, early_stopping, csv_logger]) if submit_flag: print('Generate submission ...') embedding_mlp_model.load_weights(filepath='models/embedding_mlp.hdf5') results = embedding_mlp_model.predict([ x_test_day_of_week, x_test_create_hour, x_test_poi_points, x_dev_cont_features ]).reshape(-1, 1) make_submission(result_path='submissions', results=results, model_name='Embedding_MLP') print('***** End UAI-CUP-2017 *****')
return model if __name__ == '__main__': submit_flag = True if sys.argv[1] == 'submit' else False print('***** Start UAI-CUP-2017 *****') print('Loading data ...') x_train, y_train, x_dev, y_dev, x_test = load_data_v2(data_path='data') print('Training XGBoost Regression model ...') xgb_model = xgb() eval_set = [(x_dev, y_dev)] xgb_model.fit(x_train, y_train, early_stopping_rounds=3, eval_metric='mae', eval_set=eval_set, verbose=True) plot_importance(xgb_model) pyplot.show() if submit_flag: print('Generate submission ...') results = xgb_model.predict(x_test).reshape(-1, 1) make_submission(result_path='submissions', results=results, model_name='xgboost') print('***** End UAI-CUP-2017 *****')
# r_check_pointer = ModelCheckpoint(filepath='models/r_phase_mlp.hdf5', verbose=1, save_best_only=True, # save_weights_only=True) # r_csv_logger = CSVLogger('logs/r_phase_mlp.log') r_model = regression_mlp(sample_dim=x_train_r.shape[1]) # r_model.fit({'mlp_input': x_train_r}, # {'r_output': y_train_r}, # validation_split=0.1, # batch_size=128, epochs=50, verbose=1, # callbacks=[r_check_pointer, early_stopping, r_csv_logger]) if submit_flag: print('Generate submission ...') c_model.load_weights(filepath='models/c_phase_mlp.hdf5') r_model.load_weights(filepath='models/r_phase_mlp.hdf5') c_results = c_model.predict([x_test]).reshape(-1, 1) r_results = r_model.predict([x_test]).reshape(-1, 1) results = list() for item in zip(c_results, r_results): if item[0][0] > 0.5: results.append(item[1][0]) else: results.append(1.0) results = np.array(results).reshape(-1, 1) make_submission(result_path='submissions', results=results, model_name='Two_Phase_MLP') print('***** End UAI-CUP-2017 *****')
if __name__ == '__main__': submit_flag = True if sys.argv[1] == 'submit' else False print('***** Start UAI-CUP-2017 *****') print('Loading data ...') x_train, y_train, x_dev, y_dev, x_test = load_data_v2(data_path='data') print('Training Extra Trees Regression model ...') etr = extra_trees() etr.fit(x_train, y_train) etr_y_train = etr.predict(x_train).reshape(-1, 1) etr_y_dev = etr.predict(x_dev).reshape(-1, 1) train_mae = mean_absolute_error(y_train, etr_y_train) print('Train MAE:', train_mae) dev_mae = mean_absolute_error(y_dev, etr_y_dev) print('Dev MAE:', dev_mae) if submit_flag: print('Generate submission ...') results = etr.predict(x_test).reshape(-1, 1) make_submission(result_path='submissions', results=results, model_name='Extra_Trees') print('***** End UAI-CUP-2017 *****')
if __name__ == '__main__': submit_flag = True if sys.argv[1] == 'submit' else False print('***** Start UAI-CUP-2017 *****') print('Loading data ...') x_train, y_train, x_dev, y_dev, x_test = load_data_v2(data_path='data') print('Training KNN Regression model ...') knn_reg = KNeighborsRegressor() knn_reg.fit(x_train, y_train) knn_y_train = knn_reg.predict(x_train).reshape(-1, 1) knn_y_dev = knn_reg.predict(x_dev).reshape(-1, 1) train_mae = mean_absolute_error(y_train, knn_y_train) print('Train MAE:', train_mae) dev_mae = mean_absolute_error(y_dev, knn_y_dev) print('Dev MAE:', dev_mae) if submit_flag: print('Generate submission ...') results = knn_reg.predict(x_test).reshape(-1, 1) make_submission(result_path='submissions', results=results, model_name='KNN') print('***** End UAI-CUP-2017 *****')