Database Reference
In-Depth Information
How to do it…
We'll train an instance of the Apriori class, extract the classiication rules, and use them to
classify the instances:
1.
First, we need a function that converts keywords into integers for one of the options
to the Apriori class:
(def rank-metrics
{:confidence 0 :lift 1 :leverage 2 :conviction 3})
2.
Now we'll use that in our deinition of a wrapper function for the Apriori class:
(defanalysis
apriori Apriori buildAssociations
[["-N" rules 10]
["-T" rank-metric :confidence rank-metrics]
["-C" min-metric 0.9]
["-D" min-support-delta 0.05]
[["-M" "-U"] min-support-bounds [0.1 1.0] :seq]
["-S" significance nil :not-nil]
["-I" output-itemsets false :flag-true]
["-R" remove-missing-value-columns
false :flag-true]
["-V" progress false :flag-true]
["-A" mine-class-rules false :flag-true]
["-c" class-index nil :not-nil]])
3.
With this in place, we can use it the way we have used the other wrapper functions:
(def a (apriori shrooms))
4.
Then we can print the association rules:
user=> (doseq [r (.. a getAssociationRules getRules)]
(println
(format "%s => %s %s = %.4f"
(mapv str (.getPremise r))
(mapv str (.getConsequence r))
(.getPrimaryMetricName r)
(.getPrimaryMetricValue r))))
["veil-color=w"] => ["veil-type=p"] Confidence = 1.0000
["gill-attachment=f"] => ["veil-type=p"] Confidence = 1.0000
 
Search WWH ::




Custom Search