Skip to content

Commit 7382e77

Browse files
9.8.0
1 parent 8df0e3a commit 7382e77

File tree

11 files changed

+266
-14
lines changed

11 files changed

+266
-14
lines changed

API_REFERENCE_FOR_CLASSIFICATION.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Specifies a penalty in the range [0.0, 1.0] on terms that are not linear effects
5959
Specifies a penalty in the range [0.0, 1.0] on interaction terms. A higher value increases model interpretability but can hurt predictiveness. Values outside of the [0.0, 1.0] range are rounded to the nearest boundary within the range.
6060

6161

62-
## Method: fit(X:npt.ArrayLike, y:List[str], sample_weight:npt.ArrayLike = np.empty(0), X_names:List[str]=[], cv_observations: npt.ArrayLike = np.empty([0, 0]), prioritized_predictors_indexes:List[int]=[], monotonic_constraints:List[int]=[], interaction_constraints:List[List[int]]=[])
62+
## Method: fit(X:npt.ArrayLike, y:List[str], sample_weight:npt.ArrayLike = np.empty(0), X_names:List[str]=[], cv_observations: npt.ArrayLike = np.empty([0, 0]), prioritized_predictors_indexes:List[int]=[], monotonic_constraints:List[int]=[], interaction_constraints:List[List[int]]=[], predictor_learning_rates: List[float] = [], predictor_penalties_for_non_linearity: List[float] = [], predictor_penalties_for_interactions: List[float] = [])
6363

6464
***This method fits the model to data.***
6565

@@ -89,6 +89,15 @@ An optional list of integers specifying monotonic constraints on model terms. Fo
8989
#### interaction_constraints
9090
An optional list containing lists of integers. Specifies interaction constraints on model terms. For example, interaction_constraints = [[0,1], [1,2,3]] means that 1) the first and second predictors may interact with each other, and that 2) the second, third and fourth predictors may interact with each other. There are no interaction constraints on predictors not mentioned in interaction_constraints.
9191

92+
#### predictor_learning_rates
93+
An optional list of floats specifying learning rates for each predictor. If provided then this supercedes ***v***. For example, if there are two predictors in ***X***, then predictor_learning_rates = [0.1,0.2] means that all terms using the first predictor in ***X*** as a main effect will have a learning rate of 0.1 and that all terms using the second predictor in ***X*** as a main effect will have a learning rate of 0.2.
94+
95+
#### predictor_penalties_for_non_linearity
96+
An optional list of floats specifying penalties for non-linearity for each predictor. If provided then this supercedes ***penalty_for_non_linearity***. For example, if there are two predictors in ***X***, then predictor_penalties_for_non_linearity = [0.1,0.2] means that all terms using the first predictor in ***X*** as a main effect will have a penalty for non-linearity of 0.1 and that all terms using the second predictor in ***X*** as a main effect will have a penalty for non-linearity of 0.2.
97+
98+
#### predictor_penalties_for_interactions
99+
An optional list of floats specifying interaction penalties for each predictor. If provided then this supercedes ***penalty_for_interactions***. For example, if there are two predictors in ***X***, then predictor_penalties_for_interactions = [0.1,0.2] means that all terms using the first predictor in ***X*** as a main effect will have an interaction penalty of 0.1 and that all terms using the second predictor in ***X*** as a main effect will have an interaction penalty of 0.2.
100+
92101

93102
## Method: predict_class_probabilities(X:npt.ArrayLike, cap_predictions_to_minmax_in_training:bool=False)
94103

API_REFERENCE_FOR_REGRESSION.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Specifies a penalty in the range [0.0, 1.0] on terms that are not linear effects
127127
Specifies a penalty in the range [0.0, 1.0] on interaction terms. A higher value increases model interpretability but can hurt predictiveness. Values outside of the [0.0, 1.0] range are rounded to the nearest boundary within the range.
128128

129129

130-
## Method: fit(X:npt.ArrayLike, y:npt.ArrayLike, sample_weight:npt.ArrayLike = np.empty(0), X_names:List[str]=[], cv_observations: npt.ArrayLike = np.empty([0, 0]), prioritized_predictors_indexes:List[int]=[], monotonic_constraints:List[int]=[], group:npt.ArrayLike = np.empty(0), interaction_constraints:List[List[int]]=[], other_data: npt.ArrayLike = np.empty([0, 0]))
130+
## Method: fit(X:npt.ArrayLike, y:npt.ArrayLike, sample_weight:npt.ArrayLike = np.empty(0), X_names:List[str]=[], cv_observations: npt.ArrayLike = np.empty([0, 0]), prioritized_predictors_indexes:List[int]=[], monotonic_constraints:List[int]=[], group:npt.ArrayLike = np.empty(0), interaction_constraints:List[List[int]]=[], other_data: npt.ArrayLike = np.empty([0, 0]), predictor_learning_rates: List[float] = [], predictor_penalties_for_non_linearity: List[float] = [], predictor_penalties_for_interactions: List[float] = [])
131131

132132
***This method fits the model to data.***
133133

@@ -163,6 +163,15 @@ An optional list containing lists of integers. Specifies interaction constraints
163163
#### other_data
164164
An optional numpy matrix with other data. This is used in custom loss, negative gradient and validation error functions.
165165

166+
#### predictor_learning_rates
167+
An optional list of floats specifying learning rates for each predictor. If provided then this supercedes ***v***. For example, if there are two predictors in ***X***, then predictor_learning_rates = [0.1,0.2] means that all terms using the first predictor in ***X*** as a main effect will have a learning rate of 0.1 and that all terms using the second predictor in ***X*** as a main effect will have a learning rate of 0.2.
168+
169+
#### predictor_penalties_for_non_linearity
170+
An optional list of floats specifying penalties for non-linearity for each predictor. If provided then this supercedes ***penalty_for_non_linearity***. For example, if there are two predictors in ***X***, then predictor_penalties_for_non_linearity = [0.1,0.2] means that all terms using the first predictor in ***X*** as a main effect will have a penalty for non-linearity of 0.1 and that all terms using the second predictor in ***X*** as a main effect will have a penalty for non-linearity of 0.2.
171+
172+
#### predictor_penalties_for_interactions
173+
An optional list of floats specifying interaction penalties for each predictor. If provided then this supercedes ***penalty_for_interactions***. For example, if there are two predictors in ***X***, then predictor_penalties_for_interactions = [0.1,0.2] means that all terms using the first predictor in ***X*** as a main effect will have an interaction penalty of 0.1 and that all terms using the second predictor in ***X*** as a main effect will have an interaction penalty of 0.2.
174+
166175

167176
## Method: predict(X:npt.ArrayLike, cap_predictions_to_minmax_in_training:bool=True)
168177

aplr/aplr.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ def fit(
185185
group: npt.ArrayLike = np.empty(0),
186186
interaction_constraints: List[List[int]] = [],
187187
other_data: npt.ArrayLike = np.empty([0, 0]),
188+
predictor_learning_rates: List[float] = [],
189+
predictor_penalties_for_non_linearity: List[float] = [],
190+
predictor_penalties_for_interactions: List[float] = [],
188191
):
189192
self.__set_params_cpp()
190193
self.APLRRegressor.fit(
@@ -198,6 +201,9 @@ def fit(
198201
group,
199202
interaction_constraints,
200203
other_data,
204+
predictor_learning_rates,
205+
predictor_penalties_for_non_linearity,
206+
predictor_penalties_for_interactions,
201207
)
202208

203209
def predict(
@@ -402,6 +408,9 @@ def fit(
402408
prioritized_predictors_indexes: List[int] = [],
403409
monotonic_constraints: List[int] = [],
404410
interaction_constraints: List[List[int]] = [],
411+
predictor_learning_rates: List[float] = [],
412+
predictor_penalties_for_non_linearity: List[float] = [],
413+
predictor_penalties_for_interactions: List[float] = [],
405414
):
406415
self.__set_params_cpp()
407416
self.APLRClassifier.fit(
@@ -413,6 +422,9 @@ def fit(
413422
prioritized_predictors_indexes,
414423
monotonic_constraints,
415424
interaction_constraints,
425+
predictor_learning_rates,
426+
predictor_penalties_for_non_linearity,
427+
predictor_penalties_for_interactions,
416428
)
417429

418430
def predict_class_probabilities(

cpp/APLRClassifier.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class APLRClassifier
6060
void fit(const MatrixXd &X, const std::vector<std::string> &y, const VectorXd &sample_weight = VectorXd(0),
6161
const std::vector<std::string> &X_names = {}, const MatrixXi &cv_observations = MatrixXi(0, 0),
6262
const std::vector<size_t> &prioritized_predictors_indexes = {}, const std::vector<int> &monotonic_constraints = {},
63-
const std::vector<std::vector<size_t>> &interaction_constraints = {});
63+
const std::vector<std::vector<size_t>> &interaction_constraints = {}, const std::vector<double> &predictor_learning_rates = {},
64+
const std::vector<double> &predictor_penalties_for_non_linearity = {},
65+
const std::vector<double> &predictor_penalties_for_interactions = {});
6466
MatrixXd predict_class_probabilities(const MatrixXd &X, bool cap_predictions_to_minmax_in_training = false);
6567
std::vector<std::string> predict(const MatrixXd &X, bool cap_predictions_to_minmax_in_training = false);
6668
MatrixXd calculate_local_feature_contribution(const MatrixXd &X);
@@ -110,7 +112,9 @@ APLRClassifier::~APLRClassifier()
110112

111113
void APLRClassifier::fit(const MatrixXd &X, const std::vector<std::string> &y, const VectorXd &sample_weight, const std::vector<std::string> &X_names,
112114
const MatrixXi &cv_observations, const std::vector<size_t> &prioritized_predictors_indexes,
113-
const std::vector<int> &monotonic_constraints, const std::vector<std::vector<size_t>> &interaction_constraints)
115+
const std::vector<int> &monotonic_constraints, const std::vector<std::vector<size_t>> &interaction_constraints,
116+
const std::vector<double> &predictor_learning_rates, const std::vector<double> &predictor_penalties_for_non_linearity,
117+
const std::vector<double> &predictor_penalties_for_interactions)
114118
{
115119
initialize();
116120
find_categories(y);
@@ -130,7 +134,8 @@ void APLRClassifier::fit(const MatrixXd &X, const std::vector<std::string> &y, c
130134
logit_models[categories[0]].penalty_for_non_linearity = penalty_for_non_linearity;
131135
logit_models[categories[0]].penalty_for_interactions = penalty_for_interactions;
132136
logit_models[categories[0]].fit(X, response_values[categories[0]], sample_weight, X_names, cv_observations, prioritized_predictors_indexes,
133-
monotonic_constraints, VectorXi(0), interaction_constraints);
137+
monotonic_constraints, VectorXi(0), interaction_constraints, MatrixXd(0, 0), predictor_learning_rates,
138+
predictor_penalties_for_non_linearity, predictor_penalties_for_interactions);
134139

135140
logit_models[categories[1]] = logit_models[categories[0]];
136141
invert_second_model_in_two_class_case(logit_models[categories[1]]);
@@ -149,7 +154,8 @@ void APLRClassifier::fit(const MatrixXd &X, const std::vector<std::string> &y, c
149154
logit_models[category].penalty_for_non_linearity = penalty_for_non_linearity;
150155
logit_models[category].penalty_for_interactions = penalty_for_interactions;
151156
logit_models[category].fit(X, response_values[category], sample_weight, X_names, cv_observations, prioritized_predictors_indexes,
152-
monotonic_constraints, VectorXi(0), interaction_constraints);
157+
monotonic_constraints, VectorXi(0), interaction_constraints, MatrixXd(0, 0), predictor_learning_rates,
158+
predictor_penalties_for_non_linearity, predictor_penalties_for_interactions);
153159
}
154160
}
155161

0 commit comments

Comments
 (0)