Coder Social home page Coder Social logo

lynaghk / clj-liblinear Goto Github PK

View Code? Open in Web Editor NEW
28.0 7.0 9.0 208 KB

A Clojure wrapper for LIBLINEAR, a linear support vector machine library

Home Page: http://keminglabs.com/clj-liblinear/

License: Eclipse Public License 1.0

Clojure 100.00%

clj-liblinear's Introduction

                                     _ __  
                                    | '_ \ 
                                    | | | |
  /                             \   |_| |_| 
 /                               \        
 |      +             /          |        
 |       +     +     /           |      
 |                  /   -        |      ____  _   _         _  _  _      _  _                            
 |     +    +   +  /  -          |     / ___|| | (_)       | |(_)| |__  | |(_) _ __    ___   __ _  _ __  
 |                /        -     |    | |    | | | | _____ | || || '_ \ | || || '_ \  / _ \ / _` || '__| 
 |     +   +     / -   -         |    | |___ | | | ||_____|| || || |_) || || || | | ||  __/| (_| || |    
 |              /                |     \____||_|_/ |       |_||_||_.__/ |_||_||_| |_| \___| \__,_||_|    
 |    +        /   -    -        |             |__/                                                      
 |          + /      -           |    
 \           /   -               /    
  \                             /                                                           

This is a Clojure wrapper around Benedikt Waldvogel's Java port of LIBLINEAR, a linear classifier that can handle problems with millions of instances and features. Essentially, it is a support vector machine optimized for classes that can be separated without projecting into some fancy-pants kernel space.

Deprecation notice

I wrote this library nearly 4 years ago, before I really understood Clojure. I'm not taking issues / pull requests against this library, since it needs a full redesign. Leaving it online just so you can see some examples of Clojure interop with a Java library. If the current API or performance is not what you need, your best bet is to just dig around and copy/paste what you need into your specific application.

cheers,

Kevin

Install

Add

[clj-liblinear "0.1.0"]

to the :dependencies vector in your projects.clj file.

Examples

Clj-liblinear takes maps as instances:

(use '[clj-liblinear.core :only [train predict]])
(let [train-data (concat
                  (repeatedly 300 #(hash-map :class 0 :f {:x (rand), :y (rand)}))
                  (repeatedly 300 #(hash-map :class 1 :f {:x (- (rand)), :y (- (rand))})))
      model (train
             (map :f train-data)
             (map :class train-data)
             :algorithm :l2l2)]
  
  [(predict model {:x (rand) :y (rand)})
   (predict model {:x (- (rand)) :y (- (rand))})])
;;=> [0 1]

If you are concerned only with occurrences (rather than continuous variables), you can use sets. These will be expanded into indicator variables for classification. For instance, you can easily do simple text classification based on word occurrence:

(use '[clj-liblinear.core :only [train predict]]
     '[clojure.string :only [split lower-case]])

(def facetweets [{:class 0 :text "grr i am so angry at my iphone"}
                 {:class 0 :text "this new movie is terrible"}
                 {:class 0 :text "disappointed that my maximum attention span is 10 seconds"}
                 {:class 0 :text "damn the weather sucks"}

                 {:class 1 :text "sitting in the park in the sun is awesome"}
                 {:class 1 :text "eating a burrito life is super good"}
                 {:class 1 :text "i love weather like this"}
                 {:class 1 :text "great new album from my favorite band"}])

(let [bags-of-words (map #(-> % :text (split #" ") set) facetweets)
      model         (train bags-of-words (map :class facetweets))]
  
  (map #(predict model (into #{} (split % #" ")))
       ["damn it all to hell!"
        "i love everyone"
        "my iphone is super awesome"
        "the weather is terrible this sucks"]))

;; => (0 1 1 0)

Thanks

The National Taiwan University Machine Learning Group for LIBLINEAR, and Benedikt Waldvogel his Java transliteration.

This project is sponsored by Keming Labs, a technical design studio specializing in data visualization.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.