Skip to content

Commit 3b18837

Browse files
updated docs
1 parent 8d8757c commit 3b18837

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

API_REFERENCE_FOR_REGRESSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Used to randomly split training observations into cv_folds if ***cv_observations
1717
Determines the loss function used. Allowed values are "mse", "binomial", "poisson", "gamma", "tweedie", "group_mse", "group_mse_cycle","mae", "quantile", "negative_binomial", "cauchy", "weibull" and "custom_function". This is used together with ***link_function***. When ***loss_function*** is "group_mse" then the "group" argument in the ***fit*** method must be provided. In the latter case APLR will try to minimize group MSE when training the model. When using "group_mse_cycle", ***group_mse_cycle_min_obs_in_bin*** controls the minimum amount of observations in each group. For a description of "group_mse_cycle" see ***group_mse_cycle_min_obs_in_bin***. The ***loss_function*** "quantile" is used together with the ***quantile*** constructor parameter. When ***loss_function*** is "custom_function" then the constructor parameters ***calculate_custom_loss_function*** and ***calculate_custom_negative_gradient_function***, both described below, must be provided.
1818

1919
#### link_function (default = "identity")
20-
Determines how the linear predictor is transformed to predictions. Allowed values are "identity", "logit", "log" and "custom_function". For an ordinary regression model use ***loss_function*** "mse" and ***link_function*** "identity". For logistic regression use ***loss_function*** "binomial" and ***link_function*** "logit". For a multiplicative model use the "log" ***link_function***. The "log" ***link_function*** often works best with a "poisson", "gamma", "tweedie", "negative_binomial" or "weibull" ***loss_function***, depending on the data. The ***loss_function*** "poisson", "gamma", "tweedie", "negative_binomial" or "weibull" should only be used with the "log" ***link_function***. Inappropriate combinations of ***loss_function*** and ***link_function*** may result in a warning message when fitting the model and/or a poor model fit. Please note that values other than "identity" may require a higher ***m*** (or ***v***) in order to converge. When ***link_function*** is "custom_function" then the constructor parameters ***calculate_custom_transform_linear_predictor_to_predictions_function*** and ***calculate_custom_differentiate_predictions_wrt_linear_predictor_function***, both described below, must be provided.
20+
Determines how the linear predictor is transformed to predictions. Allowed values are "identity", "logit", "log" and "custom_function". For an ordinary regression model use ***loss_function*** "mse" and ***link_function*** "identity". For logistic regression use ***loss_function*** "binomial" and ***link_function*** "logit". For a multiplicative model use the "log" ***link_function***. The "log" ***link_function*** often works best with a "poisson", "gamma", "tweedie", "negative_binomial" or "weibull" ***loss_function***, depending on the data. The ***loss_function*** "poisson", "gamma", "tweedie", "negative_binomial" or "weibull" should only be used with the "log" ***link_function***. Inappropriate combinations of ***loss_function*** and ***link_function*** may result in a warning message when fitting the model and/or a poor model fit. When ***link_function*** is "custom_function" then the constructor parameters ***calculate_custom_transform_linear_predictor_to_predictions_function*** and ***calculate_custom_differentiate_predictions_wrt_linear_predictor_function***, both described below, must be provided.
2121

2222
#### n_jobs (default = 0)
2323
Multi-threading parameter. If ***0*** then uses all available cores for multi-threading. Any other positive integer specifies the number of cores to use (***1*** means single-threading).

documentation/APLR 10.9.0.pdf

974 Bytes
Binary file not shown.

examples/train_aplr_classification.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
param_grid = ParameterGrid(
4040
{
4141
"max_interaction_level": [0, 1],
42-
"min_observations_in_split": [1, 4, 20, 40],
43-
"ridge_penalty": [0.0001, 0.001],
42+
"min_observations_in_split": [1, 4, 20],
43+
"ridge_penalty": [0, 0.0001, 0.001],
4444
}
4545
)
4646
best_model: APLRClassifier = None
@@ -50,7 +50,8 @@
5050
verbosity=2,
5151
m=3000,
5252
v=0.5,
53-
# max_terms=5, # Optionally tune this to find a trade-off between interpretability and predictiveness. May require a higher learning rate for best results.
53+
num_first_steps_with_linear_effects_only=0, # Increasing this will increase interpretabilty but may decrease predictiveness.
54+
boosting_steps_before_interactions_are_allowed=0, # Increasing this will increase interpretabilty but may decrease predictiveness.
5455
**params
5556
)
5657
model.fit(

examples/train_aplr_classification_using_aplr_tuner.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,17 @@
3737
parameters = {
3838
"random_state": [random_state],
3939
"max_interaction_level": [0, 1],
40-
"min_observations_in_split": [1, 4, 20, 40],
40+
"min_observations_in_split": [1, 4, 20],
4141
"verbosity": [2],
4242
"m": [3000],
4343
"v": [0.5],
44-
"ridge_penalty": [0.0001, 0.001],
45-
# "max_terms": [5],
44+
"ridge_penalty": [0, 0.0001, 0.001],
45+
"num_first_steps_with_linear_effects_only": [
46+
0
47+
], # Increasing num_first_steps_with_linear_effects_only will increase interpretabilty but may decrease predictiveness.
48+
"boosting_steps_before_interactions_are_allowed": [
49+
0
50+
], # Increasing boosting_steps_before_interactions_are_allowed will increase interpretabilty but may decrease predictiveness.
4651
}
4752
aplr_tuner = APLRTuner(parameters=parameters, is_regressor=False)
4853
aplr_tuner.fit(

examples/train_aplr_regression.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
param_grid = ParameterGrid(
3939
{
4040
"max_interaction_level": [0, 1],
41-
"min_observations_in_split": [1, 4, 20, 50, 100, 200],
42-
"ridge_penalty": [0.0001, 0.001],
41+
"min_observations_in_split": [1, 4, 20, 50],
42+
"ridge_penalty": [0, 0.0001, 0.001],
4343
}
4444
)
4545
best_model: APLRRegressor = None
@@ -55,7 +55,8 @@
5555
v=0.5,
5656
loss_function=loss_function,
5757
link_function=link_function,
58-
# max_terms=10, # Optionally tune this to find a trade-off between interpretability and predictiveness. May require a higher learning rate for best results.
58+
num_first_steps_with_linear_effects_only=0, # Increasing this will increase interpretabilty but may decrease predictiveness.
59+
boosting_steps_before_interactions_are_allowed=0, # Increasing this will increase interpretabilty but may decrease predictivenes.
5960
**params,
6061
)
6162
model.fit(
@@ -103,10 +104,9 @@
103104
by="importance", ascending=False
104105
)
105106

106-
# Shapes for all term affiliations in the model. For each term affiliation, contains predictor values and the corresponding
107+
# Shapes for all term affiliations in the model. For each term affiliation, shape_df contains predictor values and the corresponding
107108
# contributions to the linear predictor. Plots are created for main effects and two-way interactions.
108109
# This is probably the most useful method to use for understanding how the model works.
109-
shapes: Dict[str, pd.DataFrame] = {}
110110
predictors_in_each_affiliation = (
111111
best_model.get_base_predictors_in_each_unique_term_affiliation()
112112
)
@@ -119,7 +119,6 @@
119119
shape,
120120
columns=[predictors[i] for i in predictor_indexes_used] + ["contribution"],
121121
)
122-
shapes.update({affiliation: shape_df})
123122
is_main_effect: bool = len(predictor_indexes_used) == 1
124123
is_two_way_interaction: bool = len(predictor_indexes_used) == 2
125124
if is_main_effect:

examples/train_aplr_regression_using_aplr_tuner.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@
4040
parameters = {
4141
"random_state": [random_state],
4242
"max_interaction_level": [0, 1],
43-
"min_observations_in_split": [1, 4, 20, 50, 100, 200],
43+
"min_observations_in_split": [1, 4, 20, 50],
4444
"verbosity": [2],
4545
"m": [3000],
4646
"v": [0.5],
4747
"loss_function": [loss_function],
4848
"link_function": [link_function],
49-
"ridge_penalty": [0.0001, 0.001],
50-
# "max_terms": [10],
49+
"ridge_penalty": [0, 0.0001, 0.001],
50+
"num_first_steps_with_linear_effects_only": [
51+
0
52+
], # Increasing num_first_steps_with_linear_effects_only will increase interpretabilty but may decrease predictiveness.
53+
"boosting_steps_before_interactions_are_allowed": [
54+
0
55+
], # Increasing boosting_steps_before_interactions_are_allowed will increase interpretabilty but may decrease predictiveness.
5156
}
5257
aplr_tuner = APLRTuner(parameters=parameters, is_regressor=True)
5358
aplr_tuner.fit(
@@ -90,10 +95,9 @@
9095
by="importance", ascending=False
9196
)
9297

93-
# Shapes for all term affiliations in the model. For each term affiliation, contains predictor values and the corresponding
98+
# Shapes for all term affiliations in the model. For each term affiliation, shape_df contains predictor values and the corresponding
9499
# contributions to the linear predictor. Plots are created for main effects and two-way interactions.
95100
# This is probably the most useful method to use for understanding how the model works.
96-
shapes: Dict[str, pd.DataFrame] = {}
97101
predictors_in_each_affiliation = (
98102
best_model.get_base_predictors_in_each_unique_term_affiliation()
99103
)
@@ -106,7 +110,6 @@
106110
shape,
107111
columns=[predictors[i] for i in predictor_indexes_used] + ["contribution"],
108112
)
109-
shapes.update({affiliation: shape_df})
110113
is_main_effect: bool = len(predictor_indexes_used) == 1
111114
is_two_way_interaction: bool = len(predictor_indexes_used) == 2
112115
if is_main_effect:

0 commit comments

Comments
 (0)