aplr 10.5.0__cp38-cp38-win32.whl → 10.6.0__cp38-cp38-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aplr might be problematic. Click here for more details.
- aplr/aplr.py +69 -9
- {aplr-10.5.0.dist-info → aplr-10.6.0.dist-info}/METADATA +2 -2
- aplr-10.6.0.dist-info/RECORD +8 -0
- {aplr-10.5.0.dist-info → aplr-10.6.0.dist-info}/WHEEL +1 -1
- aplr_cpp.cp38-win32.pyd +0 -0
- aplr-10.5.0.dist-info/RECORD +0 -8
- {aplr-10.5.0.dist-info → aplr-10.6.0.dist-info}/LICENSE +0 -0
- {aplr-10.5.0.dist-info → aplr-10.6.0.dist-info}/top_level.txt +0 -0
aplr/aplr.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
from typing import List, Callable, Optional, Dict
|
|
1
|
+
from typing import List, Callable, Optional, Dict, Union
|
|
2
2
|
import numpy as np
|
|
3
3
|
import aplr_cpp
|
|
4
|
+
import itertools
|
|
4
5
|
|
|
5
6
|
FloatVector = np.ndarray
|
|
6
7
|
FloatMatrix = np.ndarray
|
|
@@ -12,7 +13,7 @@ class APLRRegressor:
|
|
|
12
13
|
def __init__(
|
|
13
14
|
self,
|
|
14
15
|
m: int = 20000,
|
|
15
|
-
v: float = 0.
|
|
16
|
+
v: float = 0.5,
|
|
16
17
|
random_state: int = 0,
|
|
17
18
|
loss_function: str = "mse",
|
|
18
19
|
link_function: str = "identity",
|
|
@@ -21,9 +22,9 @@ class APLRRegressor:
|
|
|
21
22
|
bins: int = 300,
|
|
22
23
|
max_interaction_level: int = 1,
|
|
23
24
|
max_interactions: int = 100000,
|
|
24
|
-
min_observations_in_split: int =
|
|
25
|
-
ineligible_boosting_steps_added: int =
|
|
26
|
-
max_eligible_terms: int =
|
|
25
|
+
min_observations_in_split: int = 4,
|
|
26
|
+
ineligible_boosting_steps_added: int = 15,
|
|
27
|
+
max_eligible_terms: int = 7,
|
|
27
28
|
verbosity: int = 0,
|
|
28
29
|
dispersion_parameter: float = 1.5,
|
|
29
30
|
validation_tuning_metric: str = "default",
|
|
@@ -351,7 +352,7 @@ class APLRClassifier:
|
|
|
351
352
|
def __init__(
|
|
352
353
|
self,
|
|
353
354
|
m: int = 20000,
|
|
354
|
-
v: float = 0.
|
|
355
|
+
v: float = 0.5,
|
|
355
356
|
random_state: int = 0,
|
|
356
357
|
n_jobs: int = 0,
|
|
357
358
|
cv_folds: int = 5,
|
|
@@ -359,9 +360,9 @@ class APLRClassifier:
|
|
|
359
360
|
verbosity: int = 0,
|
|
360
361
|
max_interaction_level: int = 1,
|
|
361
362
|
max_interactions: int = 100000,
|
|
362
|
-
min_observations_in_split: int =
|
|
363
|
-
ineligible_boosting_steps_added: int =
|
|
364
|
-
max_eligible_terms: int =
|
|
363
|
+
min_observations_in_split: int = 4,
|
|
364
|
+
ineligible_boosting_steps_added: int = 15,
|
|
365
|
+
max_eligible_terms: int = 7,
|
|
365
366
|
boosting_steps_before_interactions_are_allowed: int = 0,
|
|
366
367
|
monotonic_constraints_ignore_interactions: bool = False,
|
|
367
368
|
early_stopping_rounds: int = 500,
|
|
@@ -531,3 +532,62 @@ class APLRClassifier:
|
|
|
531
532
|
# For sklearn
|
|
532
533
|
def predict_proba(self, X: FloatMatrix) -> FloatMatrix:
|
|
533
534
|
return self.predict_class_probabilities(X)
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
class APLRTuner:
|
|
538
|
+
def __init__(
|
|
539
|
+
self,
|
|
540
|
+
parameters: Union[Dict[str, List[float]], List[Dict[str, List[float]]]] = {
|
|
541
|
+
"max_interaction_level": [0, 1],
|
|
542
|
+
"min_observations_in_split": [4, 10, 20, 100, 500, 1000],
|
|
543
|
+
},
|
|
544
|
+
is_regressor: bool = True,
|
|
545
|
+
):
|
|
546
|
+
self.parameters = parameters
|
|
547
|
+
self.is_regressor = is_regressor
|
|
548
|
+
self.parameter_grid = self._create_parameter_grid()
|
|
549
|
+
|
|
550
|
+
def _create_parameter_grid(self) -> List[Dict[str, float]]:
|
|
551
|
+
items = sorted(self.parameters.items())
|
|
552
|
+
keys, values = zip(*items)
|
|
553
|
+
combinations = list(itertools.product(*values))
|
|
554
|
+
grid = [dict(zip(keys, combination)) for combination in combinations]
|
|
555
|
+
return grid
|
|
556
|
+
|
|
557
|
+
def fit(self, X: FloatMatrix, y: FloatVector, **kwargs):
|
|
558
|
+
self.cv_results: List[Dict[str, float]] = []
|
|
559
|
+
best_validation_result = np.inf
|
|
560
|
+
for params in self.parameter_grid:
|
|
561
|
+
if self.is_regressor:
|
|
562
|
+
model = APLRRegressor(**params)
|
|
563
|
+
else:
|
|
564
|
+
model = APLRClassifier(**params)
|
|
565
|
+
model.fit(X, y, **kwargs)
|
|
566
|
+
cv_error_for_this_model = model.get_cv_error()
|
|
567
|
+
cv_results_for_this_model = model.get_params()
|
|
568
|
+
cv_results_for_this_model["cv_error"] = cv_error_for_this_model
|
|
569
|
+
self.cv_results.append(cv_results_for_this_model)
|
|
570
|
+
if cv_error_for_this_model < best_validation_result:
|
|
571
|
+
best_validation_result = cv_error_for_this_model
|
|
572
|
+
self.best_model = model
|
|
573
|
+
self.cv_results = sorted(self.cv_results, key=lambda x: x["cv_error"])
|
|
574
|
+
|
|
575
|
+
def predict(self, X: FloatMatrix, **kwargs) -> Union[FloatVector, List[str]]:
|
|
576
|
+
return self.best_model.predict(X, **kwargs)
|
|
577
|
+
|
|
578
|
+
def predict_class_probabilities(self, X: FloatMatrix, **kwargs) -> FloatMatrix:
|
|
579
|
+
if self.is_regressor == False:
|
|
580
|
+
return self.best_model.predict_class_probabilities(X, **kwargs)
|
|
581
|
+
else:
|
|
582
|
+
raise TypeError(
|
|
583
|
+
"predict_class_probabilities is only possible when is_regressor is False"
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
def predict_proba(self, X: FloatMatrix, **kwargs) -> FloatMatrix:
|
|
587
|
+
return self.predict_class_probabilities(X, **kwargs)
|
|
588
|
+
|
|
589
|
+
def get_best_estimator(self) -> Union[APLRClassifier, APLRRegressor]:
|
|
590
|
+
return self.best_model
|
|
591
|
+
|
|
592
|
+
def get_cv_results(self) -> List[Dict[str, float]]:
|
|
593
|
+
return self.cv_results
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: aplr
|
|
3
|
-
Version: 10.
|
|
3
|
+
Version: 10.6.0
|
|
4
4
|
Summary: Automatic Piecewise Linear Regression
|
|
5
5
|
Home-page: https://github.com/ottenbreit-data-science/aplr
|
|
6
6
|
Author: Mathias von Ottenbreit
|
|
@@ -19,7 +19,7 @@ Requires-Dist: numpy >=1.11
|
|
|
19
19
|
Automatic Piecewise Linear Regression.
|
|
20
20
|
|
|
21
21
|
# About
|
|
22
|
-
Build predictive and interpretable parametric regression or classification machine learning models in Python based on the Automatic Piecewise Linear Regression (APLR) methodology developed by Mathias von Ottenbreit. APLR is often able to compete with tree-based methods on predictiveness, but unlike tree-based methods APLR is interpretable. Please see the [documentation](https://github.com/ottenbreit-data-science/aplr/tree/main/documentation) for more information. Links to published article: [https://link.springer.com/article/10.1007/s00180-024-01475-4](https://link.springer.com/article/10.1007/s00180-024-01475-4) and [https://rdcu.be/dz7bF](https://rdcu.be/dz7bF). More functionality has been added to APLR since the article was published.
|
|
22
|
+
Build predictive and interpretable parametric regression or classification machine learning models in Python based on the Automatic Piecewise Linear Regression (APLR) methodology developed by Mathias von Ottenbreit. APLR is often able to compete with tree-based methods on predictiveness, but unlike tree-based methods APLR is interpretable. Furthermore, APLR produces smoother predictions than tree-based methods. Please see the [documentation](https://github.com/ottenbreit-data-science/aplr/tree/main/documentation) for more information. Links to published article: [https://link.springer.com/article/10.1007/s00180-024-01475-4](https://link.springer.com/article/10.1007/s00180-024-01475-4) and [https://rdcu.be/dz7bF](https://rdcu.be/dz7bF). More functionality has been added to APLR since the article was published.
|
|
23
23
|
|
|
24
24
|
# How to install
|
|
25
25
|
***pip install aplr***
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
aplr_cpp.cp38-win32.pyd,sha256=5bJiuXAovtUdo5QEIStpK8qjs7gxi1VGc_wSoffEKjg,509952
|
|
2
|
+
aplr/__init__.py,sha256=oDFSgVytP_qQ8ilun6oHxKr-DYEeqjEQp5FciX45lls,21
|
|
3
|
+
aplr/aplr.py,sha256=Qc_n1PQ1dKqyIR9UXKi73fX6HBGpmu7fayZHJxxCTXA,26006
|
|
4
|
+
aplr-10.6.0.dist-info/LICENSE,sha256=YOMo-RaL4P7edMZGD96-NskKpxyMZdP3-WiiMMmihNk,1134
|
|
5
|
+
aplr-10.6.0.dist-info/METADATA,sha256=orPj166YzyjPQirasMrR-AUJn8nJrulSNHdi_YUvyDg,2166
|
|
6
|
+
aplr-10.6.0.dist-info/WHEEL,sha256=3szW57pNWqFVRic6Ma4o9j5UYGJmr9Fs-0ZX6rmK_Y4,95
|
|
7
|
+
aplr-10.6.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
8
|
+
aplr-10.6.0.dist-info/RECORD,,
|
aplr_cpp.cp38-win32.pyd
CHANGED
|
Binary file
|
aplr-10.5.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
aplr_cpp.cp38-win32.pyd,sha256=1KDaBP-eU7OzURkVc-IE1Kavl7-qpyzXi0NlA0fxLmU,509952
|
|
2
|
-
aplr/__init__.py,sha256=oDFSgVytP_qQ8ilun6oHxKr-DYEeqjEQp5FciX45lls,21
|
|
3
|
-
aplr/aplr.py,sha256=SHeyJWIPM_2GkD7cP-d-kPaPyki__7_wXe6SV1cYDSQ,23483
|
|
4
|
-
aplr-10.5.0.dist-info/LICENSE,sha256=YOMo-RaL4P7edMZGD96-NskKpxyMZdP3-WiiMMmihNk,1134
|
|
5
|
-
aplr-10.5.0.dist-info/METADATA,sha256=oISUqQCwsBAGazVcNyUL-Q58iSz09PchKv48WqwAF6Q,2093
|
|
6
|
-
aplr-10.5.0.dist-info/WHEEL,sha256=bWd3bUqn9udrzjSPEGyjFzalPqRpt8KhSyToGhtYrI8,95
|
|
7
|
-
aplr-10.5.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
8
|
-
aplr-10.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|