Database Reference
In-Depth Information
(let [indexes
(loop [sample #{}]
(if (= (count sample) size)
(sort sample)
(recur
(conj sample
(rand-int inst-count)))))
sample (Instances. instances size)]
(doall
(map #(.add sample (.get instances %))
indexes))
sample))))
2.
We also need to create the wrapper function for the Bayesian analyzer:
(defanalysis
naive-bayes NaiveBayes buildClassifier
[["-K" kernel-density false :flag-true]
["-D" discretization false :flag-true]])
3.
Now we can create a sample of the mushroom data and apply the analyzer to it:
(def shroom-sample (sample-instances shrooms 2000))
(def bayes (naive-bayes shroom-sample))
4.
We can pull an instance from the original dataset and use the Bayesian model to
classify it. In this dataset, edible ( e ) is 0 and poisonous ( p ) is 1, so the model has
correctly classiied this data:
user=> (.get shrooms 2)
#<DenseInstance b,s,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,n,m,e>
user=> (.classifyInstance bayes (.get shrooms 2))
0.0
How it works…
Bayesian models work by initially assuming that there's usually a ifty-ifty chance that a
mushroom is edible or poisonous. For each item in the training set, it uses the values of each
mushroom's attributes to nudge this ifty-ifty chance in the direction of the classiication for
that mushroom. So if a mushroom has a bell-shaped cap, smells of anise, and is edible, the
model will assume that if it sees another mushroom with a bell-shaped cap that smells of
anise, it's slightly more likely to be edible than poisonous.
 
Search WWH ::




Custom Search