aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeynman Liang <fliang@databricks.com>2015-08-17 09:58:34 -0700
committerXiangrui Meng <meng@databricks.com>2015-08-17 09:58:34 -0700
commitf7efda3975d46a8ce4fd720b3730127ea482560b (patch)
tree4d0383fd6a3cf3ec89349d5ffcea136327d93ab4
parent3ff81ad2dedc7cc3defb6e418d7c5fb415d56026 (diff)
downloadspark-f7efda3975d46a8ce4fd720b3730127ea482560b.tar.gz
spark-f7efda3975d46a8ce4fd720b3730127ea482560b.tar.bz2
spark-f7efda3975d46a8ce4fd720b3730127ea482560b.zip
[SPARK-9959] [MLLIB] Association Rules Java Compatibility
mengxr Author: Feynman Liang <fliang@databricks.com> Closes #8206 from feynmanliang/SPARK-9959-arules-java.
-rw-r--r--mllib/src/main/scala/org/apache/spark/mllib/fpm/AssociationRules.scala30
1 files changed, 28 insertions, 2 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/fpm/AssociationRules.scala b/mllib/src/main/scala/org/apache/spark/mllib/fpm/AssociationRules.scala
index 72d0ea0c12..7f4de77044 100644
--- a/mllib/src/main/scala/org/apache/spark/mllib/fpm/AssociationRules.scala
+++ b/mllib/src/main/scala/org/apache/spark/mllib/fpm/AssociationRules.scala
@@ -16,6 +16,7 @@
*/
package org.apache.spark.mllib.fpm
+import scala.collection.JavaConverters._
import scala.reflect.ClassTag
import org.apache.spark.Logging
@@ -95,8 +96,10 @@ object AssociationRules {
* :: Experimental ::
*
* An association rule between sets of items.
- * @param antecedent hypotheses of the rule
- * @param consequent conclusion of the rule
+ * @param antecedent hypotheses of the rule. Java users should call [[Rule#javaAntecedent]]
+ * instead.
+ * @param consequent conclusion of the rule. Java users should call [[Rule#javaConsequent]]
+ * instead.
* @tparam Item item type
*
* @since 1.5.0
@@ -108,6 +111,11 @@ object AssociationRules {
freqUnion: Double,
freqAntecedent: Double) extends Serializable {
+ /**
+ * Returns the confidence of the rule.
+ *
+ * @since 1.5.0
+ */
def confidence: Double = freqUnion.toDouble / freqAntecedent
require(antecedent.toSet.intersect(consequent.toSet).isEmpty, {
@@ -115,5 +123,23 @@ object AssociationRules {
s"A valid association rule must have disjoint antecedent and " +
s"consequent but ${sharedItems} is present in both."
})
+
+ /**
+ * Returns antecedent in a Java List.
+ *
+ * @since 1.5.0
+ */
+ def javaAntecedent: java.util.List[Item] = {
+ antecedent.toList.asJava
+ }
+
+ /**
+ * Returns consequent in a Java List.
+ *
+ * @since 1.5.0
+ */
+ def javaConsequent: java.util.List[Item] = {
+ consequent.toList.asJava
+ }
}
}