我正在尝试使用 MLlib 的 FPGrowth 对交易数据进行基本的购物篮分析。我已将交易编码为类似格式:
transactions.take(3)
res632: Array[Array[String]] = Array(Array(7976503128), Array(68113132893, 1800000725, 3120027015, 4850030414, 2100061223, 5150055538, 60538871457), Array(68113174202))
数组中的各个数字是我的产品 id 作为字符串(如 68113132893、7976503128 等)。
现在,当我运行 FPGrowth 模型时,它运行时没有任何错误:
val fpg = new FPGrowth()
.setMinSupport(0.5)
.setNumPartitions(10)
val modelBuild = fpg.run(transactions)
fpg: org.apache.spark.mllib.fpm.FPGrowth = org.apache.spark.mllib.fpm.FPGrowth@74a103be
modelBuild: org.apache.spark.mllib.fpm.FPGrowthModel[String] = org.apache.spark.mllib.fpm.FPGrowthModel@391b111a
但是当我试图获取频繁项集时,它显示的是空白数组
modelBuild.freqItemsets.collect().foreach { itemset =>
println(itemset.freq)
}
res660: Array[org.apache.spark.mllib.fpm.FPGrowth.FreqItemset[String]] = Array()
无法找到问题所在。请帮忙!