我想用GBTClassifier对不平衡的数据集执行二进制分类。我没有看到spark documentation允许这样做的任何选项。
有没有人知道如何通过指定我们的数据不平衡的事实来使用GBTClassifier?
谢谢
注:我使用的是spark 2.3.2
发布于 2019-05-18 00:04:47
这是我天真的解决方案:随机对多数类进行下采样。这种解决方案的缺点是丢失了信息,并且不适用于小数据集。
val resampledTrainDF = {
val positiveLabel = "1"
val trainDF_positives = trainDF.where(F.col(label) === positiveLabel)
val trainDF_negatives = trainDF.where(F.col(label) =!= positiveLabel)
val withReplacement = trainDF_positives.count >= trainDF_negatives.count
if (withReplacement) {
// downsampling positives
val sampSize = math.round( (1.0 * trainDF_negatives.count / trainDF_positives.count) * 1000) / 1000.0
println("Downsampling Positives by " + (1 - sampSize)*100 + " %")
trainDF_positives.sample(false, sampSize).union(trainDF_negatives)
} else {
//downsampling negatives
val sampSize = math.round( (1.0 * trainDF_positives.count / trainDF_negatives.count) * 1000) / 1000.0
println("Downsampling Negatives by " + (1 - sampSize)*100 + "%")
trainDF_negatives.sample(false, sampSize).union(trainDF_positives)
}
}
https://stackoverflow.com/questions/56187405
复制相似问题