aplr 10.13.0__cp310-cp310-win_amd64.whl → 10.15.0__cp310-cp310-win_amd64.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 +37 -26
- {aplr-10.13.0.dist-info → aplr-10.15.0.dist-info}/METADATA +2 -3
- aplr-10.15.0.dist-info/RECORD +8 -0
- aplr_cpp.cp310-win_amd64.pyd +0 -0
- aplr-10.13.0.dist-info/RECORD +0 -8
- {aplr-10.13.0.dist-info → aplr-10.15.0.dist-info}/WHEEL +0 -0
- {aplr-10.13.0.dist-info → aplr-10.15.0.dist-info}/licenses/LICENSE +0 -0
- {aplr-10.13.0.dist-info → aplr-10.15.0.dist-info}/top_level.txt +0 -0
aplr/aplr.py
CHANGED
|
@@ -75,6 +75,7 @@ class APLRRegressor:
|
|
|
75
75
|
penalty_for_interactions: float = 0.0,
|
|
76
76
|
max_terms: int = 0,
|
|
77
77
|
ridge_penalty: float = 0.0001,
|
|
78
|
+
mean_bias_correction: bool = False,
|
|
78
79
|
):
|
|
79
80
|
self.m = m
|
|
80
81
|
self.v = v
|
|
@@ -122,6 +123,7 @@ class APLRRegressor:
|
|
|
122
123
|
self.penalty_for_interactions = penalty_for_interactions
|
|
123
124
|
self.max_terms = max_terms
|
|
124
125
|
self.ridge_penalty = ridge_penalty
|
|
126
|
+
self.mean_bias_correction = mean_bias_correction
|
|
125
127
|
|
|
126
128
|
# Creating aplr_cpp and setting parameters
|
|
127
129
|
self.APLRRegressor = aplr_cpp.APLRRegressor()
|
|
@@ -183,6 +185,7 @@ class APLRRegressor:
|
|
|
183
185
|
self.APLRRegressor.penalty_for_interactions = self.penalty_for_interactions
|
|
184
186
|
self.APLRRegressor.max_terms = self.max_terms
|
|
185
187
|
self.APLRRegressor.ridge_penalty = self.ridge_penalty
|
|
188
|
+
self.APLRRegressor.mean_bias_correction = self.mean_bias_correction
|
|
186
189
|
|
|
187
190
|
def fit(
|
|
188
191
|
self,
|
|
@@ -334,12 +337,9 @@ class APLRRegressor:
|
|
|
334
337
|
:param path: The file path to save the plot. If empty and save is True, a default path will be used.
|
|
335
338
|
"""
|
|
336
339
|
try:
|
|
337
|
-
import pandas as pd
|
|
338
340
|
import matplotlib.pyplot as plt
|
|
339
341
|
except ImportError:
|
|
340
|
-
raise ImportError(
|
|
341
|
-
"pandas and matplotlib are required for plotting. Please install them."
|
|
342
|
-
)
|
|
342
|
+
raise ImportError("matplotlib is required for plotting. Please install it.")
|
|
343
343
|
|
|
344
344
|
all_affiliations = self.get_unique_term_affiliations()
|
|
345
345
|
if affiliation not in all_affiliations:
|
|
@@ -362,43 +362,55 @@ class APLRRegressor:
|
|
|
362
362
|
|
|
363
363
|
predictor_names = affiliation.split(" & ")
|
|
364
364
|
|
|
365
|
-
shape_df = pd.DataFrame(shape, columns=predictor_names + ["contribution"])
|
|
366
|
-
|
|
367
365
|
is_main_effect: bool = len(predictor_indexes_used) == 1
|
|
368
366
|
is_two_way_interaction: bool = len(predictor_indexes_used) == 2
|
|
369
367
|
|
|
370
368
|
if is_main_effect:
|
|
371
369
|
fig = plt.figure()
|
|
372
|
-
|
|
373
|
-
|
|
370
|
+
# Sort by predictor value for a clean line plot
|
|
371
|
+
sorted_indices = np.argsort(shape[:, 0])
|
|
372
|
+
plt.plot(shape[sorted_indices, 0], shape[sorted_indices, 1])
|
|
373
|
+
plt.xlabel(predictor_names[0])
|
|
374
374
|
plt.ylabel("Contribution to linear predictor")
|
|
375
|
-
plt.title(f"Main effect of {
|
|
375
|
+
plt.title(f"Main effect of {predictor_names[0]}")
|
|
376
376
|
plt.grid(True)
|
|
377
377
|
elif is_two_way_interaction:
|
|
378
378
|
fig = plt.figure(figsize=(8, 6))
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
379
|
+
|
|
380
|
+
# Get unique coordinates and their inverse mapping
|
|
381
|
+
y_unique, y_inv = np.unique(shape[:, 0], return_inverse=True)
|
|
382
|
+
x_unique, x_inv = np.unique(shape[:, 1], return_inverse=True)
|
|
383
|
+
|
|
384
|
+
# Create grid for sums and counts
|
|
385
|
+
grid_sums = np.zeros((len(y_unique), len(x_unique)))
|
|
386
|
+
grid_counts = np.zeros((len(y_unique), len(x_unique)))
|
|
387
|
+
|
|
388
|
+
# Populate sums and counts to later calculate the mean
|
|
389
|
+
np.add.at(grid_sums, (y_inv, x_inv), shape[:, 2])
|
|
390
|
+
np.add.at(grid_counts, (y_inv, x_inv), 1)
|
|
391
|
+
|
|
392
|
+
# Calculate mean, avoiding division by zero
|
|
393
|
+
with np.errstate(divide="ignore", invalid="ignore"):
|
|
394
|
+
pivot_table_values = np.true_divide(grid_sums, grid_counts)
|
|
395
|
+
# Where there's no data, pivot_table_values will be nan, which is fine for imshow.
|
|
396
|
+
|
|
385
397
|
plt.imshow(
|
|
386
|
-
|
|
398
|
+
pivot_table_values,
|
|
387
399
|
aspect="auto",
|
|
388
400
|
origin="lower",
|
|
389
401
|
extent=[
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
402
|
+
x_unique.min(),
|
|
403
|
+
x_unique.max(),
|
|
404
|
+
y_unique.min(),
|
|
405
|
+
y_unique.max(),
|
|
394
406
|
],
|
|
395
407
|
cmap="Blues_r",
|
|
396
408
|
)
|
|
397
409
|
plt.colorbar(label="Contribution to the linear predictor")
|
|
398
|
-
plt.xlabel(
|
|
399
|
-
plt.ylabel(
|
|
410
|
+
plt.xlabel(predictor_names[1])
|
|
411
|
+
plt.ylabel(predictor_names[0])
|
|
400
412
|
plt.title(
|
|
401
|
-
f"Interaction between {
|
|
413
|
+
f"Interaction between {predictor_names[0]} and {predictor_names[1]}"
|
|
402
414
|
)
|
|
403
415
|
else:
|
|
404
416
|
print(
|
|
@@ -407,9 +419,7 @@ class APLRRegressor:
|
|
|
407
419
|
return
|
|
408
420
|
|
|
409
421
|
if save:
|
|
410
|
-
save_path = (
|
|
411
|
-
path if path else f"shape_of_{affiliation.replace(' & ', '_')}.png"
|
|
412
|
-
)
|
|
422
|
+
save_path = path or f"shape_of_{affiliation.replace(' & ', '_')}.png"
|
|
413
423
|
plt.savefig(save_path)
|
|
414
424
|
|
|
415
425
|
if plot:
|
|
@@ -458,6 +468,7 @@ class APLRRegressor:
|
|
|
458
468
|
"penalty_for_interactions": self.penalty_for_interactions,
|
|
459
469
|
"max_terms": self.max_terms,
|
|
460
470
|
"ridge_penalty": self.ridge_penalty,
|
|
471
|
+
"mean_bias_correction": self.mean_bias_correction,
|
|
461
472
|
}
|
|
462
473
|
|
|
463
474
|
# For sklearn
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aplr
|
|
3
|
-
Version: 10.
|
|
3
|
+
Version: 10.15.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
|
|
@@ -15,8 +15,7 @@ Description-Content-Type: text/markdown
|
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
Requires-Dist: numpy>=1.11
|
|
17
17
|
Provides-Extra: plots
|
|
18
|
-
Requires-Dist:
|
|
19
|
-
Requires-Dist: matplotlib; extra == "plots"
|
|
18
|
+
Requires-Dist: matplotlib>=3.0; extra == "plots"
|
|
20
19
|
Dynamic: author
|
|
21
20
|
Dynamic: author-email
|
|
22
21
|
Dynamic: classifier
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
aplr_cpp.cp310-win_amd64.pyd,sha256=gGn3FH67Yzpn1StyJzhWQCOEAaEpIMMWVLb4roR5yhU,636928
|
|
2
|
+
aplr/__init__.py,sha256=oDFSgVytP_qQ8ilun6oHxKr-DYEeqjEQp5FciX45lls,21
|
|
3
|
+
aplr/aplr.py,sha256=hGxqgMt6sUBi3P18W0p_Q88qqHsKX7wxpm1iQFw5Rig,33072
|
|
4
|
+
aplr-10.15.0.dist-info/licenses/LICENSE,sha256=YOMo-RaL4P7edMZGD96-NskKpxyMZdP3-WiiMMmihNk,1134
|
|
5
|
+
aplr-10.15.0.dist-info/METADATA,sha256=2JIO-RGn0S7aMiPlatABLlWNAUB0g6Lr0PHuXCjdj6M,2627
|
|
6
|
+
aplr-10.15.0.dist-info/WHEEL,sha256=KUuBC6lxAbHCKilKua8R9W_TM71_-9Sg5uEP3uDWcoU,101
|
|
7
|
+
aplr-10.15.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
8
|
+
aplr-10.15.0.dist-info/RECORD,,
|
aplr_cpp.cp310-win_amd64.pyd
CHANGED
|
Binary file
|
aplr-10.13.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
aplr_cpp.cp310-win_amd64.pyd,sha256=Ppxk0ZYVz2GVHsxoNCvnAvzDrRt5pS7a7XIEkvZtP7Q,632832
|
|
2
|
-
aplr/__init__.py,sha256=oDFSgVytP_qQ8ilun6oHxKr-DYEeqjEQp5FciX45lls,21
|
|
3
|
-
aplr/aplr.py,sha256=m1Lv4I_tWoWSUqOgXzrM4vFiPcvmGOBZ1XIw_8bkKiA,32299
|
|
4
|
-
aplr-10.13.0.dist-info/licenses/LICENSE,sha256=YOMo-RaL4P7edMZGD96-NskKpxyMZdP3-WiiMMmihNk,1134
|
|
5
|
-
aplr-10.13.0.dist-info/METADATA,sha256=0xM0tJ0OrzMJrarG-eN8nKFAFFrGKLbRL63kOBMNo8M,2663
|
|
6
|
-
aplr-10.13.0.dist-info/WHEEL,sha256=KUuBC6lxAbHCKilKua8R9W_TM71_-9Sg5uEP3uDWcoU,101
|
|
7
|
-
aplr-10.13.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
|
|
8
|
-
aplr-10.13.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|