Mappers
This page documents the mappers module.
ordboost.mappers
Base interfaces and implementations for bin-to-continuous target mappers.
BaseBinMapper
Bases: ABC, BaseEstimator, TransformerMixin
Abstract base class for all bin-to-continuous target mappers.
A bin mapper converts a discrete probability mass function (PMF) over
ordinal bins into a continuous predictive cumulative distribution
function (CDF). Subclasses need only implement _intra_bin_points,
which defines how each bin's interior is refined into additional grid
points, and optionally _validate_intra_bin_params for any
subclass-specific parameter validation that must run before the grid
is built.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
array-like of shape (n_bins - 1,) or None
|
Strictly increasing interior threshold values defining bin
boundaries, matching the convention of |
None
|
lower_bound
|
float or None
|
If set, asserts that the outcome's support has a true, known
finite lower limit at this value, and the predictive CDF is
forced to 0.0 there. If bin 0 contains no training data, this
value is still used as the anchor, If None, the first bin is
treated as genuinely unbounded below, and the CDF-0 anchor is
instead placed at the observed training minimum
(or, if bin 0 has no training data, degenerates to a zero-width
bin at |
None
|
upper_bound
|
float or None
|
Mirrors |
None
|
floor_atom
|
bool
|
If True, the lower boundary is modelled as a probability atom:
the empirical fraction of bin 0's own training data at or below
|
False
|
ceiling_atom
|
bool
|
Mirrors |
False
|
boundary_epsilon
|
float
|
Offset used to place two grid points strictly outside/inside the
outcome's support: the forced CDF=0 anchor at
|
1e-4
|
Attributes:
| Name | Type | Description |
|---|---|---|
bin_edges_ |
ndarray of shape (n_bins - 1,)
|
Validated interior threshold edges, set during |
n_bins_ |
int
|
Number of discrete bins, equal to |
grid_y_ |
ndarray of shape (n_grid_points,)
|
Fitted sub-grid target values, in ascending order. |
grid_cdf_weights_ |
ndarray of shape (n_grid_points,)
|
Fitted sub-grid weights in bin-index units, aligned with
|
Methods:
| Name | Description |
|---|---|
fit |
Fit the mapper's grid to continuous training targets. |
transform |
Map a discrete PMF matrix to continuous point estimates. |
to_continuous_dist |
Construct a ContinuousPredictiveDistribution from a discrete PMF matrix. |
Source code in ordboost/mappers.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
digitize(y_cont, edges, y_binned=None)
staticmethod
Assign each continuous target to a 0-indexed discrete bin.
Equivalent to numpy.digitize(y_cont, edges) directly: every
value in edges is a real, enforced threshold under this
mapper's bin_edges convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_cont
|
ndarray of shape (n_samples,)
|
Continuous target values. |
required |
edges
|
ndarray of shape (n_bins - 1,)
|
Validated interior threshold edges. |
required |
y_binned
|
array-like of shape (n_samples,) or None
|
Pre-computed 0-indexed bin labels. If None, labels are
derived from |
None
|
Returns:
| Type | Description |
|---|---|
ndarray of shape (n_samples,)
|
Integer bin label for each sample, in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in ordboost/mappers.py
fit(y_continuous, y_binned=None)
Fit the mapper's grid to continuous training targets.
Shared across all subclasses: validates any subclass-specific
parameters via _validate_intra_bin_params, then constructs the
grid via _build_grid, which sets bin_edges_, n_bins_,
grid_y_, and grid_cdf_weights_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_continuous
|
array-like of shape (n_samples,)
|
Unbinned continuous target values (e.g. exact physical units). |
required |
y_binned
|
array-like of shape (n_samples,)
|
Corresponding 0-indexed discrete bin labels. If None, labels
are computed automatically from |
None
|
Returns:
| Type | Description |
|---|---|
BaseBinMapper
|
The fitted mapper instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised by |
Source code in ordboost/mappers.py
to_continuous_dist(pmf)
Construct a continuous predictive distribution from a PMF.
Interpolates each sample's cumulative PMF against the fitted
grid_cdf_weights_ to obtain the predicted CDF value at each
grid_y_ point. Shared across all subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmf
|
array-like of shape (n_samples, n_bins)
|
Discrete probability mass function matrix where rows sum to 1.0. |
required |
Returns:
| Type | Description |
|---|---|
ContinuousPredictiveDistribution
|
Continuous distribution evaluated over the fitted |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If the mapper instance has not been fitted prior to calling. |
ValueError
|
If |
Source code in ordboost/mappers.py
transform(pmf)
Map a discrete PMF matrix to continuous point estimates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmf
|
array-like of shape (n_samples, n_bins)
|
Discrete probability mass function matrix where rows sum to 1.0. |
required |
Returns:
| Type | Description |
|---|---|
ndarray of shape (n_samples,)
|
Continuous point estimates, taken as the mean of
|
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If the mapper instance has not been fitted prior to calling. |
ValueError
|
If |
Source code in ordboost/mappers.py
ContinuousBinMapper
Bases: BaseBinMapper
Maps discrete bin probabilities to a maximally fine continuous grid.
Refines each bin's interior by enumerating every value spaced
resolution apart within that bin. For an integer-valued outcome,
resolution=1.0 enumerates every achievable value in the target range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
array-like of shape (n_bins + 1,) or None
|
Monotonically increasing boundaries defining continuous bin intervals. |
None
|
resolution
|
float
|
Spacing between consecutive interior grid points within a bin. Should reflect the outcome's true or effectively quantized resolution (e.g. 1.0 for an integer-valued outcome); very small values relative to bin width produce very large grids. |
1.0
|
density_weighted
|
bool
|
If True, each interior point's CDF weight is the empirical fraction of that bin's own training data at or below the point. If False, weight is assigned by uniform linear interpolation across the bin's width instead. |
True
|
max_grid_points
|
int
|
Upper bound on the total number of interior points generated
across all bins during |
1_000_000
|
lower_bound
|
float or None
|
See |
None
|
upper_bound
|
float or None
|
See |
None
|
floor_atom
|
bool
|
See |
False
|
ceiling_atom
|
bool
|
See |
False
|
boundary_epsilon
|
float
|
See |
1e-4
|
Attributes:
| Name | Type | Description |
|---|---|---|
resolution_ |
float
|
Validated copy of |
Source code in ordboost/mappers.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 | |
EmpiricalMeanBinMapper
Bases: BaseBinMapper
Maps discrete bin probabilities using one empirical-mean point per bin.
Refines each bin's interior with a single point at the empirical mean of that bin's own training data (not the geometric midpoint of the bin's edges), weighted by the empirical fraction of that bin's own data at or below the mean. This fraction is estimated from data rather than assumed to be 0.5, since the mean does not generally split a skewed bin's probability mass evenly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
array-like of shape (n_bins + 1,) or None
|
Monotonically increasing boundaries defining continuous bin intervals. |
None
|
lower_bound
|
bool
|
See |
True
|
upper_bound
|
bool
|
See |
True
|
floor_atom
|
bool
|
See |
False
|
ceiling_atom
|
bool
|
See |
False
|
boundary_epsilon
|
float
|
See |
1e-4
|
Source code in ordboost/mappers.py
EmpiricalMedianBinMapper
Bases: BaseBinMapper
Maps discrete bin probabilities using one empirical-median point per bin.
Refines each bin's interior with a single point at the empirical
median of that bin's own training data, weighted by the empirical
fraction of that bin's own data at or below the median. Unlike
EmpiricalMeanBinMapper, this fraction is close to 0.5 by
construction for even-sized, duplicate-free bins, but is still
computed empirically rather than assumed, since ties and odd sample
counts (where the median is itself an observed data point) can shift
it away from exactly 0.5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
array-like of shape (n_bins + 1,) or None
|
Monotonically increasing boundaries defining continuous bin intervals. |
None
|
lower_bound
|
bool
|
See |
True
|
upper_bound
|
bool
|
See |
True
|
floor_atom
|
bool
|
See |
False
|
ceiling_atom
|
bool
|
See |
False
|
boundary_epsilon
|
float
|
See |
1e-4
|
Source code in ordboost/mappers.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
transform(pmf)
Map a discrete PMF matrix to continuous median point estimates.
Overrides BaseBinMapper.transform to return the median of
to_continuous_dist(pmf) rather than the mean, consistent with
this mapper's use of the empirical median for grid construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmf
|
array-like of shape (n_samples, n_bins)
|
Discrete probability mass function matrix where rows sum to 1.0. |
required |
Returns:
| Type | Description |
|---|---|
ndarray of shape (n_samples,)
|
Continuous median point estimates. |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If the mapper instance has not been fitted prior to calling. |
ValueError
|
If |
Source code in ordboost/mappers.py
QuantileBinMapper
Bases: BaseBinMapper
Maps discrete bin probabilities using intra-bin empirical quantiles.
Refines each bin's interior using several fixed quantile levels computed on that bin's own training data, with each point's weight assumed equal to its quantile level (e.g. a bin's own empirical 25th percentile is assumed to sit at 25% into that bin's probability mass).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
array-like of shape (n_bins + 1,) or None
|
Monotonically increasing boundaries defining continuous bin intervals. |
None
|
quantiles
|
array-like of shape (n_quantiles,)
|
Intra-bin quantile levels, strictly within (0.0, 1.0), used to construct interior grid points for every bin. |
(0.25, 0.50, 0.75)
|
lower_bound
|
float or None
|
See |
None
|
upper_bound
|
float or None
|
See |
None
|
floor_atom
|
bool
|
See |
False
|
ceiling_atom
|
bool
|
See |
False
|
boundary_epsilon
|
float
|
See |
1e-4
|
Attributes:
| Name | Type | Description |
|---|---|---|
quantiles_ |
ndarray of shape (n_quantiles,)
|
Validated, sorted quantile levels, set by |
Source code in ordboost/mappers.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
UniformBinMapper
Bases: BaseBinMapper
Maps discrete bin probabilities using evenly-spaced uniform points.
Refines each bin's interior under a uniform-density-within-bin
assumption: n_points interior points are placed at evenly spaced
fractions of the bin's width, with cumulative weights assigned at
those same evenly spaced fractions. With n_points=0, no interior
refinement is added at all, and the mapper reduces to a piecewise-
linear CDF across raw bin edges. Point placement is independant
of bin_data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bin_edges
|
array-like of shape (n_bins + 1,) or None
|
Monotonically increasing boundaries defining continuous bin intervals. |
None
|
n_points
|
int
|
Number of evenly spaced interior points to add per bin. Must be a
non-negative integer. With |
1
|
lower_bound
|
float or None
|
See |
None
|
upper_bound
|
float or None
|
See |
None
|
floor_atom
|
bool
|
See |
False
|
ceiling_atom
|
bool
|
See |
False
|
boundary_epsilon
|
float
|
See |
1e-4
|
Attributes:
| Name | Type | Description |
|---|---|---|
n_points_ |
int
|
Validated copy of |
Source code in ordboost/mappers.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |