Estimators
Summary
CALMRegressor and CALMClassifier are the two estimators. One fit call
trains the teacher, finds and selects the regions, and fits one curve per
(feature, region). Both follow the scikit-learn convention: constructor
arguments configure, fit learns, fitted attributes end with _. Every
argument is keyword-only and has a default; the
parameters page lists them by importance.
Usage
from calm_additive import CALMRegressor, CALMClassifier
calm = CALMRegressor(max_partition_depth=2)
calm.fit(X_train, y_train) # numpy array or pandas DataFrame
calm.predict(X_test)
clf = CALMClassifier().fit(X_train, y_train) # y in {0, 1}
clf.predict(X_test) # labels
clf.predict_proba(X_test) # (N, 2)
After fit:
| access | what it is |
|---|---|
calm.print_summary(), calm.plot_curves(), … |
the model printed and drawn: see printing and plotting |
calm.chain_.show() |
the ledger: accepted and rejected partitions, and why |
calm.n_conditional_interactions_ |
number of (feature, conditioning feature) pairs; x1 \| x2 and x2 \| x1 are two |
calm.partitions_ |
{feature index: Partition}; part.leaves, part.label(leaf.idx) |
calm.interactions_info_ |
regions per feature, conditioning features |
calm.teacher_ |
the fitted teacher |
calm.effect_ |
the effector effect used for detection |
calm.model_ |
the fitted additive model |
calm.gam_ |
the GAM reference, once print_summary(X, y) has fitted it |
chain_, partitions_ and effect_ are effector
objects and are documented there.
Binary classification and regression only
Multi-class targets are not supported.
API
calm_additive.engine.CALMRegressor(*, max_conditional_interactions=10, max_partitions=None, max_partition_depth=2, min_heterogeneity_drop=0.05, min_r2_gain=0.01, teacher='xgb', effect='pdp', partitioner='best', partition_features='heterogeneous', conditioning_features='all', selection='r2_gain', curve_fitter='ebm', selection_target='teacher', min_relative_r2_gain=None, teacher_params=None, effect_params=None, partitioner_params=None, curve_fitter_params=None, schema=None, random_state=42, verbose=0)
Bases: _CALMBase
CALM for regression.
calm = CALMRegressor(max_partition_depth=2)
calm.fit(X_train, y_train) # numpy array or pandas DataFrame
calm.predict(X_test)
calm.print_summary(X_test, y_test) # the model card, and where it stands
calm.plot_curves() # one panel per feature, one curve per region
calm.print_prediction(X_test.iloc[0]) # why this prediction
calm.chain_.show() # why each partition was kept or rejected
One fit runs the whole pipeline: fit the teacher, read it with a
feature-effect method, propose and select the partitions, then fit one
curve per (feature, region). Every argument is keyword-only and has a
default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_conditional_interactions
|
Optional[int]
|
(K in the paper) the most conditional
interactions the model may have — one per (feature, conditioning
feature) pair, so |
10
|
max_partitions
|
Optional[int]
|
the most features that may get a partition;
selection stops once it is reached. Default |
None
|
max_partition_depth
|
int
|
(d_max in the paper) depth of each feature's
partition tree, so a feature gets at most
|
2
|
min_heterogeneity_drop
|
float
|
(ε in the paper) inside one partition tree, the fraction by which a split must reduce the feature's heterogeneity to be made. Default 0.05. Higher means fewer splits. |
0.05
|
min_r2_gain
|
float
|
smallest R² gain (fraction of the target's variance, default 0.01 = 1 pt) a feature's partition must add, on top of the partitions already kept, to be kept. Higher means fewer partitions. |
0.01
|
teacher
|
the black-box model the partitions are read from. A
registered name ( |
'xgb'
|
|
effect
|
Union[str, object]
|
how the teacher is read to detect interactions — |
'pdp'
|
partitioner
|
Union[str, object]
|
what proposes a partition tree per feature — |
'best'
|
partition_features
|
Union[str, list]
|
which features may get a partition —
|
'heterogeneous'
|
conditioning_features
|
Union[str, list]
|
which features may appear in the region
rules — |
'all'
|
selection
|
str
|
which proposed partitions are kept — |
'r2_gain'
|
curve_fitter
|
what is fitted inside the regions — |
'ebm'
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
selection_target |
str
|
what the R² of |
min_relative_r2_gain |
Optional[float]
|
optional relaxed gate for nearly saturated
models — the threshold becomes
|
teacher_params |
Optional[dict]
|
keyword arguments for a teacher given by name or
class, e.g. |
effect_params |
Optional[dict]
|
effector's settings for an effect given by name —
constructor or |
partitioner_params |
Optional[dict]
|
effector's settings for a partitioner given by
name, e.g. |
curve_fitter_params |
Optional[dict]
|
keyword arguments for a fitter given by name,
e.g. |
schema |
feature names and types for a numpy |
|
random_state |
Optional[int]
|
one seed, passed to every component built by name. Default 42. |
verbose |
int
|
0 (default) is silent; 1 shows a progress bar over the
stages of |
Attributes:
| Name | Type | Description |
|---|---|---|
chain_ |
the decision ledger ( |
|
partitions_ |
|
|
model_ |
the fitted additive model ( |
|
teacher_ |
the fitted teacher. |
|
effect_ |
the effector effect the partitions were read from. |
|
n_conditional_interactions_ |
number of (feature, conditioning
feature) pairs in the model; |
|
interactions_info_ |
regions per feature and their conditioning features. |
|
n_features_in_ |
number of features seen in |
|
feature_names_in_ |
their names — the DataFrame's columns, the
schema's |
|
baseline_ |
float
|
the average score over the training rows; a prediction
is this plus the row's |
gam_ |
float
|
the GAM reference (the same curve fitter, no partitions) —
set by the first |
Methods:
| Name | Description |
|---|---|
fit |
Fit the teacher, propose and select the partitions, fit the curves. |
predict |
Predict: values for regression, 0/1 labels for classification. |
predict_score |
The raw score: the prediction for regression, the positive-class |
paper |
The apples-to-apples preset: old-CALM behavior on the new engine. |
Source code in calm_additive/engine.py
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 | |
fit(X, y)
Fit the teacher, propose and select the partitions, fit the curves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required | |
y
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
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 898 899 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 | |
predict(X)
Predict: values for regression, 0/1 labels for classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
958 959 960 961 962 963 964 965 966 967 | |
predict_score(X)
The raw score: the prediction for regression, the positive-class probability for classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
969 970 971 972 973 974 975 976 977 978 979 | |
paper(**overrides)
classmethod
The apples-to-apples preset: old-CALM behavior on the new engine.
Every proposed partition is applied (no R² selection, no cap on the
conditional interactions), Best partitioner, threshold proposer, numeric-only conditioning
(categorical splits off), 20 candidate split points, depth 2. The
drop threshold translates the paper's variance-scale ε=0.2 to the std
scale: 1 − √0.8 ≈ 0.106. Keyword arguments override the preset.
Source code in calm_additive/engine.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | |
calm_additive.engine.CALMClassifier(*, max_conditional_interactions=10, max_partitions=None, max_partition_depth=2, min_heterogeneity_drop=0.05, min_r2_gain=0.01, teacher='xgb', effect='pdp', partitioner='best', partition_features='heterogeneous', conditioning_features='all', selection='r2_gain', curve_fitter='ebm', selection_target='teacher', min_relative_r2_gain=None, teacher_params=None, effect_params=None, partitioner_params=None, curve_fitter_params=None, schema=None, random_state=42, verbose=0)
Bases: _CALMBase
CALM for binary classification.
calm = CALMClassifier(max_partition_depth=2)
calm.fit(X_train, y_train) # numpy array or pandas DataFrame
calm.predict(X_test)
calm.print_summary(X_test, y_test) # the model card, and where it stands
calm.plot_curves() # one panel per feature, one curve per region
calm.print_prediction(X_test.iloc[0]) # why this prediction
calm.chain_.show() # why each partition was kept or rejected
One fit runs the whole pipeline: fit the teacher, read it with a
feature-effect method, propose and select the partitions, then fit one
curve per (feature, region). Every argument is keyword-only and has a
default.
The target must be 0/1. The teacher is read through its positive-class
probability; predict thresholds the score at 0.5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_conditional_interactions
|
Optional[int]
|
(K in the paper) the most conditional
interactions the model may have — one per (feature, conditioning
feature) pair, so |
10
|
max_partitions
|
Optional[int]
|
the most features that may get a partition;
selection stops once it is reached. Default |
None
|
max_partition_depth
|
int
|
(d_max in the paper) depth of each feature's
partition tree, so a feature gets at most
|
2
|
min_heterogeneity_drop
|
float
|
(ε in the paper) inside one partition tree, the fraction by which a split must reduce the feature's heterogeneity to be made. Default 0.05. Higher means fewer splits. |
0.05
|
min_r2_gain
|
float
|
smallest R² gain (fraction of the target's variance, default 0.01 = 1 pt) a feature's partition must add, on top of the partitions already kept, to be kept. Higher means fewer partitions. |
0.01
|
teacher
|
the black-box model the partitions are read from. A
registered name ( |
'xgb'
|
|
effect
|
Union[str, object]
|
how the teacher is read to detect interactions — |
'pdp'
|
partitioner
|
Union[str, object]
|
what proposes a partition tree per feature — |
'best'
|
partition_features
|
Union[str, list]
|
which features may get a partition —
|
'heterogeneous'
|
conditioning_features
|
Union[str, list]
|
which features may appear in the region
rules — |
'all'
|
selection
|
str
|
which proposed partitions are kept — |
'r2_gain'
|
curve_fitter
|
what is fitted inside the regions — |
'ebm'
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
selection_target |
str
|
what the R² of |
min_relative_r2_gain |
Optional[float]
|
optional relaxed gate for nearly saturated
models — the threshold becomes
|
teacher_params |
Optional[dict]
|
keyword arguments for a teacher given by name or
class, e.g. |
effect_params |
Optional[dict]
|
effector's settings for an effect given by name —
constructor or |
partitioner_params |
Optional[dict]
|
effector's settings for a partitioner given by
name, e.g. |
curve_fitter_params |
Optional[dict]
|
keyword arguments for a fitter given by name,
e.g. |
schema |
feature names and types for a numpy |
|
random_state |
Optional[int]
|
one seed, passed to every component built by name. Default 42. |
verbose |
int
|
0 (default) is silent; 1 shows a progress bar over the
stages of |
Attributes:
| Name | Type | Description |
|---|---|---|
chain_ |
the decision ledger ( |
|
partitions_ |
|
|
model_ |
the fitted additive model ( |
|
teacher_ |
the fitted teacher. |
|
effect_ |
the effector effect the partitions were read from. |
|
n_conditional_interactions_ |
number of (feature, conditioning
feature) pairs in the model; |
|
interactions_info_ |
regions per feature and their conditioning features. |
|
n_features_in_ |
number of features seen in |
|
feature_names_in_ |
their names — the DataFrame's columns, the
schema's |
|
baseline_ |
float
|
the average score over the training rows; a prediction
is this plus the row's |
gam_ |
float
|
the GAM reference (the same curve fitter, no partitions) —
set by the first |
Methods:
| Name | Description |
|---|---|
fit |
Fit the teacher, propose and select the partitions, fit the curves. |
predict |
Predict: values for regression, 0/1 labels for classification. |
predict_proba |
Class probabilities, in scikit-learn's two-column shape. |
predict_score |
The raw score: the prediction for regression, the positive-class |
paper |
The apples-to-apples preset: old-CALM behavior on the new engine. |
Source code in calm_additive/engine.py
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 | |
fit(X, y)
Fit the teacher, propose and select the partitions, fit the curves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required | |
y
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
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 898 899 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 | |
predict(X)
Predict: values for regression, 0/1 labels for classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
958 959 960 961 962 963 964 965 966 967 | |
predict_proba(X)
Class probabilities, in scikit-learn's two-column shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 | |
predict_score(X)
The raw score: the prediction for regression, the positive-class probability for classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in calm_additive/engine.py
969 970 971 972 973 974 975 976 977 978 979 | |
paper(**overrides)
classmethod
The apples-to-apples preset: old-CALM behavior on the new engine.
Every proposed partition is applied (no R² selection, no cap on the
conditional interactions), Best partitioner, threshold proposer, numeric-only conditioning
(categorical splits off), 20 candidate split points, depth 2. The
drop threshold translates the paper's variance-scale ε=0.2 to the std
scale: 1 − √0.8 ≈ 0.106. Keyword arguments override the preset.
Source code in calm_additive/engine.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | |