Skip to content

Commit

Permalink
nothing to show on when pps is 0 on all fields (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
benisraeldan committed Jan 4, 2022
1 parent 33b4820 commit 31018fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
25 changes: 1 addition & 24 deletions deepchecks/checks/distribution/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,16 @@
import numpy as np
import pandas as pd
from scipy.stats import gaussian_kde
import matplotlib.pyplot as plt
import plotly.graph_objs as go

__all__ = ['plot_density', 'feature_distribution_traces', 'drift_score_bar_traces', 'get_density']
__all__ = ['feature_distribution_traces', 'drift_score_bar_traces', 'get_density']

from typing import List, Union, Dict

from deepchecks.checks.distribution.preprocessing import preprocess_2_cat_cols_to_same_bins
from deepchecks.utils.plot import colors


def plot_density(data, xs, color='b', alpha: float = 0.7, **kwargs) -> np.ndarray:
"""Plot a KDE density plot of the data. Adding labels and other plotting attributes is left to ths user.
Args:
data (): The data used to compute the pdf function.
xs (iterable): List of x values to plot the computed pdf for.
color (): Color of the filled graph.
alpha (float): Transparency of the filled graph.
Returns:
np.array: The computed pdf values at the points xs.
"""
density = gaussian_kde(data)
density.covariance_factor = lambda: .25
# pylint: disable=protected-access
density._compute_covariance()
plt.fill_between(xs, density(xs), color=color, alpha=alpha, **kwargs)
plt.gca().set_ylim(bottom=0)

return density(xs)


def get_density(data, xs) -> np.ndarray:
"""Get gaussian kde density to plot.
Expand Down
5 changes: 4 additions & 1 deletion deepchecks/checks/methodology/identifier_leakage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def _identifier_leakage(self, dataset: Union[pd.DataFrame, Dataset], ppscore_par
'For Identifier columns (Index/Date) PPS should be nearly 0, otherwise date and index have some '
'predictive effect on the label.']

return CheckResult(value=s_ppscore.to_dict(), display=[figure, *text])
# display only if not all scores are 0
display = [figure, *text] if s_ppscore.sum() else None

return CheckResult(value=s_ppscore.to_dict(), display=display)

def add_condition_pps_not_greater_than(self, max_pps: float = 0):
"""Add condition - require columns not to have a greater pps than given max.
Expand Down
5 changes: 4 additions & 1 deletion deepchecks/checks/methodology/single_feature_contribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def plot(n_show_top=self.n_show_top):
' actually due to data',
'leakage - meaning that the feature holds information that is based on the label to begin with.']

return CheckResult(value=s_ppscore.to_dict(), display=[plot, *text], header='Single Feature Contribution')
# display only if not all scores are 0
display = [plot, *text] if s_ppscore.sum() else None

return CheckResult(value=s_ppscore.to_dict(), display=display, header='Single Feature Contribution')

def add_condition_feature_pps_not_greater_than(self: FC, threshold: float = 0.8) -> FC:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def _single_feature_contribution_train_test(self, train_dataset: Dataset, test_d
ret_value = {'train': s_pps_train.to_dict(), 'test': s_pps_test.to_dict(),
'train-test difference': s_difference.to_dict()}

return CheckResult(value=ret_value, display=[fig, *text], header='Single Feature Contribution Train-Test')
# display only if not all scores are 0
display = [fig, *text] if s_pps_train.sum() or s_pps_test.sum() else None

return CheckResult(value=ret_value, display=display, header='Single Feature Contribution Train-Test')

def add_condition_feature_pps_difference_not_greater_than(self: FC, threshold: float = 0.2) -> FC:
"""Add new condition.
Expand Down

0 comments on commit 31018fa

Please sign in to comment.