Skip to main content

Ridge and Lasso in Python for regression analysis, prediction and variables selection.

Project description

590038024-72dde7d8-86bd-41c8-9010-f585e939285a

Description

Frenezik is a Python package that enables the development of Ridge and Lasso regularized regression models. These models can be designed using two approaches. The first approach is known as the simulation approach because it allows for the generation of data from the population and/or sample under study. This approach is suitable for researchers and students whose goal is to gain a deep understanding of Ridge and Lasso models. The second approach uses existing data, that is, non-simulated data.

Application

This package provides:

Advanced regression analyses that include estimates of regression coefficients regularized using the LSQR optimization algorithm, significance tests for the coefficients and residual analysis using 3D visualizations for Ridge. Variable selection methods based on the notion of shrinkage of penalized coefficients as a function of the penalty parameter alpha. Predictions based on machine learning. We can therefore evaluate regularized models by splitting the data into training and test sets. Frenezik is an open-source project that uses and is compatible with the following stacks : NumPy, SciPy, Matplotlib, Seaborn, Pandas, Scikit-Learn, and Statsmodels.

Tutorial

Installation frenezik

pip install frenezik

Import frenezik

import frenezik as fk

Simulation and visualization Residuals

# Population size
PopulationSize = 500

# Random seed
RandomSeed = 1980

# Instance of <<Residuals>> class
Resid = fk.Residuals(population_size=PopulationSize, random_seed=RandomSeed)

# Parameter of Mean
LawMean = 2.81

# Parameter of Variance
LawVar = 3.89

# Simulation of residuals
Residus = Resid.Simulation(law="normal", law_parameters=[LawMean, LawVar])

# Histogram of residuals simulated
Resid.Visualization(residuals_simulated=Residus, figure='histogram')
590086839-0a5591fe-8b61-4449-bdc0-5e5e538cc29d

Generation X and y data

# True coefficients 
TrueCoefficients = np.arange(-20, 20, 4.5)

# Generation of X and y data with simulated residuals
TarPred = fk.TargetPredictors(population_size=PopulationSize, true_coefficients=TrueCoefficients)
data_population = TarPred.Simulation(residuals_simulated=Residus)
data_population.head(5)
590087986-c5b513f4-2aeb-4b87-8f8e-df16fd3b8059
# Lineplot of generated X and y data
plt.figure(figsize=(8,6))
TarPred.Visualization_X_y(data_simulated=data_population, figure='lineplot')
590087620-a998f557-c213-46fd-9651-b33641e11692

Ridge Regression with ($\alpha = 5$)

# penality factor (alpha)
AlphaValue = 5

# Intercept State
InterceptState = True

# Instance of <<Regularization>> 
Regul = fk.Regularization(predictors=Predictors,
                       target=Target,
                       alpha=AlphaValue,
                       intercept=InterceptState,
                       random_seed=RandomSeed)

# Results of Ridge regression
ResultsRidge = Regul.Penalized_Regression(model='ridge')
ResultsRidge
590088650-465d1b59-2ac2-4797-b594-358a49a7b432 Notes : The result of Regularization.Penalized_Regression function when alpha is scalar and model is Lasso is not yet available.

Lasso Regularization Path with Lasso instead Ridge fore more shrinkage ($\alpha_{k}$)

# Range of penality factor (alpha)
AlphaList = np.linspace(0, 9, 19)

# Intercept
InterceptState = True

# Instance of <<regularization>>
Regul = fk.Regularization(predictors=Predictors,
                       target=Target,
                       alpha=AlphaList,
                       intercept=InterceptState,
                       random_seed=RandomSeed)

# Summary of penalized coefficients in function of alpha
SummaryCoefLasso = Regul.Penalized_Regression(model='lasso')
SummaryCoefLasso
590089550-017cd3f8-0343-4c43-88b1-ad0de87886f5
# Regularization path of Lasso model
Regul.Visualization_Shrinking(penalized_coefficients_table=SummaryCoefLasso,
                              variables_selected=None, 
                              alpha_value_selected=None,<img width="582" height="459" alt="download" src="https://github.com/user-attachments/assets/1928380b-f4f4-4df5-bba5-c73b66999673" />
                              figure='curve')
590089670-820b6744-bfa2-48fa-adf9-927f21c196f7

Residuals Analysis

# Contour plot of residuals sum square loss
Beta1 = np.linspace(-25, 25, 50)
Beta2 = np.linspace(-25, 25, 50)
Regul.Visualization_Residuals(list_beta_1=Beta1,
                        list_beta_2=Beta2,
                        predictors=Predictors,
                        target=Target,
                        penalized_coefficients_table=SummaryCoefLasso,
                        var_1='X_2',
                        var_2='X_3',
                        intercept=0,
                        figure='contour_map')
590090580-45717dfe-ee81-49e6-8cc1-deaa7117effe

Bibliography

  • Hastie, T. (2009). The elements of statistical learning: data mining, inference, and prediction.
  • Cule, E., Vineis, P., & De Iorio, M. (2011). Significance testing in ridge regression for genetic data. BMC bioinformatics, 12(1), 372.
  • van Wieringen, W. N. (2015). Lecture notes on ridge regression. arXiv preprint arXiv:1509.09169.

Author

If you noticed some issues or you just want to improve the project, it's will be a pleasure for me to discuss with you ☎ :

  • Frenezik is developped and maintained by : Bengone Akou Lajoie
  • Github : beng-one | Email : bengonelajoie@gmail.com
  • ATLAS Organization
Logo_Futurist_Design_ElectronikBlack

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

frenezik-0.1.3.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

frenezik-0.1.3-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file frenezik-0.1.3.tar.gz.

File metadata

  • Download URL: frenezik-0.1.3.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for frenezik-0.1.3.tar.gz
Algorithm Hash digest
SHA256 65a86e1a50ca9caee961ad8208368aa7101efe441567b8e0f8dd102ad39cc5f5
MD5 e48a6b962af2d5365580f665a6e00839
BLAKE2b-256 693edc6874b1870d844b4054e80f5e1ad93856cf427225d84316f33217f7f21c

See more details on using hashes here.

File details

Details for the file frenezik-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: frenezik-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for frenezik-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9fd481fac2fd6067d4f3e654dd5bc105b1b0b025dd50dd81960ecb86e0b81507
MD5 668b03c16d6d34685f107898453e146e
BLAKE2b-256 c1779c7257e118d1e476a940564496b845e9535b66dd17388327a644846a4644

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