yngvem / group-lasso

Group Lasso implementation following the scikit-learn API
MIT License
105 stars 32 forks source link

`AttributeError` shows up, when it tested on the official example of logistic regression #22

Closed Dawntown closed 4 years ago

Dawntown commented 4 years ago

In the wake of installing group-lasso in my conda env, I tried to test it if it was configured correctly, so I ran the example of logistic regression offered on the docs page.

Every step is OK, but gl.fit(X, c), which throws out AttributeError as follows.

~/project/NDA_download/workshop_2/scripts/example_logistic_group_lasso.py in 
----> 86 gl.fit(X, c)

~/miniconda3/envs/zxcpy/lib/python3.6/site-packages/group_lasso/_group_lasso.py in fit(self, X, y, lipschitz)
    433         """Fit a group-lasso regularised linear model.
    434         """
--> 435         self._init_fit(X, y, lipschitz=lipschitz)
    436         self._minimise_loss()
    437         self.intercept_ -= (self._X_means_ @ self.coef_).reshape(

~/miniconda3/envs/zxcpy/lib/python3.6/site-packages/group_lasso/_group_lasso.py in _init_fit(self, X, y, lipschitz)
    413 
    414         self.subsampler_ = Subsampler(
--> 415             X.shape[0], self.subsampling_scheme, self.random_state
    416         )
    417 

~/miniconda3/envs/zxcpy/lib/python3.6/site-packages/group_lasso/_subsampling.py in __init__(self, num_indices, subsampling_scheme, random_state)
     88         self.random_state = random_state
     89         self.subsampling_scheme = subsampling_scheme
---> 90         self.set_num_indices(num_indices)
     91 
     92     def set_num_indices(self, num_indices):

~/miniconda3/envs/zxcpy/lib/python3.6/site-packages/group_lasso/_subsampling.py in set_num_indices(self, num_indices)
     92     def set_num_indices(self, num_indices):
     93         self.num_indices_ = num_indices
---> 94         self.update_indices()
     95 
     96     def subsample(self, *Xs):

~/miniconda3/envs/zxcpy/lib/python3.6/site-packages/group_lasso/_subsampling.py in update_indices(self)
    106             self.num_indices_,
    107             self.subsampling_scheme,
--> 108             random_state=self.random_state,
    109         )
    110 

~/miniconda3/envs/zxcpy/lib/python3.6/site-packages/group_lasso/_subsampling.py in _get_random_row_idxes(num_rows, subsampling_scheme, random_state)
     29         raise ValueError("Not valid subsampling scheme")
     30 
---> 31     inds = random_state.choice(num_rows, num_subsampled_rows, replace=False)
     32     inds.sort()
     33     return inds

AttributeError: 'NoneType' object has no attribute 'choice'

I had searched it on Google, while the error info seems ambiguous, nothing related found. The versions of dependencies are:

numpy = 1.18.4
scikit-learn = 0.23.0
joblib = 0.14.1
scipy = 1.4.1
threadpoolctl = 2.0.0
group-lasso = 1.4.0

Thank you very much.

yngvem commented 4 years ago

Thank you for notifying me. Apparently, I dodnt test the subsampling thoroughly with the latest version. I'll fix it by the end of this week, when I back from vacation and have my computer.

In the meantime, you can pass a random state object to the group lasso constructor

gl = GroupLasso([...], random_state=no.random.RandomState())

That should hopefully work!

Dawntown commented 4 years ago

Thank you for notifying me. Apparently, I dodnt test the subsampling thoroughly with the latest version. I'll fix it by the end of this week, when I back from vacation and have my computer.

In the meantime, you can pass a random state object to the group lasso constructor

gl = GroupLasso([...], random_state=no.random.RandomState())

That should hopefully work!

That works pretty well! Thank you very much!

yngvem commented 4 years ago

Hopefully it should all work now