VectorIndexer学习笔记
val indexer = new VectorIndexer()
.setInputCol("features")
.setOutputCol("indexed")
.setMaxCategories(2)
.fit(data).transform(data)
indexer.show(false)
spark.stop()
输出结果如下
结果分析
特征向量包含3个特征:0,1,2
特征0对应的值有4(1,2,3,5)个,大于设置的2,不进行转换
特征1对应的值有2(1,5)个,不大于设置的2,进行转换:
1 -> 0
5 -> 1
特征2对应的值有4(6,7,8,9)个,大于设置的2,不进行转换: