Skip to content

A small machine learning library written in Lisp (Clojure) aimed at providing simple, concise implementations of machine learning techniques and utilities.

License

Notifications You must be signed in to change notification settings

jiyouyou125/lambda-ml

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lambda-ml

A small machine learning library aimed at providing simple, concise implementations of machine learning techniques and utilities. It is written in Lisp (using the implementation du jour, Clojure) to maximize expressiveness and enjoyment.

Documentation

Algorithms

Supervised Learning

Unsupervised Learning

Data Structures

Installation

Add the following dependency to your project:

Clojars Project

Examples

Artificial neural network

(ns example (:require [lambda-ml.neural-network :refer :all]))

(def data [[0 0 0] [0 1 1] [1 0 1] [1 1 0]])
(def hidden-layers [3])
(def alpha 0.5)
(def lambda 0.001)
(def model (make-neural-network hidden-layers alpha lambda))

(def fit
  (-> #(neural-network-fit % (map butlast data) (map (comp vector last) data))
      (iterate model)
      (nth 5000)))

(neural-network-predict fit (map butlast data))
;;=> ((0.018947665113895507) (0.9768421723034613) (0.9770467568718264) (0.03108874342427228))

DBSCAN

(ns example (:require [lambda-ml.clustering.dbscan :refer :all]
                      [lambda-ml.distance :refer :all]))

(def epsilon 4.0)
(def min-pts 2)
(def data [[2 10] [2 5] [8 4] [5 8] [7 5] [6 4] [1 2] [4 9]])

(dbscan euclidean epsilon min-pts data)
;;=> {[4 9] 2, [5 8] 2, [7 5] 1, [6 4] 1, [8 4] 1}

Decision Tree

(ns example (:require [lambda-ml.decision-tree :refer :all]
                      [lambda-ml.metrics :refer :all]))

(def min-split 2)
(def min-leaf 1)
(def data [[0 0 0] [0 1 1] [1 0 1] [1 1 0]])
(def model (make-classification-tree gini-impurity min-split min-leaf))
(def fit (decision-tree-fit model data))

(decision-tree-predict fit (map butlast data))
;;=> (0 1 1 0)

K-means

(ns example (:require [lambda-ml.clustering.k-means :refer :all]
                      [lambda-ml.distance :refer :all]))

(def k 2)
(def iters 100)
(def data [[1 1] [1.5 2] [3 4] [5 7] [3.5 5] [4.5 5] [3.5 4.5]])

(nth (k-means k euclidean data) iters)
;;=> {0 ([3.5 4.5] [4.5 5] [3.5 5] [5 7] [3 4]), 1 ([1.5 2] [1 1])}

K-nearest neighbors

(ns example (:require [lambda-ml.neighborhood :refer :all]
                      [lambda-ml.distance :refer :all]))

(def data [[2 3] [5 4] [9 6] [4 7] [8 1] [7 2]])
(def knn (make-knn euclidean data))

(knn 3 [8 1])
;;=> [[0 [8 1]] [2 [7 2]] [18 [5 4]]]

Linear regression

(ns example (:require [lambda-ml.regression :refer :all]))

(def data [[-2 -1] [1 1] [3 2]])
(def model (make-linear-regression 0.01 0 5000))
(def fit (regression-fit model data))

(regression-predict fit (map #(take 1 %) data))
;;=> (-0.9473684210526243 0.8684210526315812 2.0789473684210513)

Logistic regression

(ns example (:require [lambda-ml.regression :refer :all]))

(def data [[0.50 0] [0.75 0] [1.00 0] [1.25 0] [1.50 0] [1.75 0] [1.75 1] [2.00 0] [2.25 1] [2.50 0] [2.75 1] [3.00 0] [3.25 1] [3.50 0] [4.00 1] [4.25 1] [4.50 1] [4.75 1] [5.00 1] [5.50 1]])
(def model (make-logistic-regression 0.1 0 10000))
(def fit (regression-fit model data))

(fit :parameters)
;;=> (-4.077712444728931 1.5046450944762417)

Naive Bayes

(ns example (:require [lambda-ml.naive-bayes :refer :all]))

(def x [[6.0 180 12] [5.92 190 11] [5.58 170 12] [5.92 165 10] [5.0 100 6] [5.5 150 8] [5.42 130 7] [5.75 150 9]])
(def y [:male :male :male :male :female :female :female :female])
(def model (naive-bayes-fit x y))

(naive-bayes-predict model [[6.0 130 8]])
;;=> (:female)

License

Copyright © 2015-2016

About

A small machine learning library written in Lisp (Clojure) aimed at providing simple, concise implementations of machine learning techniques and utilities.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Clojure 100.0%