Code Monkey home page Code Monkey logo

lrb's Introduction

Logistic Regression with bounded coefficients

This repo implements a projected coordinate-descent Newton (CDN) solver for L1-regularized logistic regression in Cython.

The basic CDN algorithm is presented in Yuan et al (2010) and Yuan et al (2012). The only modification here is to add projection to allow for imposing bounds on the model coefficients, such as constraining them to be positive.

The API closely resembles the scikit-learn implementation of Logistic Regression, which calls liblinear, which in turn uses newGLMNET (Yuan et al, 2012). This cython implementation of CDN is perhaps 10 times slower than scikit-learn's call to liblinear, but it allows for placing constraints on the weights, which was an option in the original GLMNET package, but not in liblinear or scikit-learn.

Requirements

  • python3
  • numpy
  • scipy
  • cython

Installation

To use this code, first compile it with cython by using

> python setup.py build_ext --inplace

You can then run a test using test_lrb.py (add --both to compare to the scikit-learn results or -h to see more options).

Usage

To embed in python code, the API is essentially the same as scikit-learn, e.g.

import lrb
model = lrb.LogisticRegressionBounded()
model.fit(X, y)
predictions = model.predict(X)

To add bounds on the weights, use the lower or upper keywords, e.g.

model = lrb.LogisticRegression(lower=0)

Limitations

This implementation currently only supports binary classification (not multi-class), and X must be passed as a scipy.sparse matrix (not dense). Also, only L1 regularization is implemented (not L2).

Note that at the moment, the intercept is being regularized (as is the case in liblinear and scikit-learn). I may change this in the future...

To do

  • handle dense data
  • remove bounds restriction on intercept
  • replace convergence test with something better

References

lrb's People

Contributors

habush avatar

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.