civisanalytics / python-glmnet

A python port of the glmnet package for fitting generalized linear models via penalized maximum likelihood.
Other
262 stars 59 forks source link

New Feature: plotting #70

Open amirhessam88 opened 3 years ago

amirhessam88 commented 3 years ago

Hello! My name is Amir. I've been using GLMNet for the past couple years and I can tell you that is one of the go-to packages in industry especially in healthcare! So, I had to develop multiple helper functions to visualize the outputs and I was like why not to send a PR. Hope you guys accept it.

I have added a new .py file plotting.py. In this file, two main functions are written: coeff_path_plot and cv_score_plot. In this way, the user can run the plots by importing the functions from plotting. In addition to this, the class methods are written for both logitnet.py and elasticnet.py. So, the user can have plots by running model.plot_cv_score() or model.plot_coeff_path().

In terms of new dependency, I have added matplotlib and pandas to the dev-requirements.txt file. I did need to have pandas to figure-out if the input X is in pd.DataFrame format to use the column names for legends for plot_coeff_path module. Other than that, the pandas is not required. However, I believe it would be good if we keep it.

I have also added an example directory with two Jupyter Notebook to show how the new feature works.

I would probably need some help in testing part (one of them failed!). I appreciate it.

Here is the snapshots of the plots:

  1. Plot Cross-Validation Score: LogitNet cv_score_logitnet
  2. Plot Cross-Validation Score: ElasticNet cv_score_elasticnet
  3. Plot Coefficient Path: LogitNet coeff_path_logitnet
  4. Plot Coefficient Path: ElasticNet coeff_path_elasticnet

NOTE All plots are customizable. elasticnet_custom logitnet_custom