def binary_accuracy_indirect(predict, true): pred = utils.get_all_dangerous_scenarios(predict['speed'], predict['cos_wind_dir'], predict['sin_wind_dir']) true = utils.get_all_dangerous_scenarios(true['speed'], true['cos_wind_dir'], true['sin_wind_dir']) pred_auc = metrics.roc_auc_score(true, pred).round(3) return pred_auc #, base_auc, pred_score, base_score,
def binary_accuracy(predict, true, baseline): pred = utils.get_all_dangerous_scenarios(predict['speed'], predict['cos_wind_dir'], predict['sin_wind_dir']) true = utils.get_all_dangerous_scenarios(true['speed'], true['cos_wind_dir'], true['sin_wind_dir']) base = utils.get_all_dangerous_scenarios(baseline['speed'], baseline['cos_wind_dir'], baseline['sin_wind_dir']) #calculate prediction accuracies pred_score = metrics.accuracy_score(pred, true).round(3) base_score = metrics.accuracy_score(base, true).round(3) #calculate auc pred_auc = metrics.roc_auc_score(pred, true).round(3) base_auc = metrics.roc_auc_score(base, true).round(3) return pred_score, base_score, pred_auc, base_auc
} # predict_train, predict_test = run_rf(steps_in=1, steps_out=1) for t in t_list: #run model predict_train, predict_test = run_rf(steps_in, steps_out=t) # #calculate angles from sin and cosine # predict['angle'] = predict.apply(lambda row: utils.get_angle_in_degree(row['cos_wind_dir'],row['sin_wind_dir']),axis = 1) # true['angle'] = true.apply(lambda row: utils.get_angle_in_degree(row['cos_wind_dir'],row['sin_wind_dir']), axis = 1) # base['angle'] = base.apply(lambda row: utils.get_angle_in_degree(row['cos_wind_dir'],row['sin_wind_dir']), axis = 1) predict_train[ 'dangerous_indirect'] = utils.get_all_dangerous_scenarios( predict_train['speed'], predict_train['cos_wind_dir'], predict_train['sin_wind_dir']) predict_test['dangerous_indirect'] = utils.get_all_dangerous_scenarios( predict_test['speed'], predict_test['cos_wind_dir'], predict_test['sin_wind_dir']) predict_train.to_csv('results/rf_result_train_' + str(t) + '.csv', index=False) predict_test.to_csv('results/rf_result_test_' + str(t) + '.csv', index=False) # # #calculate mae for regression # mae_speed, mae_speed_base, mae_angle, mae_angle_base = get_mae_indirect(predict, true, base) # #calculate accuracy & auc for scenario prediction # pred_scenario_indirect = scenario_accuracy_indirect(predict, true) # pred_dangerous_indirect= binary_accuracy_indirect(predict, true)