2016-09-21 39 views
1

我正在嘗試使用MLlib中的FPGrowth對交易數據進行基本的市場購物籃分析。我已編碼的交易是像格式:Spark 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 = [email protected] 
    modelBuild: org.apache.spark.mllib.fpm.FPGrowthModel[String] = [email protected] 

當我試圖讓頻繁項集,它顯示空白陣列

modelBuild.freqItemsets.collect().foreach { itemset => 
    println(itemset.freq) 
    } 

    res660: Array[org.apache.spark.mllib.fpm.FPGrowth.FreqItemset[String]] = Array() 

無法找到問題所在。請幫忙!

回答

2

將minSupport減小到0.00001並打印所有設置。來自Spark文檔:

minSupport:對項目集的最小支持被標識爲頻繁。例如,如果一個項目出現在5個交易中的3個,則它具有3/5 = 0.6的支持。

相關問題