aplr 10.12.1__cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl → 10.13.0__cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.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.
- aplr/aplr.py +132 -1
- {aplr-10.12.1.dist-info → aplr-10.13.0.dist-info}/METADATA +11 -1
- aplr-10.13.0.dist-info/RECORD +8 -0
- aplr_cpp.cpython-39-i386-linux-gnu.so +0 -0
- aplr-10.12.1.dist-info/RECORD +0 -8
- {aplr-10.12.1.dist-info → aplr-10.13.0.dist-info}/WHEEL +0 -0
- {aplr-10.12.1.dist-info → aplr-10.13.0.dist-info}/licenses/LICENSE +0 -0
- {aplr-10.12.1.dist-info → aplr-10.13.0.dist-info}/top_level.txt +0 -0
aplr/aplr.py
CHANGED
|
@@ -315,6 +315,108 @@ class APLRRegressor:
|
|
|
315
315
|
def set_intercept(self, value: float):
|
|
316
316
|
self.APLRRegressor.set_intercept(value)
|
|
317
317
|
|
|
318
|
+
def plot_affiliation_shape(
|
|
319
|
+
self,
|
|
320
|
+
affiliation: str,
|
|
321
|
+
plot: bool = True,
|
|
322
|
+
save: bool = False,
|
|
323
|
+
path: str = "",
|
|
324
|
+
):
|
|
325
|
+
"""
|
|
326
|
+
Plots or saves the shape of a given unique term affiliation.
|
|
327
|
+
|
|
328
|
+
For main effects, it produces a line plot. For two-way interactions, it produces a heatmap.
|
|
329
|
+
Plotting for higher-order interactions is not supported.
|
|
330
|
+
|
|
331
|
+
:param affiliation: A string specifying which unique_term_affiliation to use.
|
|
332
|
+
:param plot: If True, displays the plot.
|
|
333
|
+
:param save: If True, saves the plot to a file.
|
|
334
|
+
:param path: The file path to save the plot. If empty and save is True, a default path will be used.
|
|
335
|
+
"""
|
|
336
|
+
try:
|
|
337
|
+
import pandas as pd
|
|
338
|
+
import matplotlib.pyplot as plt
|
|
339
|
+
except ImportError:
|
|
340
|
+
raise ImportError(
|
|
341
|
+
"pandas and matplotlib are required for plotting. Please install them."
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
all_affiliations = self.get_unique_term_affiliations()
|
|
345
|
+
if affiliation not in all_affiliations:
|
|
346
|
+
raise ValueError(
|
|
347
|
+
f"Affiliation '{affiliation}' not found in model. "
|
|
348
|
+
f"Available affiliations are: {all_affiliations}"
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
affiliation_index = all_affiliations.index(affiliation)
|
|
352
|
+
|
|
353
|
+
predictors_in_each_affiliation = (
|
|
354
|
+
self.get_base_predictors_in_each_unique_term_affiliation()
|
|
355
|
+
)
|
|
356
|
+
predictor_indexes_used = predictors_in_each_affiliation[affiliation_index]
|
|
357
|
+
|
|
358
|
+
shape = self.get_unique_term_affiliation_shape(affiliation)
|
|
359
|
+
if shape.shape[0] == 0:
|
|
360
|
+
print(f"No shape data available for affiliation '{affiliation}'.")
|
|
361
|
+
return
|
|
362
|
+
|
|
363
|
+
predictor_names = affiliation.split(" & ")
|
|
364
|
+
|
|
365
|
+
shape_df = pd.DataFrame(shape, columns=predictor_names + ["contribution"])
|
|
366
|
+
|
|
367
|
+
is_main_effect: bool = len(predictor_indexes_used) == 1
|
|
368
|
+
is_two_way_interaction: bool = len(predictor_indexes_used) == 2
|
|
369
|
+
|
|
370
|
+
if is_main_effect:
|
|
371
|
+
fig = plt.figure()
|
|
372
|
+
plt.plot(shape_df.iloc[:, 0], shape_df.iloc[:, 1])
|
|
373
|
+
plt.xlabel(shape_df.columns[0])
|
|
374
|
+
plt.ylabel("Contribution to linear predictor")
|
|
375
|
+
plt.title(f"Main effect of {shape_df.columns[0]}")
|
|
376
|
+
plt.grid(True)
|
|
377
|
+
elif is_two_way_interaction:
|
|
378
|
+
fig = plt.figure(figsize=(8, 6))
|
|
379
|
+
pivot_table = shape_df.pivot_table(
|
|
380
|
+
index=shape_df.columns[0],
|
|
381
|
+
columns=shape_df.columns[1],
|
|
382
|
+
values=shape_df.columns[2],
|
|
383
|
+
aggfunc="mean",
|
|
384
|
+
)
|
|
385
|
+
plt.imshow(
|
|
386
|
+
pivot_table.values,
|
|
387
|
+
aspect="auto",
|
|
388
|
+
origin="lower",
|
|
389
|
+
extent=[
|
|
390
|
+
pivot_table.columns.min(),
|
|
391
|
+
pivot_table.columns.max(),
|
|
392
|
+
pivot_table.index.min(),
|
|
393
|
+
pivot_table.index.max(),
|
|
394
|
+
],
|
|
395
|
+
cmap="Blues_r",
|
|
396
|
+
)
|
|
397
|
+
plt.colorbar(label="Contribution to the linear predictor")
|
|
398
|
+
plt.xlabel(shape_df.columns[1])
|
|
399
|
+
plt.ylabel(shape_df.columns[0])
|
|
400
|
+
plt.title(
|
|
401
|
+
f"Interaction between {shape_df.columns[0]} and {shape_df.columns[1]}"
|
|
402
|
+
)
|
|
403
|
+
else:
|
|
404
|
+
print(
|
|
405
|
+
f"Plotting for interaction level > 2 is not supported. Affiliation: {affiliation}"
|
|
406
|
+
)
|
|
407
|
+
return
|
|
408
|
+
|
|
409
|
+
if save:
|
|
410
|
+
save_path = (
|
|
411
|
+
path if path else f"shape_of_{affiliation.replace(' & ', '_')}.png"
|
|
412
|
+
)
|
|
413
|
+
plt.savefig(save_path)
|
|
414
|
+
|
|
415
|
+
if plot:
|
|
416
|
+
plt.show()
|
|
417
|
+
|
|
418
|
+
plt.close(fig)
|
|
419
|
+
|
|
318
420
|
def remove_provided_custom_functions(self):
|
|
319
421
|
self.APLRRegressor.remove_provided_custom_functions()
|
|
320
422
|
self.calculate_custom_validation_error_function = None
|
|
@@ -504,7 +606,36 @@ class APLRClassifier:
|
|
|
504
606
|
return self.APLRClassifier.get_categories()
|
|
505
607
|
|
|
506
608
|
def get_logit_model(self, category: str) -> APLRRegressor:
|
|
507
|
-
|
|
609
|
+
logit_model_cpp = self.APLRClassifier.get_logit_model(category)
|
|
610
|
+
|
|
611
|
+
logit_model_py = APLRRegressor(
|
|
612
|
+
m=self.m,
|
|
613
|
+
v=self.v,
|
|
614
|
+
random_state=self.random_state,
|
|
615
|
+
loss_function="binomial",
|
|
616
|
+
link_function="logit",
|
|
617
|
+
n_jobs=self.n_jobs,
|
|
618
|
+
cv_folds=self.cv_folds,
|
|
619
|
+
bins=self.bins,
|
|
620
|
+
max_interaction_level=self.max_interaction_level,
|
|
621
|
+
max_interactions=self.max_interactions,
|
|
622
|
+
min_observations_in_split=self.min_observations_in_split,
|
|
623
|
+
ineligible_boosting_steps_added=self.ineligible_boosting_steps_added,
|
|
624
|
+
max_eligible_terms=self.max_eligible_terms,
|
|
625
|
+
verbosity=self.verbosity,
|
|
626
|
+
boosting_steps_before_interactions_are_allowed=self.boosting_steps_before_interactions_are_allowed,
|
|
627
|
+
monotonic_constraints_ignore_interactions=self.monotonic_constraints_ignore_interactions,
|
|
628
|
+
early_stopping_rounds=self.early_stopping_rounds,
|
|
629
|
+
num_first_steps_with_linear_effects_only=self.num_first_steps_with_linear_effects_only,
|
|
630
|
+
penalty_for_non_linearity=self.penalty_for_non_linearity,
|
|
631
|
+
penalty_for_interactions=self.penalty_for_interactions,
|
|
632
|
+
max_terms=self.max_terms,
|
|
633
|
+
ridge_penalty=self.ridge_penalty,
|
|
634
|
+
)
|
|
635
|
+
|
|
636
|
+
logit_model_py.APLRRegressor = logit_model_cpp
|
|
637
|
+
|
|
638
|
+
return logit_model_py
|
|
508
639
|
|
|
509
640
|
def get_validation_error_steps(self) -> FloatMatrix:
|
|
510
641
|
return self.APLRClassifier.get_validation_error_steps()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aplr
|
|
3
|
-
Version: 10.
|
|
3
|
+
Version: 10.13.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
|
|
@@ -14,6 +14,9 @@ Requires-Python: >=3.8
|
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
Requires-Dist: numpy>=1.11
|
|
17
|
+
Provides-Extra: plots
|
|
18
|
+
Requires-Dist: pandas; extra == "plots"
|
|
19
|
+
Requires-Dist: matplotlib; extra == "plots"
|
|
17
20
|
Dynamic: author
|
|
18
21
|
Dynamic: author-email
|
|
19
22
|
Dynamic: classifier
|
|
@@ -23,6 +26,7 @@ Dynamic: home-page
|
|
|
23
26
|
Dynamic: license
|
|
24
27
|
Dynamic: license-file
|
|
25
28
|
Dynamic: platform
|
|
29
|
+
Dynamic: provides-extra
|
|
26
30
|
Dynamic: requires-dist
|
|
27
31
|
Dynamic: requires-python
|
|
28
32
|
Dynamic: summary
|
|
@@ -42,6 +46,12 @@ To install APLR, use the following command:
|
|
|
42
46
|
pip install aplr
|
|
43
47
|
```
|
|
44
48
|
|
|
49
|
+
To include dependencies for plotting, use this command instead:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install aplr[plots]
|
|
53
|
+
```
|
|
54
|
+
|
|
45
55
|
## Availability
|
|
46
56
|
APLR is available for Windows, most Linux distributions, and macOS.
|
|
47
57
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
aplr_cpp.cpython-39-i386-linux-gnu.so,sha256=xV5CIFZrVzCFDHLcRJ2f6hzWQjTFhzBMN_967kybI2A,32148264
|
|
2
|
+
aplr-10.13.0.dist-info/METADATA,sha256=T8C_-jreoBSoWJuQap5KassYfloS06hmEXKH5gdZxNw,2594
|
|
3
|
+
aplr-10.13.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
4
|
+
aplr-10.13.0.dist-info/WHEEL,sha256=fP3RXkZCZzBk2lCtKApSgTul3NFZw5foIJqL-i_vQLM,143
|
|
5
|
+
aplr-10.13.0.dist-info/RECORD,,
|
|
6
|
+
aplr-10.13.0.dist-info/licenses/LICENSE,sha256=g4qcQtkSVPHtGRi3T93DoFCrssvW6ij_emU-2fj_xfY,1113
|
|
7
|
+
aplr/__init__.py,sha256=rRfTgNWnYZlFatyA920lWqBcjwmQUI7FcvEPFUTJgzE,20
|
|
8
|
+
aplr/aplr.py,sha256=m1Lv4I_tWoWSUqOgXzrM4vFiPcvmGOBZ1XIw_8bkKiA,32299
|
|
Binary file
|
aplr-10.12.1.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
aplr_cpp.cpython-39-i386-linux-gnu.so,sha256=gG0K6RArLgJzObtj4NfmuRP8z-19GhePd01r4F8QZqU,32148264
|
|
2
|
-
aplr-10.12.1.dist-info/METADATA,sha256=W8PrVP-Gjop24f06L2ml5guAd0bHhP48y7uhIBErFi8,2362
|
|
3
|
-
aplr-10.12.1.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
4
|
-
aplr-10.12.1.dist-info/WHEEL,sha256=fP3RXkZCZzBk2lCtKApSgTul3NFZw5foIJqL-i_vQLM,143
|
|
5
|
-
aplr-10.12.1.dist-info/RECORD,,
|
|
6
|
-
aplr-10.12.1.dist-info/licenses/LICENSE,sha256=g4qcQtkSVPHtGRi3T93DoFCrssvW6ij_emU-2fj_xfY,1113
|
|
7
|
-
aplr/__init__.py,sha256=rRfTgNWnYZlFatyA920lWqBcjwmQUI7FcvEPFUTJgzE,20
|
|
8
|
-
aplr/aplr.py,sha256=Sgpwe0h22J_B8aZGK1uexgb1MVS_Pq4Ygr7YNj3kE_Q,27090
|
|
File without changes
|
|
File without changes
|
|
File without changes
|