Database Reference
In-Depth Information
This chart helps us visually verify the results, but the most important part of the algorithm's
output is probably the within-cluster sum of squared errors (WCSS). This should be as low
as possible for a given number of clusters. In the example, this value is approximately 1.71,
which is ine.
Building macros
Another interesting aspect of this recipe is the use of a macro to create a wrapper function for
the cluster analysis. Because Clojure, like other lisps, is written in its own data structures, it's
common to write programs to manipulate programs. In fact, this is so common that Clojure
provides a stage of compilation dedicated to letting the user manipulate the input program.
These meta-programs are called macros. The Clojure compiler reads forms, uses macros
to manipulate them, and inally compiles the output of the macros. Macros are a powerful
tool that allows users to deine their own control structures and other forms far beyond what
programmers of other languages have available to them.
We can easily see how the macro is turned into a function using macroexpand-1 , like this:
(macroexpand-1 '(defanalysis
k-means SimpleKMeans buildClusterer
[["-N" k 2]
["-I" iterations 100]
["-V" verbose false :flag-true]
["-S" seed 1 random-seed]
["-A" distance EuclideanDistance .getName]]))
I cleaned up this output to make it look more like something we'd type. The function that the
macro creates is listed here:
(defn k-means
[dataset__1216__auto__ &
{:or {k 2,
max-iterations 100,
verbose false,
seed 1,
distance EuclideanDistance},
:keys [k max-iterations verbose seed distance]}]
(let [options__1217__auto__
(->options "-N" k
"-I" max-iterations
(when verbose "-V")
"-S" (random-seed seed)
"-A" (.getName distance))]
(doto (new SimpleKMeans)
(.setOptions options__1217__auto__)
(.buildClusterer dataset__1216__auto__))))
 
Search WWH ::




Custom Search