Skip to main content

Python port of the tlars R package for Terminating-LARS (T-LARS) algorithm

Project description

tlars-python

A Python port of the tlars R package for Terminating-LARS (T-LARS) algorithm.

Overview

The Terminating-LARS (T-LARS) algorithm is a modification of the Least Angle Regression (LARS) algorithm that allows for early termination of the forward selection process. This is particularly useful for high-dimensional data where the number of predictors is much larger than the number of observations.

This Python package provides a port of the original R implementation by Jasin Machkour, maintaining the same functionality while providing a more Pythonic interface. The Python port was created by Arnau Vilella (avp@connect.ust.hk).

Installation

The package is available on PyPI for Windows, macOS, and Linux:

pip install tlars

This is the recommended installation method as it will automatically install pre-built wheels for your platform with all required dependencies.

Usage

import numpy as np
from tlars import TLARS, generate_gaussian_data

# Generate some example data using the built-in function
n, p = 100, 20
X, y, beta = generate_gaussian_data(n=n, p=p, seed=42)

# Alternatively, create your own data
X = np.random.randn(n, p)
beta = np.zeros(p)
beta[:5] = np.array([1.5, 0.8, 2.0, -1.0, 1.2])
y = X @ beta + 0.5 * np.random.randn(n)

# Create dummy variables
num_dummies = p
dummies = np.random.randn(n, num_dummies)
XD = np.hstack([X, dummies])

# Create and fit the model
model = TLARS(XD, y, num_dummies=num_dummies)
model.fit(T_stop=3, early_stop=True)

# Get the coefficients
print(model.coef_)

# Get other properties
print(f"Number of active predictors: {model.n_active_}")
print(f"Number of active dummies: {model.n_active_dummies_}")
print(f"R² values: {model.r2_}")

# Plot the solution path
model.plot(include_dummies=True, show_actions=True)

Library Reference

TLARS Class

Constructor

TLARS(X=None, y=None, verbose=False, intercept=True, standardize=True, 
      num_dummies=0, type='lar', lars_state=None, info=True)
  • X: numpy.ndarray - Real valued predictor matrix.
  • y: numpy.ndarray - Response vector.
  • verbose: bool - If True, progress in computations is shown.
  • intercept: bool - If True, an intercept is included.
  • standardize: bool - If True, the predictors are standardized and the response is centered.
  • num_dummies: int - Number of dummies that are appended to the predictor matrix.
  • type: str - Type of used algorithm (currently possible choices: 'lar' or 'lasso').
  • lars_state: object - Previously saved TLARS state to resume from.
  • info: bool - If True, information about the initialization is printed.

Methods

  • fit(T_stop=None, early_stop=True, info=True): Fit the TLARS model.

    • T_stop: int - Number of included dummies after which the random experiments are stopped.
    • early_stop: bool - If True, then the forward selection process is stopped after T_stop dummies have been included.
    • info: bool - If True, informational messages are displayed during fitting.
  • plot(xlabel="# Included dummies", ylabel="Coefficients", include_dummies=True, show_actions=True, col_selected="black", col_dummies="red", ls_selected="-", ls_dummies="--", legend_pos="best", figsize=(10, 6)): Plot the T-LARS solution path.

    • xlabel: str - Label for the x-axis.
    • ylabel: str - Label for the y-axis.
    • include_dummies: bool - If True, solution paths of dummies are added to the plot.
    • show_actions: bool - If True, marks for added variables are shown above the plot.
    • col_selected: str - Color of lines corresponding to selected variables.
    • col_dummies: str - Color of lines corresponding to dummy variables.
    • ls_selected: str - Line style for selected variables.
    • ls_dummies: str - Line style for dummy variables.
    • legend_pos: str - Position of the legend.
    • figsize: tuple - Figure size.
  • get_all(): Returns a dictionary with all the results and properties.

Properties

  • coef_: numpy.ndarray - The coefficients of the model.
  • coef_path_: list - A list of coefficient vectors at each step.
  • n_active_: int - The number of active predictors.
  • n_active_dummies_: int - The number of active dummy variables.
  • n_dummies_: int - The total number of dummy variables.
  • actions_: list - The indices of added/removed variables along the solution path.
  • df_: list - The degrees of freedom at each step.
  • r2_: list - The R² statistic at each step.
  • rss_: list - The residual sum of squares at each step.
  • cp_: numpy.ndarray - The Cp-statistic at each step.
  • lambda_: numpy.ndarray - The lambda-values (penalty parameters) at each step.
  • entry_: list - The first entry/selection steps of the predictors.

Helper Functions

  • generate_gaussian_data(n=50, p=100, seed=789): Generate synthetic Gaussian data for testing.
    • n: int - Number of observations.
    • p: int - Number of variables.
    • seed: int - Random seed for reproducibility.
    • Returns: tuple - (X, y, beta) where X is the design matrix, y is the response, and beta is the true coefficient vector.

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

Acknowledgments

The original R package tlars was created by Jasin Machkour. This Python port was developed by Arnau Vilella (avp@connect.ust.hk).

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

tlars-0.6.1.tar.gz (256.0 kB view details)

Uploaded Source

Built Distributions

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

tlars-0.6.1-cp312-cp312-win_amd64.whl (159.7 kB view details)

Uploaded CPython 3.12Windows x86-64

tlars-0.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

tlars-0.6.1-cp312-cp312-macosx_11_0_arm64.whl (188.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

tlars-0.6.1-cp312-cp312-macosx_10_13_x86_64.whl (206.1 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

tlars-0.6.1-cp311-cp311-win_amd64.whl (159.2 kB view details)

Uploaded CPython 3.11Windows x86-64

tlars-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

tlars-0.6.1-cp311-cp311-macosx_11_0_arm64.whl (187.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

tlars-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl (204.5 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

tlars-0.6.1-cp310-cp310-win_amd64.whl (158.1 kB view details)

Uploaded CPython 3.10Windows x86-64

tlars-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

tlars-0.6.1-cp310-cp310-macosx_11_0_arm64.whl (186.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

tlars-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl (202.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

tlars-0.6.1-cp39-cp39-win_amd64.whl (158.3 kB view details)

Uploaded CPython 3.9Windows x86-64

tlars-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

tlars-0.6.1-cp39-cp39-macosx_11_0_arm64.whl (186.8 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

tlars-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl (202.9 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

tlars-0.6.1-cp38-cp38-win_amd64.whl (158.0 kB view details)

Uploaded CPython 3.8Windows x86-64

tlars-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

tlars-0.6.1-cp38-cp38-macosx_11_0_arm64.whl (186.4 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

tlars-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl (202.4 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

Details for the file tlars-0.6.1.tar.gz.

File metadata

  • Download URL: tlars-0.6.1.tar.gz
  • Upload date:
  • Size: 256.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1.tar.gz
Algorithm Hash digest
SHA256 47d60f5a4e0d8156891583a55aef564d21e6b117ca6420f3291c398e952977e8
MD5 21ee9de861a545038b2cb4bdfad95838
BLAKE2b-256 d03a2cc8f5f36dfbdcad9d7068f6cb2f6c158f88f5fd012dcb729975cfdda793

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 159.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3dbadc09963d1bb9b7b1394458575023910154d8c5a5608640e6e8ca31911449
MD5 e4332d7e4fef4cfcc4935c7a5c5e581c
BLAKE2b-256 1a45585d769fcd7366745c9f4c9a48629404b7efe4bf4d002af306e66696b293

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a566d72d04f82927062a5d38c247eedc4ee22f861f26aa1d02f32cc14838d864
MD5 5bcbae49df53d803e95c57cb7eab90f8
BLAKE2b-256 1cbd4fb5168eaed8671ae3c556807891a3b1344c9f9a938ea8321fd432440b3b

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a604a6f6492163e4e1df01f8bcfcd15f9e210caa671cc1d94856a6065f8ab60
MD5 0a79f9c32ff1b7671749306c7d602b58
BLAKE2b-256 6591b1b71e8072cd2e0843228738cf465dfd9f3d659bce978e883b48e190bf25

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d14c8ac1c60af33f663fe536e746192fc43d69b08358a30bc36bfecd7b4e7cba
MD5 aa357060d7ee0ac59d5294d9043557e7
BLAKE2b-256 007b3a8fb0670e9fe0ef911847029bee6938c23a3612a883475451385ed2a190

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 159.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a1493df3007674bb7de3c6943c938b86e86e84c94ec124217bbc2196dac3e177
MD5 ed6f4ac3efa18baed2e67596b12eddfd
BLAKE2b-256 4c29da2dc4c7f4a055ab13632447ea8bbe56550bb35012fdcfcf4778c2b16f45

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d6432beb6833764be7e8b0df434b8ef16138f2fa23be173033d2e26ff95f474
MD5 b749d7427382e136879b791d9e991763
BLAKE2b-256 bce6f9a24628c0a8da76b03c1686338f45331014d320508af46afd5ac009d65a

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83b7fcc2a005e8601f6287e73189718ce4c7466ed2d0c550b4c7301fe03c72a5
MD5 d76a15ea8ceb67508ecdb309bbe59fe9
BLAKE2b-256 6290fd8bd7f45f8f06e8e0dec6894f239f56dfe17451e5bfe41d4515dd6b8cf0

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e22612fdfb976c86484e3ea0d499694ada9197b6d0f6e935a24c20451aaade31
MD5 92d84a15b1321b7e4b099d26f384fa28
BLAKE2b-256 df052f07314217d68f2c9ea30030e76c177f2976dbd0a25a4e7d39a210eda2b7

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 158.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 89bc068d6b2d1ae92fe03d21a21b252330434057c6dc59f88cc6ed49eaf17fbb
MD5 cb3dc9c86d87a5c1b7b627135165de1d
BLAKE2b-256 48cbb599abc70feefb8a2715dacf4366a5f6dc0bbe27fbcacb9447e85d2e373c

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 caeb08e8637383e9c3c905ce5e6005c803154a8079911aff12be92856a4c0a85
MD5 8be84d8710ac3594e398f5ec7d10e373
BLAKE2b-256 23aafdc7805862a97509161e47b579bd565244f4b977b7a8bc702f182e39a44d

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c88f6470bbfc28b9e3f52acf4ef4ca86553e1e9e3982bd9b3afb432c5a4f3a9
MD5 90f5b72e82736294f51a5792f6423f25
BLAKE2b-256 fd9bb17bd5755e6ca0367bd19bb169152cca1b7abe4305c4fef3c79ce3ffad45

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f9c8563d02e350679b5c834335784493e4c320b407f582e81c59b017d42d9d6b
MD5 e94e0c5ccc4d6b4aae41fd5493d0d57a
BLAKE2b-256 2c8ba3b3672370fe8186554681a49f7d52c398ce707e27bedfaac26c9d2e1f7c

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 158.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 46e31b3930342e6eb047f95c470ec4539eba34cd353ccefc1be865605137a53b
MD5 bc2230f01952fe354444cc0933c33f28
BLAKE2b-256 c4c8b2e60d2cba5cde1cac3301ce7a3fb6309966e6ef7efa64540274002d347a

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1f1e517eb42a28acc6f89d7a2a9a06d9fb196bb3f7e9cef75304449f5d0d04e
MD5 713cf64a455736e1c1ad7f7de1a9a54e
BLAKE2b-256 1e5d257b8163a4dfe055d2cbea60316746f26b6eeb620a6e965f07557c042eb0

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 186.8 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a4fc6189374f8137796a1392024601aa57d8c3271490a737370e4d7fed54879
MD5 aa79692ebc9306ff3064a896952597aa
BLAKE2b-256 5d63bdf697a985da817dd556c2c2541670e5aa82be4899f248236da8c40b5126

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ca17ef8740c6406bc3e0bf282c4cec37c5e0f0d2b57e9d112a5e5f6a4d43f8e3
MD5 0e15c968703b6222f304b50af8f2bcb2
BLAKE2b-256 3a47cb6710ae1d7e44bd80fdc9e2c2e0b17a88e8dc4e2811f242058de1f4fc6c

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 158.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3bd6946fe0900b2674422c2d4f30eabfdecf93fc7c15fca5e54104098e9e273f
MD5 82c9cf2f5400efd73342849b24d9ce06
BLAKE2b-256 12b832d0589065c548a979a4ff201ebde03a611d1ea0010a06c955f89d832251

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5cef8df2958ba7fb66ee58658af5b00e7dc040864d07bad6a4a51b67fc002c63
MD5 1395a543e5a02071112cbaf0d1acaa22
BLAKE2b-256 d13c01e6a836339c541e463e619aa840301c905d59700b402bbfe3c7ad10cb52

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

  • Download URL: tlars-0.6.1-cp38-cp38-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 186.4 kB
  • Tags: CPython 3.8, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b8a390b59083c5a19a489735998596a277532813d49a5d55413ee41f0c5e45f
MD5 6ea16c8fca0f5724202a40a87c068aa6
BLAKE2b-256 ed6dae023251c4408105407fc05a2ddd93bf039c5a7cbb24364e364896cbbc2f

See more details on using hashes here.

File details

Details for the file tlars-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ddac669817dcad917d45a5af295ff43b8ccafcba9375920beda0e6d28f84bfcc
MD5 53f1c1058c1322a8aafef8946e315c7e
BLAKE2b-256 5ab9dfd5eff66a156f43a6996c280c40577f8538800f9e48f816c6739578767b

See more details on using hashes here.

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