Skip to content

Commit

Permalink
Merge pull request #53 from Blue-Yonder-OSS/analysis_plots_bin_occupa…
Browse files Browse the repository at this point in the history
…ncies

bin occupancy plots
  • Loading branch information
FelixWick authored Oct 16, 2023
2 parents 550760c + c01bb1c commit 0203e88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 0 additions & 1 deletion cyclic_boosting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ def prepare_plots(self, X: np.ndarray, y: np.ndarray, prediction: np.ndarray) ->
mean_prediction_finite = np.mean(prediction)

mean_prediction_binned = (sum_pw + 1) / (sum_w + 1)
feature.unbind_data()

if isinstance(self, IdentityLinkMixin):
feature.mean_dev = mean_prediction_binned - mean_target_binned
Expand Down
30 changes: 22 additions & 8 deletions cyclic_boosting/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ def plot_analysis(
dpi = 200
with contextlib.closing(PdfPages(filepath_or_object)) as pdf_pages:
plot_observer.check_fitted()
means, bin_centers, errors, _ = plot_observer.histograms

# do not show for nbinom width mode
if plot_observer.link_function.__class__ != CBNBinomC:
Expand Down Expand Up @@ -283,13 +282,28 @@ def _format_groupname_with_type(feature_group, feature_type):
def _plot_one_feature_group(plot_observer, grid_item, feature, binners=None, use_tightlayout=True, plot_yp=True):
if len(feature.feature_group) == 1:
# treatment of one-dimensional features
plt.subplot(grid_item)
plot_factor_1d(
feature,
bin_bounds=get_bin_bounds(binners, feature.feature_group[0]),
link_function=plot_observer.link_function,
plot_yp=plot_yp,
)
# no bin occupancy plot for too many bins
if len(feature.factors_link) > 400:
plt.subplot(grid_item)
plot_factor_1d(
feature,
bin_bounds=get_bin_bounds(binners, feature.feature_group[0]),
link_function=plot_observer.link_function,
plot_yp=plot_yp,
)
else:
gs = gridspec.GridSpecFromSubplotSpec(2, 1, subplot_spec=grid_item, height_ratios=[2.5, 0.4])
factor_plot = plt.subplot(gs[0, 0])
plot_factor_1d(
feature,
bin_bounds=get_bin_bounds(binners, feature.feature_group[0]),
link_function=plot_observer.link_function,
plot_yp=plot_yp,
)
plt.subplot(gs[1, 0], sharex=factor_plot)
bin_occupancies = np.bincount(feature.lex_binned_data)
plt.plot(range(len(bin_occupancies)), bin_occupancies)
plt.xticks(size="xx-small", rotation="vertical")
plt.grid(True, which="both")

elif len(feature.feature_group) == 2:
Expand Down

0 comments on commit 0203e88

Please sign in to comment.