SauceCat / PDPbox

python partial dependence plot toolbox
http://pdpbox.readthedocs.io/en/latest/
MIT License
840 stars 129 forks source link

Accepts a custom matplotlib.colors.Normalize object #42

Open vaidyasm opened 5 years ago

vaidyasm commented 5 years ago

In this PR, pdpbox.pdp.pdp_interact_plot() makes use of user specified (if any) matplotlib.colors.Normalize object as value for 'norm' key in 'plot_params' dictionary argument. A user initialized normalize object can be used & reused to obtain consistent normalization of 'marginal effect' being plotted. If this key is not set, the method is set to behave as unmodified version by passing None as norm to _pdp_inter_one().

This PR was created to address https://github.com/SauceCat/PDPbox/issues/39

Affect of this PR can be seen in following two plots. The 'Before' plots uses full color scale regardless of the range of 'marginal effect' being plotted. In the 'After' plots, color mappings are consistent with values of the 'marginal effect' being plotted.

Interaction plots with large variations in marginal effects can now be identified with cursory look at 'After' plots, without having to read off range from color scale.

Plot 1: Small Range of Marginal Effect

Before: 01_before_crop

After: 01_after_crop

Plot 2: Large Range of Marginal Effect

Before: 02_before_crop

After: 02_after_crop

vaidyasm commented 5 years ago

@SauceCat I was wondering how master branch build is passing in the first place as the errors are emanating from https://github.com/SauceCat/PDPbox/blob/master/pdpbox/pdp_plot_utils.py#L251

Error: TypeError: clabel() got an unexpected keyword argument 'contour_label_fontsize'