bald mathematicians; and an analytics guy • Clojure (Ruby, Python, Node.js, R, C#, whatever works best or is needed) • Predictive Analytics (Automated Decisions, Machine Learning, Visualizations & Intelligence) • Math Mornings (Stochastic Calculus For Finance; Friends of Red Brain Labs)
a row `a` from the matrix `M` to the row `b` returning the updated matrix. Assumes that `a` is the values of the row, and `b` is the index of the row to be operated on." [M a b] (assoc M b (vec (map (fn [a_i b_i] (+ a_i b_i)) a (M b)))))
[M pivot] (let [m (count M)] (reduce (fn [M i] (let [scaler-‐factor (scale-‐factor M i pivot) scaled-‐row (scaler-‐multiply M scaler-‐factor pivot)] (add-‐row-‐to-‐row M scaled-‐row i))) M (range (inc pivot) m)))) (defn row-‐echelon-‐form "Computes the row-‐echelon form of a matrix, `A`, using gaussian elimination." [A] (let [m (count A)] (reduce (fn [A pivot] (let [B (partial-‐pivot A pivot)] (eliminate B pivot))) A (range 0 m))))
2 vectors. The higher the result, the more different the vectors." (/ (count (filter #(= false %) (map = v1 v2))) (count v1))) (defn count-‐occurences [v] "Counts occurences in a vector" (partition 2 (interleave (set v) (map #(count (filter #{%} v)) (set v))))) (defn majority-‐vote [v] "Calculates which item appears most often in a vector. CAUTION: in case two items appear equally often, will pick at random" (first (last (sort-‐by second (count-‐occurences v))))) (defn classify [sample training-‐set k] (let [distances (pmap #(calculate-‐distance (:pattern %) sample) training-‐set) labels (map :label training-‐set) distances-‐with-‐labels (map first (take k (sort-‐by second (partition 2 (interleave labels distances)))))] (majority-‐vote distances-‐with-‐labels))) https://github.com/jandot/machine-learning-in-action/blob/master/knn.clj