lasso-net / lassonet

Feature selection in neural networks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need help regarding extracting lambda values and feature_importances_

TipTopWarrior opened this issue · comments

Hi, thank you so much for the wonderful project and for providing the basic codes. I am currently testing the LassoNet Classifier algorithm on a dataset that I have. However, I need the best lambda value (best model) and also observe the features that are getting selected for this lambda value. Until now, I tried using the function model.best_lambda_ but that has been unsuccessful. Some help and direction would be appreciated.
Second question, in the Diabetes.py file, I see that the importance of each feature is calculated using model.feature_importances_.numpy(). I am a bit confused by this approach as shouldn't we be using the features from the best model. It might be a misunderstanding on my part but a clarification would be very good.
Looking forward to your help.

Hi, thank you for the interest in LassoNet.

However, I need the best lambda value (best model) and also observe the features that are getting selected for this lambda value. Until now, I tried using the function model.best_lambda_ but that has been unsuccessful. Some help and direction would be appreciated.

Indeed, the correct way is to use model.best_lambda and model.best_selected_. Do you run in any problem? Please share your code and the error you are getting.

model.feature_importance_ tells the lambda at which the feature willl disappear. Hence, the higher the importance, the more important the feature is. The best model chose some lambda and uses only the features with a higher importance.

Thank you so much for your help and here are code snippets that I am using:

model = LassoNetClassifier(
hidden_dims=(100,),
verbose=True
)
print("Lambda =", model.best_lambda)
print("Best Selected Features are: ", model.best_selected_)

This is how I am using the functions mentioned above in my code. However, I am getting the following errors:

AttributeError: 'LassoNetClassifier' object has no attribute 'best_lambda'

AttributeError: 'LassoNetClassifier' object has no attribute 'best_selected_'

Any help would be appreciated.
So, this model.feature_importance_ function finds the lambda for each feature and assigns an importance score for each feature. Did I understand the working perfectly?

Hey, really sorry I missed putting that but I have included the model.fit(X_train, y_train). The error still persists.

Have you installed the latest version? pip install git+https://github.com/lasso-net/lassonet

Can you provide a minimal reproducible example?

Closing this issue as it is stale.
Don't hesitate to reopen it if needed.