Database Reference
In-Depth Information
In the script or REPL, we'll import the SVM library:
(import [weka.classifiers.functions LibSVM])
We'll also use the ionosphere dataset from the Weka datasets. (You can download this from
http://www.ericrochester.com/clj-data-analysis/data/UCI/ionosphere.
arff . ) This data is taken from a phased-array antenna system in Goose Bay, Labrador.
For each observation, the irst 34 attributes are from 17 pulse numbers (a pulse for each
observation) for the system, with two attributes per pulse number. The thirty-ifth attribute
indicates whether the reading is good or bad. Good readings show evidence of some kind of
structure in the ionosphere. Bad readings do not; their signals pass through the ionosphere.
We'll load this and set the last column, the "good" or "bad" column as the class index:
(def ion (doto (load-arff "data/UCI/ionosphere.arff")
(.setClassIndex 34)))
Finally, we'll use the defanalysis macro from the Discovering groups of data with K-Means
clustering recipe and the sample-instances function from the Classifying data with Naive
Bayesian classiiers recipe.
How to do it…
For this recipe, we'll deine some utility functions and the analysis algorithm wrapper. Then
we'll put it through its paces:
1.
A number of the options for the SVM analysis have to be converted from Clojure-
friendly values. For example, we want to pass true to one option and a mnemonic
keyword to another, but Weka wants both of these as integers. So to make the
parameter values more natural to Clojure, we'll use several functions that convert the
Clojure parameters to the integer strings that Weka wants:
(defn bool->int [b] (if b 1 0))
(def svm-types
{:c-svc 0, :nu-svc 1, :one-class-svm 2,
:epsilon-svr 3, :nu-svr 4})
(def svm-fns
{:linear 0, :polynomial 1, :radial-basis 2,
:sigmoid 3})
2. We'll use these to deine the wrapper function for the LibSVM class, which is a
standalone library that works with Weka:
(defanalysis
svm LibSVM buildClassifier
[["-S" svm-type :c-svc svm-types]
["-K" kernel-fn :radial-basis svm-fns]
 
Search WWH ::




Custom Search