Database Reference
In-Depth Information
How to do it…
Once the namespaces are available, we can access the datasets easily:
user=> (def iris (get-dataset :iris) )
#'user/iris
user=> (col-names iris)
[:Sepal.Length :Sepal.Width :Petal.Length :Petal.Width :Species]
user=> (nrow iris)
150
user=> (set ($ :Species iris))
#{"versicolor" "virginica" "setosa"}
How it works…
We use the get-dataset function to access the built-in datasets. In this case, we're loading
the Fisher's Iris dataset, sometimes called Anderson's dataset. This is a multivariate dataset
for discriminant analysis. It gives petal and sepal measurements for 150 different Irises of
three different species.
Incanter's sample datasets cover a wide variety of topics—from U.S. arrests to plant growth
and ultrasonic calibration. They can be used to test different algorithms and analyses and to
work with different types of data.
By the way, the names of functions should be familiar to you if you've previously used R.
Incanter often uses the names of R's functions instead of using the Clojure names for the
same functions. For example, the preceding code sample used nrow instead of count .
There's more...
Incanter's API documentation for get-dataset ( http://liebke.github.com/
incanter/datasets-api.html#incanter.datasets/get-dataset ) lists more
sample datasets, and you can refer to it for the latest information about the data that
Incanter bundles.
Loading Clojure data structures into
datasets
While they are good for learning, Incanter's built-in datasets probably won't be that useful for
your work (unless you work with irises). Other recipes cover ways to get data from CSV iles
and other sources into Incanter (see Chapter 1 , Importing Data for Analysis ). Incanter also
accepts native Clojure data structures in a number of formats. We'll take look at a couple of
these in this recipe.
 
Search WWH ::




Custom Search