weight
Param
해야 이중와 왜곡 된 라벨 분배를 수정하기 위해 예를 들어 샘플의 중요성을 결정하는 데 사용됩니다.
의는이 같은 데이터가 있다고 가정 해 봅시다 :
val data = spark.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt")
val skewed = data
.where($"label" === 0.0).limit(5)
.union(data.where($"label" === 1.0))
skewed.groupBy($"label").count.show
+-----+-----+
|label|count|
+-----+-----+
| 0.0| 5|
| 1.0| 57|
+-----+-----+
우리는
label
동일한 0.0로 기록에 높은 가중치를 추가 할 수 있습니다
:
val weighted = skewed
.withColumn("weight", when($"label" === 0.0, 1.0).otherwise(0.1))
val weightedModel = new NaiveBayes().setWeightCol("weight").fit(weighted)
weightedModel.transform(weighted.where($"label" === 0.0)).show
+-----+--------------------+------+--------------------+-----------+----------+
|label| features|weight| rawPrediction|probability|prediction|
+-----+--------------------+------+--------------------+-----------+----------+
| 0.0|(692,[127,128,129...| 1.0|[-165013.81130787...| [1.0,0.0]| 0.0|
| 0.0|(692,[129,130,131...| 1.0|[-191959.02863649...| [1.0,0.0]| 0.0|
| 0.0|(692,[154,155,156...| 1.0|[-201850.30335886...| [1.0,0.0]| 0.0|
| 0.0|(692,[127,128,129...| 1.0|[-202315.73236242...| [1.0,0.0]| 0.0|
| 0.0|(692,[153,154,155...| 1.0|[-258710.53340756...| [1.0,0.0]| 0.0|
+-----+--------------------+------+--------------------+-----------+----------+
은 당신이 할 수있는 특징 벡터의 크기를 조절하기 ElementwiseProduct
을 사용하십시오.