Fast logistic regression
Project description
fastlr: fast(er) logistic regression
This package aims to estimate a logistic regression model in a fast(er)
way using the iteratively reweighted least squares (IRLS) algorithm.
This is implemented using the C++ library
armadillo. The package provides
R-bindings through
Rcpp in the
R package fastlr and Python-bindings through
pybind11 in the
Python package fastlr; the Python package also provides a pure Python
implementation of the IRLS algorithm.
Usage
Python
from fastlr import fastlr, generate_data
X, y = generate_data(N=10_000, k=10, seed=0)
print(py_res := fastlr(X, y))
IRLSResult(coefficients=array([-0.19547786, 0.26833757, -0.1303476 , -0.03979692, -0.15035753,
-0.26321948, 0.33105813, -0.19471808, 0.12025924, 0.11202108]), iterations=4, converged=True, time=0.022075296)
# Alternatively, use the pure Python implementation
print(py_res_simple := fastlr(X, y, method="python"))
IRLSResult(coefficients=array([-0.19547786, 0.26833757, -0.1303476 , -0.03979692, -0.15035753,
-0.26321948, 0.33105813, -0.19471808, 0.12025924, 0.11202108]), iterations=4, converged=True, time=0.002509422993171029)
import numpy as np
np.allclose(py_res.coefficients, py_res_simple.coefficients)
True
R
library(fastlr)
library(reticulate)
m <- fastlr(py$X, py$y) # py from reticulate; reticulate nice
print(m)
$coefficients
[1] -0.19547786 0.26833757 -0.13034760 -0.03979692 -0.15035753 -0.26321948
[7] 0.33105813 -0.19471808 0.12025924 0.11202108
$iterations
[1] 4
$time
[1] 0.001886126
$converged
[1] TRUE
Thanks reticulate!
py_estimates <- py$py_res$coefficients |> as.numeric()
r_estimates <- m$coefficients
print(py_estimates)
[1] -0.19547786 0.26833757 -0.13034760 -0.03979692 -0.15035753 -0.26321948
[7] 0.33105813 -0.19471808 0.12025924 0.11202108
print(r_estimates)
[1] -0.19547786 0.26833757 -0.13034760 -0.03979692 -0.15035753 -0.26321948
[7] 0.33105813 -0.19471808 0.12025924 0.11202108
all.equal(py_estimates, r_estimates, tolerance = 1e-6)
[1] TRUE
Installation
Python
git clone https://github.com/jsr-p/fastlr
cd fastlr
pip install .
or from pypi
pip install fastlr
R
Benchmarks
To reproduce the benchmarks install the development versions of both packages and run:
just bench
Benchmark against fastglm
This benchmark shows the same results as shown in the fastglm
package
with the fastlr (Rcpp) implementation added to
the figure (run on my laptop).
See scripts/fastglm_bm.R and the Justfile.
For the sessionInfo() see here.
BTW:
grep 'Running under' output/sessioninfo.txt
Running under: Arch Linux
Benchmark against Python packages
A benchmark study of this package’s two implementations
- Python implementation of the
IRLSalgorithm - C++ implementation of the
IRLSalgorithm with Python bindings through pybind11
against:
- glum
- statsmodels logit
- minimal
newton-cgminimize implementation from scipy
for varying sample size $N$ and number of covariates $k$.
See the generate_data function
here.
Benchmark Python implementations
Interestingly, as seen from the figure, the pure Python implementation is quite fast and comparable to the C++ version!
Benchmark R implementations on same setup as above
Benchmark results as tables
- See here for the benchmark results as a table.
Development
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastlr-0.1.0.dev1.tar.gz.
File metadata
- Download URL: fastlr-0.1.0.dev1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c0a6c402998890e5d8a140cff8531eddcf69d462c6e293c51b153637dff25f2
|
|
| MD5 |
05e38bc423b6aa9f43445a0aedd8d380
|
|
| BLAKE2b-256 |
e019db94c29560aed2a06d0538889b5b6b4aeae942df50633224b3000305f542
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1.tar.gz:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1.tar.gz -
Subject digest:
8c0a6c402998890e5d8a140cff8531eddcf69d462c6e293c51b153637dff25f2 - Sigstore transparency entry: 356825777
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 7.6 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4994908c09a0b1c8cb11d08ce83511b41a5071da2101ac630b54b5024d4974b3
|
|
| MD5 |
451ee113ac4bd2c84563389ba6f49259
|
|
| BLAKE2b-256 |
39febf1d2e7da5ae2373e080935f0bfa345cbe90693248d440f0f8df76f50741
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp313-cp313-win_amd64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp313-cp313-win_amd64.whl -
Subject digest:
4994908c09a0b1c8cb11d08ce83511b41a5071da2101ac630b54b5024d4974b3 - Sigstore transparency entry: 356825817
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 43.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01d9b2fd1277b23131aa9668fc443f4658092598d51ea550f7b87dea1b7a60bb
|
|
| MD5 |
247ab5512ccad0c35309a260e839087a
|
|
| BLAKE2b-256 |
cdb99af7c6aa7e413b5d340bb14077c07486010d651838a6c949b684859216d0
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
01d9b2fd1277b23131aa9668fc443f4658092598d51ea550f7b87dea1b7a60bb - Sigstore transparency entry: 356825850
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp313-cp313-macosx_14_0_arm64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp313-cp313-macosx_14_0_arm64.whl
- Upload date:
- Size: 12.7 MB
- Tags: CPython 3.13, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd59110c02c069b02913306bb93833ae20b743d6086ac1661f261551c2a3f924
|
|
| MD5 |
8ca89d5643ff6258cdad025d542c5675
|
|
| BLAKE2b-256 |
7bdf78b4ea6577d3627911d34d66aedcbc0c3b1683e8cf8e9e7b4a66b60f0112
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp313-cp313-macosx_14_0_arm64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp313-cp313-macosx_14_0_arm64.whl -
Subject digest:
cd59110c02c069b02913306bb93833ae20b743d6086ac1661f261551c2a3f924 - Sigstore transparency entry: 356825825
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 7.6 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0aa935a6df58b76fadac426d0a10b1b8f216bcd9692145a9a5911f8f32f3aa7
|
|
| MD5 |
e1ed601c835ff4362370d12110605cc0
|
|
| BLAKE2b-256 |
eb758cc323396e6966152b92db5df64ed751df0e5e1916c447d8677f1588f17c
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp312-cp312-win_amd64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp312-cp312-win_amd64.whl -
Subject digest:
a0aa935a6df58b76fadac426d0a10b1b8f216bcd9692145a9a5911f8f32f3aa7 - Sigstore transparency entry: 356825839
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 43.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47812fcd1773447c446b44f6dd85d63c67ec36c3aaa4503b9844bbae0ea16ad2
|
|
| MD5 |
f4ca7ca90a3ce17753097e3213ff837d
|
|
| BLAKE2b-256 |
2926ff43ec0cf8ac67cdaf6150dab679ff44f1a674ac606741ebe63629a13c20
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
47812fcd1773447c446b44f6dd85d63c67ec36c3aaa4503b9844bbae0ea16ad2 - Sigstore transparency entry: 356825831
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 12.7 MB
- Tags: CPython 3.12, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c49f3e4d4c6b3b112f38156ca84519ec4b2542a0eef869b58b8979b197c76de
|
|
| MD5 |
42df75f99d6b2b406d12819a9924677e
|
|
| BLAKE2b-256 |
e594db30e45f9bb10fe1966be1c1c4ae17a723088b16c4d06139cf5577437a9c
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp312-cp312-macosx_14_0_arm64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp312-cp312-macosx_14_0_arm64.whl -
Subject digest:
3c49f3e4d4c6b3b112f38156ca84519ec4b2542a0eef869b58b8979b197c76de - Sigstore transparency entry: 356825860
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 7.6 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f79934ca765d8f9e7e602eefd6b44fd57ec673c17930d0d2219a1611e132c04a
|
|
| MD5 |
500c56fe9277e816237cfcce6cdafe57
|
|
| BLAKE2b-256 |
ce6ac2f1a7bc090c1133165019955e1e157052da62e9f99d34d997d8111a73ea
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp311-cp311-win_amd64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp311-cp311-win_amd64.whl -
Subject digest:
f79934ca765d8f9e7e602eefd6b44fd57ec673c17930d0d2219a1611e132c04a - Sigstore transparency entry: 356825797
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 43.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5cbdc42bf76c8398d837368f5c29d062283dd41fc3eba7aab5f378fe38d49a8
|
|
| MD5 |
2422d8ad4e021aff7c887e1d2d9b20a7
|
|
| BLAKE2b-256 |
032ee8987fd5b1478d8100a29b0111db10ab698c749142681cfd0affab635acf
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
e5cbdc42bf76c8398d837368f5c29d062283dd41fc3eba7aab5f378fe38d49a8 - Sigstore transparency entry: 356825805
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlr-0.1.0.dev1-cp311-cp311-macosx_14_0_arm64.whl.
File metadata
- Download URL: fastlr-0.1.0.dev1-cp311-cp311-macosx_14_0_arm64.whl
- Upload date:
- Size: 12.7 MB
- Tags: CPython 3.11, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
273e5b19670ad947d3cf0c8d35284a9896b0c2cf0c2b0ba093bebc54a3fc035f
|
|
| MD5 |
500b66d2b843bc6b24720f9f69f1e30e
|
|
| BLAKE2b-256 |
48ac25e0fdd38d89ab90d308216b7653673aaa37ab6e8b8bc80700cddb26e918
|
Provenance
The following attestation bundles were made for fastlr-0.1.0.dev1-cp311-cp311-macosx_14_0_arm64.whl:
Publisher:
build-wheels.yml on jsr-p/fastlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlr-0.1.0.dev1-cp311-cp311-macosx_14_0_arm64.whl -
Subject digest:
273e5b19670ad947d3cf0c8d35284a9896b0c2cf0c2b0ba093bebc54a3fc035f - Sigstore transparency entry: 356825788
- Sigstore integration time:
-
Permalink:
jsr-p/fastlr@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Branch / Tag:
refs/tags/v0.1.0.dev1 - Owner: https://github.com/jsr-p
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@0f650201c585605a3dc9a4a340ac21c4a3c55c97 -
Trigger Event:
push
-
Statement type: