Skip to content
Snippets Groups Projects
Commit f7efda39 authored by Feynman Liang's avatar Feynman Liang Committed by Xiangrui Meng
Browse files

[SPARK-9959] [MLLIB] Association Rules Java Compatibility

mengxr

Author: Feynman Liang <fliang@databricks.com>

Closes #8206 from feynmanliang/SPARK-9959-arules-java.
parent 3ff81ad2
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
package org.apache.spark.mllib.fpm package org.apache.spark.mllib.fpm
import scala.collection.JavaConverters._
import scala.reflect.ClassTag import scala.reflect.ClassTag
import org.apache.spark.Logging import org.apache.spark.Logging
...@@ -95,8 +96,10 @@ object AssociationRules { ...@@ -95,8 +96,10 @@ object AssociationRules {
* :: Experimental :: * :: Experimental ::
* *
* An association rule between sets of items. * An association rule between sets of items.
* @param antecedent hypotheses of the rule * @param antecedent hypotheses of the rule. Java users should call [[Rule#javaAntecedent]]
* @param consequent conclusion of the rule * instead.
* @param consequent conclusion of the rule. Java users should call [[Rule#javaConsequent]]
* instead.
* @tparam Item item type * @tparam Item item type
* *
* @since 1.5.0 * @since 1.5.0
...@@ -108,6 +111,11 @@ object AssociationRules { ...@@ -108,6 +111,11 @@ object AssociationRules {
freqUnion: Double, freqUnion: Double,
freqAntecedent: Double) extends Serializable { freqAntecedent: Double) extends Serializable {
/**
* Returns the confidence of the rule.
*
* @since 1.5.0
*/
def confidence: Double = freqUnion.toDouble / freqAntecedent def confidence: Double = freqUnion.toDouble / freqAntecedent
require(antecedent.toSet.intersect(consequent.toSet).isEmpty, { require(antecedent.toSet.intersect(consequent.toSet).isEmpty, {
...@@ -115,5 +123,23 @@ object AssociationRules { ...@@ -115,5 +123,23 @@ object AssociationRules {
s"A valid association rule must have disjoint antecedent and " + s"A valid association rule must have disjoint antecedent and " +
s"consequent but ${sharedItems} is present in both." 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
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment