aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark
diff options
context:
space:
mode:
Diffstat (limited to 'python/pyspark')
-rw-r--r--python/pyspark/mllib/fpm.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/python/pyspark/mllib/fpm.py b/python/pyspark/mllib/fpm.py
index 628ccc01cf..d8df02bdba 100644
--- a/python/pyspark/mllib/fpm.py
+++ b/python/pyspark/mllib/fpm.py
@@ -15,6 +15,10 @@
# limitations under the License.
#
+import numpy
+from numpy import array
+from collections import namedtuple
+
from pyspark import SparkContext
from pyspark.rdd import ignore_unicode_prefix
from pyspark.mllib.common import JavaModelWrapper, callMLlibFunc, inherit_doc
@@ -36,14 +40,14 @@ class FPGrowthModel(JavaModelWrapper):
>>> rdd = sc.parallelize(data, 2)
>>> model = FPGrowth.train(rdd, 0.6, 2)
>>> sorted(model.freqItemsets().collect())
- [([u'a'], 4), ([u'c'], 3), ([u'c', u'a'], 3)]
+ [FreqItemset(items=[u'a'], freq=4), FreqItemset(items=[u'c'], freq=3), ...
"""
def freqItemsets(self):
"""
- Get the frequent itemsets of this model
+ Returns the frequent itemsets of this model.
"""
- return self.call("getFreqItemsets")
+ return self.call("getFreqItemsets").map(lambda x: (FPGrowth.FreqItemset(x[0], x[1])))
class FPGrowth(object):
@@ -67,6 +71,11 @@ class FPGrowth(object):
model = callMLlibFunc("trainFPGrowthModel", data, float(minSupport), int(numPartitions))
return FPGrowthModel(model)
+ class FreqItemset(namedtuple("FreqItemset", ["items", "freq"])):
+ """
+ Represents an (items, freq) tuple.
+ """
+
def _test():
import doctest