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.2.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.2-cp312-cp312-win_amd64.whl (159.7 kB view details)

Uploaded CPython 3.12Windows x86-64

tlars-0.6.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (189.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

tlars-0.6.2-cp312-cp312-macosx_10_13_x86_64.whl (206.6 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

tlars-0.6.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (188.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

tlars-0.6.2-cp311-cp311-macosx_10_9_x86_64.whl (204.8 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

tlars-0.6.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (187.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

tlars-0.6.2-cp310-cp310-macosx_10_9_x86_64.whl (203.1 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

tlars-0.6.2-cp39-cp39-win_amd64.whl (158.4 kB view details)

Uploaded CPython 3.9Windows x86-64

tlars-0.6.2-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.2-cp39-cp39-macosx_11_0_arm64.whl (187.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

tlars-0.6.2-cp39-cp39-macosx_10_9_x86_64.whl (203.2 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

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

Uploaded CPython 3.8Windows x86-64

tlars-0.6.2-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.2-cp38-cp38-macosx_11_0_arm64.whl (186.7 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

tlars-0.6.2-cp38-cp38-macosx_10_9_x86_64.whl (202.7 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tlars-0.6.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f4413da91f543d994783a1113e4a508897af2fd55cb00139ab0e06ea35a967ac
MD5 443afe6b1b5325cd2bca86476eb35b6a
BLAKE2b-256 c8a45cc50f465e2d15b472055bc8dcb1128b2ae4e02f63dc4d5ea1b1bc92389f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5ccf3b890c9b789b6190baebfd23661a9fbb1ad26cbab345efe33adabf23d51d
MD5 98908318c47f7bcc28073155c0d616af
BLAKE2b-256 a7fd02bfa39eed70b74ce1b490d73c7faf1689ca3fc3b58500265afbf8847958

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a61ba6321262dc81acb3cbfdfdf9b3dc589553db877d1ee7cb0846c1b1d32021
MD5 e85eba9d15eb658e51ef43a21cad05a3
BLAKE2b-256 6fef263eae0c31174f7670bae1a21bc03ca5a8d29a1ad8bad5581be991fb0629

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b5894307713ebfe135ede0e6cdb5fbdb43b8727a015d4bf418f47b3fdad1e38
MD5 5d50bb329a5e0e889171bde0ebaf4b97
BLAKE2b-256 7c43d0442c38ca839939bde0f50b2341726d37aed8a710f1df14352b8f09ea7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 429ecd1b7ae15324bd78bd2a98de1562efcb3620722118aab6ce96532d93445f
MD5 6548696bfa3ac3013f31c57933409749
BLAKE2b-256 a4dde47e8a1562ff61a0a4d4ace50ac6adcc286b8c8a20ae6283a60a7a036418

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 666a8e2167f3eb93870c758e9a7796a43e34de5355162dace269d8e4c6564c36
MD5 e79ded9641bc5e2415c1e3c8b167b104
BLAKE2b-256 9c4fbdf28ea64e3222c96bebd6ed69c4380a001d795b9fd2b53abdcec80f9c65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb73b8dce7ef4b74d6cf7d92d1e094d0770a7f989f5bcbeaae18581c0d9bfaec
MD5 9c0e920304603a3a514cbd0ea0987e63
BLAKE2b-256 a3c41d80678428f204e76cfff7372c2b07297333191109bcc37e537bd349b4e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e448b135c75284e19decf103c33f5778ad698ead62c1cc102c3e5ea21738895c
MD5 b0bca15856d43bc34ffa145e9be0f52e
BLAKE2b-256 a4b13d5f999a81cb0160ff3f723044413f050348418b3846fbce5552ef917841

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d37cf65e1f415c95994f47a051349adebb8d4de7a0a09a4b19b657bc51788dd8
MD5 8ba22c80d05112000bdaba8ae2eda929
BLAKE2b-256 0b80719f9d482cb172a5546fd48f4c7dc65f6e0548f57a17134179e9f05780fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2b02b8b6dd0cd3a0e943892b082a9c843411d8225da00799d7919354cc43a24e
MD5 ef10486b34884791363b46e9883b65fd
BLAKE2b-256 01b42057652a82c7c6e737c7efcf2f656a38a934cd68174c362c0ca794fdae19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 581280c6a23084fd9db750332964d33b9f3780a6cc27d19568817ce93706caa6
MD5 ad4990d47c4c0926ad7fdbcad0e5f3cf
BLAKE2b-256 60e3e9ad84356cc77dcb1f531e985061960447d5cab84873e2803c5a035cfcc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d43293751253e638d6b277f3f2b57032841c61afe0622c2aab656dad2444edb
MD5 e3934272cf046e77157c76af6217c9e0
BLAKE2b-256 139517830f6cc9f61b024b4d523842dc63ca2af44ce573c16eae2f36d58b4745

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a95b7e52fd9f7afd216e2dac3b421b7c8bbde36061fcf67f43c62d7a28914868
MD5 cec81bfc9dd28958db3bde77c9ff2949
BLAKE2b-256 639fffa3e517c9458f1ffe9c5d96ee41fa510aeb081c10bd5e917a41cb251d58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 158.4 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.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4d3b3b531b69682f8cdeac642ea1cedaa339b7d9da0442396722b98906c47f8a
MD5 f2c24aff07f5ff544d9302a3274e5ade
BLAKE2b-256 be188afe9f935d7c68411a30b99eead7a08741aa33e664e287c2f4c81e7a3d6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19ee9829cc6e0e1b8aff907311747d6418bd439477a4d5632b60588110814271
MD5 44d16c7b06d589b3a94d4878f3253317
BLAKE2b-256 19e0ace5e1218163a27ae3298a861bb400464a8eae62a33c6a234d9a479580e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 187.1 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.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e2eecf21b8d0b184af645419390de3e092a52c1d75a1df2ee9b3f18e8c5e8c50
MD5 89cda3668497ff40c46ac73791d98942
BLAKE2b-256 ad3bd715fe6e237436251b2ea3abde15c57d9aea444bc89a189dfc3d313c7d71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fca30ebda7ff85bbe5d2dc28d2c052aac8de85ad50111b5119056cc324e60f43
MD5 2228c245ea33955cd1b74487ea36c5b5
BLAKE2b-256 a87c52f77a55ae1945c73c5775f4385c704b5c03464ca90973c095c608f19d56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-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.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e470ea87d0687301412ee7609f189b2bde04bc8cd5c0a8f14dea761604956c68
MD5 53235a6ce477241a1e73672579a52b19
BLAKE2b-256 9408115ae770b289c56a79d0098d283fcf251af4b7e67f77657c3b0e3ad4a6c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5acd3f0db0bf11426542b7b3adff67e8bf2ae662434ffd012e4842eb6c1ab6fd
MD5 4bd514a9015e33569190cdbf01ecb18d
BLAKE2b-256 6c353140c316739d1a8da302884c1ebbb50b9c316d8205a4f8a123f4f299a44a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.2-cp38-cp38-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 186.7 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.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91ea0188f67cd54b1d780ea900d044027de8a2ea36341f92814f6803d278ad57
MD5 85d575dc528613a8e0eda4af2ec71c39
BLAKE2b-256 a1b3c1b5fe6525a13463aa8c3404626261d5cee5a378b9d2092788d9debd52f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 68b9bb7e3198858512f82efa2e14f89107c50c0f8887a93720e33c34f297cebc
MD5 efd8ca2fc3f569b8bc3ded925c34bb56
BLAKE2b-256 d512ad836f1803afe5911b1bfc778e2accc069338298c8cf35a04852525f1b7e

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