Skip to content

Commit

Permalink
add bin occupancy plot below factor plots
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixWick committed Oct 9, 2023
1 parent 37873ab commit 838c466
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion cyclic_boosting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,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
8 changes: 6 additions & 2 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,18 @@ 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)
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 838c466

Please sign in to comment.