Ps:若不参加比赛的同志们可忽略此篇。
官方大赛提交要求:
模型得到的结果:
随机森林以及其他分类算法模型会输出当前的预测值和结果为此值的概率。如下所示:
假定这里我们规定正样本为0(即无风险的支付行为),负样本为1(即有风险的支付行为)。第一个概率表示预测结果为正样本的概率,第二个概率表示预测结果为负样本的概率,若预测结果为正样本的概率小于0.5,则表示该样本是正样本的概率很小,即模型会预测它为负样本(1)。见上图。
处理模型输出的结果:
package test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.text.DecimalFormat;
public class ProcessResultRiskxx {
public static void main(String[] args) throws IOException {
// 待处理的结果文件(无ID)
String testResultFilePath = "D:\\ant\\result_randomforest_deep15.csv";
// b榜测试文件(用于提取ID)
String testBFilePath = "D:\\ant\\atec_anti_fraud_test_b_convert.csv";
// 最终提交的文件
String finalFilePath = "D:\\ant\\result_randomforest_deep15_final.csv";
File testReadFile = new File(testResultFilePath);
File testBFile = new File(testBFilePath);
File finalFile = new File(finalFilePath);
BufferedReader brTestResultFile = new BufferedReader(new InputStreamReader(new FileInputStream(testReadFile)));
BufferedReader brTestBFile = new BufferedReader(new InputStreamReader(new FileInputStream(testBFile)));
BufferedWriter bwFinalFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(finalFile)));
String strLine = "";
// 表头不要
String strTestResult = brTestResultFile.readLine();
String strTestB = brTestBFile.readLine();
bwFinalFile.write("id,score\n");
// 逐行读入并替换引号,最后逐行写入
try {
while ((strTestResult = brTestResultFile.readLine()) != null
&& (strTestB = brTestBFile.readLine()) != null) {
// 读取id、风险类型
String id = strTestB.split(",")[0];
double probability = Double.parseDouble(strTestResult.split(",")[0].substring(2));
// 88577行
probability = 1.0 - probability;
// 不以科学记数法记录
DecimalFormat decimalFormat = new DecimalFormat("#,##0.0000000000000000");
String formattedProbability = decimalFormat.format(probability);
String tmpStr = id + "," + formattedProbability + "\n";
// 输出控制台
System.out.println(id + "----" + formattedProbability);
// 写入文件
bwFinalFile.write(tmpStr);
}
bwFinalFile.flush();
// 关闭流
brTestResultFile.close();
brTestBFile.close();
bwFinalFile.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
brTestResultFile.close();
brTestBFile.close();
bwFinalFile.close();
}
}
}
本次因未将id列送入模型训练,故需要在最后提交环节前加上id,表示唯一标示的交易。逻辑比较简单大家随便看下应该就懂了。这里为了方便大家提交,就贴出来了。
好,至此,将上一步文件提交后,英雄榜上应该就会有你的大名了!说实话,还是挺有意思的,我就是在这个环节中了排行榜的毒,熬夜刷了4、5次榜。大家需谨慎!!!