Skip to main content

bess Python Package

Project description

bess: An python Package for Best Subset Selection

Introduction

One of the main tasks of statistical modeling is to exploit the association between a response variable and multiple predictors. Linear model (LM), as a simple parametric regression model, is often used to capture linear dependence between response and predictors. Generalized linear model (GLM) can be considered as the extensions of linear model, depending on the types of responses. Parameter estimation in these models can be computationally intensive when the number of predictors is large. Meanwhile, Occam's razor is widely accepted as a heuristic rule for statistical modeling, which balances goodness of fit and model complexity. This rule leads to a relative small subset of important predictors.

bess package provides solutions for best subset selection problem for sparse LM, and GLM models.

We consider a primal-dual active set (PDAS) approach to exactly solve the best subset selection problem for sparse LM and GLM models. The PDAS algorithm for linear least squares problems was first introduced by Ito and Kunisch (2013) and later discussed by Jiao, Jin, and Lu (2015) and Huang, Jiao, Liu, and Lu (2017). It utilizes an active set updating strategy and fits the sub-models through use of complementary primal and dual variables. We generalize the PDAS algorithm for general convex loss functions with the best subset constraint, and further extend it to support both sequential and golden section search strategies for optimal k determination.

Install

Python Version

  • python >= 3.5

Modules needed

  • numpy

The package has been publish in PyPI. You can easy install by:

$ pip install bess

Example

from bess.linear import PdasLm, PdasLogistic, PdasPoisson
import numpy as np
np.random.seed(12345)

### PdasLm sample
x = np.random.normal(0, 1, 100 * 150).reshape((100, 150))
beta = np.hstack((np.array([1, 1, -1, -1, -1]), np.zeros(145)))
noise = np.random.normal(0, 1, 100)
y = np.matmul(x, beta) + noise      # test_x
model = PdasLm(path_type = "seq", sequence = [5])
model.fit(X = x, y = y)
print(np.nonzero(model.beta))
print(model.beta[0:5])


### PdasLogistic sample
np.random.seed(12345)  
x = np.random.normal(0, 1, 100 * 150).reshape((100, 150))
beta = np.hstack((np.array([1, 1, -1, -1, -1]), np.zeros(145)))
xbeta = np.matmul(x, beta)
p = np.exp(xbeta)/(1+np.exp(xbeta))
y = np.random.binomial(1, p)
model = PdasLogistic(path_type="seq", sequence=[5])
model.fit(X=x, y=y)
print(np.nonzero(model.beta))
print(model.beta[0:5])


### PdasPoisson sample
np.random.seed(12345)
x = np.random.normal(0, 1, 100 * 150).reshape((100, 150))
beta = np.hstack((np.array([1, 1, -1, -1, -1]), np.zeros(145)))
lam = np.exp(np.matmul(x, beta))
y = np.random.poisson(lam=lam)
model = PdasPoisson(path_type="seq", sequence=[5])
model.fit(x, y)
print(np.nonzero(model.beta))

Reference

Bug report

Connect to @Jiang-Kangkang, or send an email to Jiang Kangkang(jiangkk3@mail2.sysu.edu.cn)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bess, version 0.0.8
Filename, size File type Python version Upload date Hashes
Filename, size bess-0.0.8-cp35-cp35m-win_amd64.whl (371.1 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size bess-0.0.8-cp36-cp36m-win_amd64.whl (371.1 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size bess-0.0.8-cp37-cp37m-win_amd64.whl (374.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size bess-0.0.8-cp38-cp38-win_amd64.whl (371.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size bess-0.0.8.tar.gz (926.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page