glm-tools / pyglmnet

Python implementation of elastic-net regularized generalized linear models
http://glm-tools.github.io/pyglmnet/
MIT License
280 stars 84 forks source link

Group lasso does not set any variables to zero #235

Closed pavanramkumar closed 6 years ago

pavanramkumar commented 6 years ago
from pyglmnet import GLM
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from pyglmnet.datasets import fetch_group_lasso_datasets
import pandas as pd

df = pd.read_csv("cleaned.csv", delimiter= "\t")
df.describe()

X = df[df.columns.difference(["bwt"])].values
y = df.loc[:, "bwt"].values
Xtrain, Xtest, ytrain, ytest =  train_test_split(X, y, test_size=0.2, random_state=42)

groups = [1,1,1,2,2,2,3,3,4,5,5,6,7,8,8,8]
lambdas = 0.1
gl_glm = GLM(tol=1e-2, group=groups, score_metric="deviance", alpha=1.0, reg_lambda=lambdas)
gl_glm.fit(Xtrain, ytrain)
print(gl_glm.beta_)

Doesn't set a single group's coefficients to zero. Issue reported by: adityagc@cmu.edu

pavanramkumar commented 6 years ago

Should be fixed by #249