Skip to content

Commit 11b74f3

Browse files
10.10.0
1 parent 3b18837 commit 11b74f3

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

API_REFERENCE_FOR_REGRESSION.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,8 @@ Prevents the output from having significantly more than ***max_rows_before_sampl
368368
### Parameters
369369

370370
#### value
371-
A float representing the new intercept.
371+
A float representing the new intercept.
372+
373+
## Method: remove_provided_custom_functions()
374+
375+
***Removes any custom functions provided for calculating the loss, negative gradient, or validation error. This is useful after model training with custom functions, ensuring that the APLRRegressor object no longer depends on these functions—so they do not need to be present in the Python environment when loading a saved model.***

aplr/aplr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ def get_cv_error(self) -> float:
312312
def set_intercept(self, value: float):
313313
self.APLRRegressor.set_intercept(value)
314314

315+
def remove_provided_custom_functions(self):
316+
self.APLRRegressor.remove_provided_custom_functions()
317+
self.calculate_custom_validation_error_function = None
318+
self.calculate_custom_loss_function = None
319+
self.calculate_custom_negative_gradient_function = None
320+
315321
# For sklearn
316322
def get_params(self, deep=True):
317323
return {

cpp/APLRRegressor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class APLRRegressor
304304
size_t unique_term_affiliation_index);
305305
double get_cv_error();
306306
void set_intercept(double value);
307+
void remove_provided_custom_functions();
307308

308309
friend class APLRClassifier;
309310
};
@@ -2775,4 +2776,11 @@ void APLRRegressor::set_intercept(double value)
27752776
throw std::runtime_error("The new intercept must be finite.");
27762777
intercept = value;
27772778
term_coefficients[0] = value;
2779+
}
2780+
2781+
void APLRRegressor::remove_provided_custom_functions()
2782+
{
2783+
calculate_custom_validation_error_function = {};
2784+
calculate_custom_loss_function = {};
2785+
calculate_custom_negative_gradient_function = {};
27782786
}

cpp/pythonbinding.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ PYBIND11_MODULE(aplr_cpp, m)
8080
py::arg("max_rows_before_sampling") = 100000)
8181
.def("get_cv_error", &APLRRegressor::get_cv_error)
8282
.def("set_intercept", &APLRRegressor::set_intercept, py::arg("value"))
83+
.def("remove_provided_custom_functions", &APLRRegressor::remove_provided_custom_functions)
8384
.def_readwrite("intercept", &APLRRegressor::intercept)
8485
.def_readwrite("m", &APLRRegressor::m)
8586
.def_readwrite("m_optimal", &APLRRegressor::m_optimal)

cpp/tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class Tests
661661
model.fit(X_train, y_train, sample_weight, {}, cv_observations, prioritized_predictor_indexes, {}, VectorXi(0), {}, X_train);
662662
std::cout << "feature importance\n"
663663
<< model.feature_importance << "\n\n";
664-
664+
model.remove_provided_custom_functions();
665665
VectorXd predictions{model.predict(X_test)};
666666

667667
// Saving results
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
setuptools.setup(
3030
name="aplr",
31-
version="10.9.0",
31+
version="10.10.0",
3232
description="Automatic Piecewise Linear Regression",
3333
ext_modules=[sfc_module],
3434
author="Mathias von Ottenbreit",

0 commit comments

Comments
 (0)