数据集下载地址: http://www.sigkdd.org/kddcup/index.php?section=1998&method=data
1、因变量为数值类型,转化为分类类型
> cup98$TARGET_D2 <- cut(cup98$TARGET_D, right=F, breaks=c(0, 0.1, 10, 15, 20, 25, 30, 50,max(cup98$TARGET_D))) breaks也可以用seq生成breaks=seq(0, 100, by=5)
>table(cup98$TARGET_D2)
[0,0.1)[0.1,10) [10,15) [15,20) [20,25) [25,30) [30,50) [50,200)
90569 1132 1378 806 745 435 233 110
2、检查采样的结果
检查抽样后的训练集和测试集中的因变量,看其分布与原始数据中的分布时候一致,如果不一致,可是使用分层抽样:
>round(prop.table(table(cup98$TARGET_B)), digits=3)
0 1
0.949 0.051
>round(prop.table(table(trainData$TARGET_B)), digits=3)
0 1
0.948 0.052
>round(prop.table(table(testData$TARGET_B)), digits=3)
0 1
0.95 0.05