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.3.tar.gz (255.4 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.3-cp312-cp312-win_amd64.whl (159.6 kB view details)

Uploaded CPython 3.12Windows x86-64

tlars-0.6.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

tlars-0.6.3-cp312-cp312-macosx_14_0_x86_64.whl (200.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

tlars-0.6.3-cp312-cp312-macosx_14_0_arm64.whl (11.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

tlars-0.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

tlars-0.6.3-cp311-cp311-macosx_14_0_x86_64.whl (199.1 kB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

tlars-0.6.3-cp311-cp311-macosx_14_0_arm64.whl (11.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

tlars-0.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

tlars-0.6.3-cp310-cp310-macosx_14_0_x86_64.whl (197.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ x86-64

tlars-0.6.3-cp310-cp310-macosx_14_0_arm64.whl (11.7 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

tlars-0.6.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

tlars-0.6.3-cp39-cp39-macosx_14_0_x86_64.whl (197.7 kB view details)

Uploaded CPython 3.9macOS 14.0+ x86-64

tlars-0.6.3-cp39-cp39-macosx_14_0_arm64.whl (11.7 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

tlars-0.6.3-cp38-cp38-win_amd64.whl (158.1 kB view details)

Uploaded CPython 3.8Windows x86-64

tlars-0.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

tlars-0.6.3-cp38-cp38-macosx_14_0_x86_64.whl (197.2 kB view details)

Uploaded CPython 3.8macOS 14.0+ x86-64

tlars-0.6.3-cp38-cp38-macosx_14_0_arm64.whl (11.7 MB view details)

Uploaded CPython 3.8macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: tlars-0.6.3.tar.gz
  • Upload date:
  • Size: 255.4 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.3.tar.gz
Algorithm Hash digest
SHA256 9fed49493ae46e701ec8ed642d8d618a19114da19bfa2aecfb445d56c019a14c
MD5 2b4d082bc4e229004484f88719da412b
BLAKE2b-256 a47d67d66b677ab0ea0a7347436e8c9c6cb0fcad0b95e7795beea7c4e560df4a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 159.6 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 de7c843905644c34e08f7b3578aaedfeca60b7705ee11cf4e8988c1dc4d60435
MD5 595e486fd5bc085e98905a184bc54dd9
BLAKE2b-256 37f31bff58ca6c29d1f7d89fc96ae34b2df4902ae72fb0096015b3d31c769824

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eedadf74e97ef5bf9abbf2969216408bc4d630b63a8ef15737fb41d4ff486c57
MD5 192d8a0c7df637df80f97990c0dea620
BLAKE2b-256 568d4359422190e2b0a597c9ce10fc15de2ebf0fa37ccc2ace692660a39e7fcd

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 9da125b8ed34e4f43f4b4e2255432a4682c439330db5d67463d98b9c5999007b
MD5 1c05deaf22356f8a1adcfd704def1ab2
BLAKE2b-256 26e00d2a5217111db1deaff9e37f808e89e392a2632a899b1545e389ab7237fb

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5abc4f0e7be5fe3685d00ef8425a4495d2530e9f66f3af572b65feb9b3f2caa6
MD5 f9f3600529c371ecfce167d2ab9835d1
BLAKE2b-256 8c8460c7b37bf7636507060476c441697054665eaba8b6e79e2de0d4c64211df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.3-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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 07f3fba41114170d137a60939340b3e1dae13e3d87a956300a43f6408b1797fe
MD5 59ff7f09d4f110fccc5d4d3e9320f26a
BLAKE2b-256 407f531e365008c6276265dc0e8a2ff1f8e53f08dd04b9e9cd230e93f07f1766

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 744a71b85c0ebfa2da7ca5a78d55eb991470c254d5dd2a79a63ee389120c7681
MD5 8830b18059622bcad3eff7047e66f380
BLAKE2b-256 83af144bf38ad24261225222e0771250727bec62c1b559d788aaf212fb3f078c

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 82a2a8ba7beac257e7eb20c35c49d2cffa9b19318768ce7cfda0016893a10c00
MD5 f1bf5753ddda3e2e6dc9534c31b55fe9
BLAKE2b-256 ca268a6e5fda6bb5e974e0a7963d72048fe0ed040fa018c3cede7ebd8fb3553f

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 49aabecff27588f3477011a638438c7e0de0f9749cbf4dfeb81f580bcb355918
MD5 05814d25709e2649513f2c8f48abe365
BLAKE2b-256 2c9b35d51a595d7e5cd7d5f85659d503f175dc1203668569cb714a6e99dd5146

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.3-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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ae77a42b8b666ab996cdbe0e15887c9a739af266658e5453cd5deaca95cddebe
MD5 57038cc526e6375186aeddb2f3ebb306
BLAKE2b-256 36c3f9374e1c6c23f69aefb276bf3d025e0290056ac14a8e4e5af2cf4c9cd365

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66f7c1ce14228b8f13bf68cc5c1859314b16a1505dbdab1d580ab04d2e92bdcb
MD5 1042bcf3844ba649b8b587e023c1ab3f
BLAKE2b-256 3f8815aa3f78fd754dcafcb39cc82fad31573e854a8420e6a7962e6559938c2d

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp310-cp310-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp310-cp310-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 3d4e37762cb6a7ae0e58aa06d9df85bdaf19b9cbe55ad99dba52e6ef04d5aea7
MD5 aab96b0aade6dc457ae1cad893f9fd54
BLAKE2b-256 c030c89096ef165f9fd441cbc55292c5f831e97af5181c71c8103693fb971dcb

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 421f6353a94f7b8c2686c0ed3ce96a7c722161c8b80888ab8b5f00276d1488df
MD5 eb0f8bbb443129641980a6f30b378b27
BLAKE2b-256 a94a6e36bad3fe1c44a2abe487a6cd83b2452e48b92f5bdc4f933be3af0465ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.3-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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0d609754321ba0bbc031ad818fbb1fbae2beddeb127f0d85fd1395378159af67
MD5 b3821480406f73e67c8c2b0307881f77
BLAKE2b-256 aecba73c689410ddadd1db4e7a9e9987fae2ffe66b03a4e254664d5e953de071

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f15a904b0e82a5283dabe4467a0f6934803a90fe6c53766dee006ff4ab8610bd
MD5 503c6f59e340896a7da2a3b5f3095eac
BLAKE2b-256 d1736b797a9311da913aa97a95bd40fb9e439c0c20d3f32c6d806897058a2636

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp39-cp39-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp39-cp39-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 6ba4db17473fd01a034c52843a0e7a0b947139ed7a787fb0afcabbcf217e4748
MD5 f60f7017cd022030efd9659b0a949b76
BLAKE2b-256 77e7a9504fb50958a88e67ef1ed790e29bba9850d15246ae0c4e1cf8e11130f7

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

  • Download URL: tlars-0.6.3-cp39-cp39-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 11.7 MB
  • Tags: CPython 3.9, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.3-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1e0d7c98062b320213c9aad68abf6f65cb787f12bf4a87fd8c3caec3f731255a
MD5 1c5b13a5a92806ebf10647c025289270
BLAKE2b-256 c16662da1c19a650d48a913c27c0f5303d1fd3b28a1a9b2059977638f066d929

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tlars-0.6.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 158.1 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.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 77fff5643d663b67eeb8e00952aab362032fe63f06dc1004a690edc86386c9a6
MD5 77da70b45f3608d4907c53b1ce8c7bcf
BLAKE2b-256 92c06b602dbb4c98ab4d105fa83d4cd2232c883e5fc84de4461f94c3be3e5405

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tlars-0.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b55c972154189c7d5f4f606f0dce30b834d05516de5f573ae43aaa7b982c9b9
MD5 14d9f57aa092452fd98ea178fbcf2d26
BLAKE2b-256 c6df8caac48d0b658b6fdde5da198fc6a1cd7fc4288973ebad74713582e69bec

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp38-cp38-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for tlars-0.6.3-cp38-cp38-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 e1e4ca39df28b50f621b37c681559c76f636c02800e07a0137ff67c48ff453ed
MD5 94cf7404858df3171eba27e1b0541d86
BLAKE2b-256 c9299b9ac073c97408f3c9af800dc407647805fe3808793692c13340d0506b77

See more details on using hashes here.

File details

Details for the file tlars-0.6.3-cp38-cp38-macosx_14_0_arm64.whl.

File metadata

  • Download URL: tlars-0.6.3-cp38-cp38-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 11.7 MB
  • Tags: CPython 3.8, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for tlars-0.6.3-cp38-cp38-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 75f77c36c8b951b604cc64cd66b04e3c714e290ba32ad341efad9cdb1f6704cc
MD5 54ea0db199d8dad88645c2ac97dec9e2
BLAKE2b-256 dbf76f836521cec600b63bf33c666d26571b959a69decece7a57ee8dc02ee045

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