我正在尝试使用Spark Scala运行关联规则。我首先创建一个FPGrowth树并将其传递给关联规则方法。
但是,我希望添加一个最大模式长度参数,以限制我想要的LHS和RHS项目数。我只想要项目之间的一对一关联。
val model = new FPGrowth()
.setMinSupport(0.1)
.setNumPartitions(10)
.run(transactions)
// Generate association rules based on the frequent sets generated by FPgrowth
val ar = new AssociationRules().setMinConfidence(0.6)
val results = ar.run(model.freqItemsets)
产生的关联规则是:
ItemA => ItemB, {confidence}
ItemB => ItemC, {confidence}
ItemA,ItemB => ItemC, {confidence}
ItemA,ItemD => ItemE, {confidence}
但我只希望它返回双方都有一个项目的结果,即:
ItemA => ItemB, {confidence}
ItemB => ItemC, {confidence}
基本上,我正在寻找一种在Spark Scala / Spark Java中指定最大长度参数的方法
有什么建议吗?
答案 0 :(得分:1)
您可以filter
结果:
val ar = new AssociationRules().setMinConfidence(0.6)
val results = ar.run(model.freqItemsets)
.filter(rule => rule.antecedent.size == 1 && rule.consequent.size == 1)