Skip to main content

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))
FastLrResult(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.051200235)
# Alternatively, use the pure Python implementation
print(py_res_simple := fastlr(X, y, method="python"))
FastLrResult(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.002805208001518622)
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.00205007

$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
uv sync
pip install .

or from pypi

pip install fastlr

R

git clone https://github.com/jsr-p/fastlr
cd fastlr
Rscript -e 'devtools::install_local(".")'

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

against:

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


Download files

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

Source Distribution

fastlr-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastlr-0.1.0-cp313-cp313-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.13Windows x86-64

fastlr-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (43.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastlr-0.1.0-cp313-cp313-macosx_14_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

fastlr-0.1.0-cp312-cp312-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.12Windows x86-64

fastlr-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (43.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastlr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

fastlr-0.1.0-cp311-cp311-win_amd64.whl (7.6 MB view details)

Uploaded CPython 3.11Windows x86-64

fastlr-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (43.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastlr-0.1.0-cp311-cp311-macosx_14_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file fastlr-0.1.0.tar.gz.

File metadata

  • Download URL: fastlr-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastlr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b95464c797946131eea68d9e22c70b1d849e7d3ac391fdb3d4daf1889d84327e
MD5 8df466c83c296e66bb8d929d89c0c367
BLAKE2b-256 0ea6ee6522c4ed888789b68dbd3760a4c9078ede63d84c58fe6c21f9565aed88

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0.tar.gz:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fastlr-0.1.0-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

Hashes for fastlr-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d3e2253254f85f563f50c84256d9595a9fbf32f18fe77c3b605eb9153d64007c
MD5 dfaeca3b8945c350f7b4b6f4e0a8ffb4
BLAKE2b-256 4888fce5a9b0832f51bbd5d12a28dca6abb6fa3ffe57674c29d3551acad1b42d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastlr-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 543a3bfe2a7c86fa52c6b0f031aafa7a98c4389984a1ecb2504e9c7e3d99b54c
MD5 5d62ac7901645ff9b8e22587417fb415
BLAKE2b-256 396c2c222cd6698b2b439fef14b55c0d5394401113fbe7bdae11692a96f8f2fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for fastlr-0.1.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b3fbddb2c08c09df281d1f4803b5a6ac2d0d75acce52429b0cb0296f3c9b338e
MD5 2d1f52943e3194d54703cee2a630ceab
BLAKE2b-256 78754ad7e0b0868c5a8ea573540f10f96bd5ec0db9134faefdbb08d8cd9f0ab5

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fastlr-0.1.0-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

Hashes for fastlr-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4a2cf8f0b836946453ef2283b00e427fd6fbbd7914ea547ccd6a80049e65a355
MD5 7aeb82a60ce856a32c87a747351f7e71
BLAKE2b-256 5b50d274b46186ddb8a87b17d32a6aeb872cedeb20ca5441d781765fda723707

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastlr-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef2b0dddaeaaac2e0d01f868abd008a256ef7910a0c63a905f3cdcd5dd343465
MD5 c542e506ab8cc0d08119ffe60de92cde
BLAKE2b-256 20368834a7805ee8c6c55834ec102189248a017d17a6324aab47c17f6609f292

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for fastlr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 90e93f42032ca9f28d5a9feeeacb1a41614b3a332c46954beab4d06489479af1
MD5 73d096f464d08d3bb078c007ffc6f09e
BLAKE2b-256 f398bcaab0bd93e0ac9cdffe3793f9c6db537ebf03ba7869f48ee18a7ef330ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fastlr-0.1.0-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

Hashes for fastlr-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c1d533763a010bfb6e6d39371ef4781d8ffaedadd1a3fae0989f53888f40c74a
MD5 200c88b1bd18e28d57f5869109ed218a
BLAKE2b-256 7dd324c2cb1706f63ddc143a953ab7ce68e65292d75db55e6a32eabcb5b75f81

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastlr-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cc81d9b20d9be29de1f73ccb77a0e9af74355bb6cb3e1c16899d2461a29f179e
MD5 3d7ddccf7305314b7e812de7d6fb4245
BLAKE2b-256 8c4b0f394d4d0064fc280aecf3600205adadba73b8d442972cdeeee1a7c0c010

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastlr-0.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for fastlr-0.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d9b8255082e7c676a5b93dba8d1eeffadba3570b8a67f15f39194567c07ba572
MD5 5dd8b26257c758d62af87233061ff19e
BLAKE2b-256 ef1b773ce9a8fec3f3fd5739288d5215f0503d2d259d3919137270bfc4463dbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastlr-0.1.0-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: build-wheels.yml on jsr-p/fastlr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page