Saving the classifier to a file

Finally, we can write out our classifier to a file using clj-ml.utils/serialize-to-file:

(defn ex-4-48 []
  (let [dataset (->> (load-data "titanic.tsv")
                     (to-weka)
                     (mlf/make-apply-filter
                      :replace-missing-values {}))
        classifier (cl/make-classifier :decision-tree
                                       :random-forest)
        file (io/file (io/resource "classifier.bin"))]
    (clu/serialize-to-file classifier file)))

At some point later, we can load up our trained classifier using the clj-ml.utils/deserialize-from-file and immediately begin classifying new data.

Get Clojure for Data Science now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.