(+ clojure big-ml)

Posted by

clojureWe’re excited to announce a Clojure library for our machine learning API. We use Clojure everyday here at BigML, so we want to make it easy to fire up the REPL and dive right into building decision tree models and making predictions.

The library is available from Clojars.  If you’re familiar with Leiningen, simply add this to your project’s dependencies to get started:
[bigml/clj-bigml “0.1.0”]

The library makes it easy to get, create, update, delete, and list BigML resources (which include sources, datasets, models, predictions, and evaluations).  The project readme has all the pertinent details, but we’ll highlight a couple Clojure specific features here.

First, data can be shared with BigML in three ways.  A data source may be created using either a local file, a remote URL (s3 and odata resources are supported), or directly from Clojure data:

;; source from local file
(source/create "some-local-directory/iris.csv.gz")

;; source from remote URL
(source/create "https://static.bigml.com/csv/iris.csv")

;; in-line source from Clojure data
(source/create [["Make" "Model" "Year" "Weight" "MPG"]
                ["AMC" "Gremlin" 1970 2648 21]
                ["AMC" "Matador" 1973 3672 14]
                ["AMC" "Gremlin" 1975 2914 20]
                ["Honda" "Civic" 1974 2489 24]
                ["Honda" "Civic" 1976 1795 33]])

Once you’ve built a model (see the readme for more on that), predictions may be generated with an API call. Alternatively, a model may be downloaded and converted directly into a Clojure function.  This approach means no waiting for an HTTP response.  It’s a great option when you need performance or just want to use your model offline.

;; get a previously created model from the famous iris dataset
;; http://en.wikipedia.org/wiki/Iris_flower_data_set
(def iris-model (api/get iris-model-id))

;; transform the model into a Clojure fn
(def iris-local-predictor
  (prediction/predictor iris-model))

;; apply the prediction fn to a list of field values
(iris-local-predictor [7.6 3.0 6.6 2.1]) ;; --> "Iris-virginica"

;; or apply the prediction fn to a map of field-id to value
(iris-local-predictor {"000000" 7.6
                       "000001" 3.0
                       "000002" 6.6
                       "000003" 2.1}) ;; --> "Iris-virginica"

Please make sure to check out the short examples we’ve added here.  One example shows how to grow and use a random decision forest.  The other illustrates how to use sampling options to split a dataset into proper training and test sets.

We hope this library will help Clojure developers explore BigML. Signing up is free and new accounts come with some initial credits.  Moreover, the API includes a development mode that waives the cost for small datasets. So we invite you to try out BigML and give us feedback!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s