Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.spark.mllib.fpm

import scala.collection.JavaConverters._
import scala.reflect.ClassTag

import org.apache.spark.Logging
Expand Down Expand Up @@ -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
Expand All @@ -108,12 +111,35 @@ 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, {
val sharedItems = antecedent.toSet.intersect(consequent.toSet)
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
}
}
}