aplr 10.13.0__cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl → 10.14.0__cp313-cp313-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.

Potentially problematic release.


This version of aplr might be problematic. Click here for more details.

aplr/aplr.py CHANGED
@@ -334,12 +334,9 @@ class APLRRegressor:
334
334
  :param path: The file path to save the plot. If empty and save is True, a default path will be used.
335
335
  """
336
336
  try:
337
- import pandas as pd
338
337
  import matplotlib.pyplot as plt
339
338
  except ImportError:
340
- raise ImportError(
341
- "pandas and matplotlib are required for plotting. Please install them."
342
- )
339
+ raise ImportError("matplotlib is required for plotting. Please install it.")
343
340
 
344
341
  all_affiliations = self.get_unique_term_affiliations()
345
342
  if affiliation not in all_affiliations:
@@ -362,43 +359,55 @@ class APLRRegressor:
362
359
 
363
360
  predictor_names = affiliation.split(" & ")
364
361
 
365
- shape_df = pd.DataFrame(shape, columns=predictor_names + ["contribution"])
366
-
367
362
  is_main_effect: bool = len(predictor_indexes_used) == 1
368
363
  is_two_way_interaction: bool = len(predictor_indexes_used) == 2
369
364
 
370
365
  if is_main_effect:
371
366
  fig = plt.figure()
372
- plt.plot(shape_df.iloc[:, 0], shape_df.iloc[:, 1])
373
- plt.xlabel(shape_df.columns[0])
367
+ # Sort by predictor value for a clean line plot
368
+ sorted_indices = np.argsort(shape[:, 0])
369
+ plt.plot(shape[sorted_indices, 0], shape[sorted_indices, 1])
370
+ plt.xlabel(predictor_names[0])
374
371
  plt.ylabel("Contribution to linear predictor")
375
- plt.title(f"Main effect of {shape_df.columns[0]}")
372
+ plt.title(f"Main effect of {predictor_names[0]}")
376
373
  plt.grid(True)
377
374
  elif is_two_way_interaction:
378
375
  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
- )
376
+
377
+ # Get unique coordinates and their inverse mapping
378
+ y_unique, y_inv = np.unique(shape[:, 0], return_inverse=True)
379
+ x_unique, x_inv = np.unique(shape[:, 1], return_inverse=True)
380
+
381
+ # Create grid for sums and counts
382
+ grid_sums = np.zeros((len(y_unique), len(x_unique)))
383
+ grid_counts = np.zeros((len(y_unique), len(x_unique)))
384
+
385
+ # Populate sums and counts to later calculate the mean
386
+ np.add.at(grid_sums, (y_inv, x_inv), shape[:, 2])
387
+ np.add.at(grid_counts, (y_inv, x_inv), 1)
388
+
389
+ # Calculate mean, avoiding division by zero
390
+ with np.errstate(divide="ignore", invalid="ignore"):
391
+ pivot_table_values = np.true_divide(grid_sums, grid_counts)
392
+ # Where there's no data, pivot_table_values will be nan, which is fine for imshow.
393
+
385
394
  plt.imshow(
386
- pivot_table.values,
395
+ pivot_table_values,
387
396
  aspect="auto",
388
397
  origin="lower",
389
398
  extent=[
390
- pivot_table.columns.min(),
391
- pivot_table.columns.max(),
392
- pivot_table.index.min(),
393
- pivot_table.index.max(),
399
+ x_unique.min(),
400
+ x_unique.max(),
401
+ y_unique.min(),
402
+ y_unique.max(),
394
403
  ],
395
404
  cmap="Blues_r",
396
405
  )
397
406
  plt.colorbar(label="Contribution to the linear predictor")
398
- plt.xlabel(shape_df.columns[1])
399
- plt.ylabel(shape_df.columns[0])
407
+ plt.xlabel(predictor_names[1])
408
+ plt.ylabel(predictor_names[0])
400
409
  plt.title(
401
- f"Interaction between {shape_df.columns[0]} and {shape_df.columns[1]}"
410
+ f"Interaction between {predictor_names[0]} and {predictor_names[1]}"
402
411
  )
403
412
  else:
404
413
  print(
@@ -407,9 +416,7 @@ class APLRRegressor:
407
416
  return
408
417
 
409
418
  if save:
410
- save_path = (
411
- path if path else f"shape_of_{affiliation.replace(' & ', '_')}.png"
412
- )
419
+ save_path = path or f"shape_of_{affiliation.replace(' & ', '_')}.png"
413
420
  plt.savefig(save_path)
414
421
 
415
422
  if plot:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aplr
3
- Version: 10.13.0
3
+ Version: 10.14.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: pandas; extra == "plots"
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.cpython-313-i386-linux-gnu.so,sha256=vw95IKx3_Hm1ZxWBRdL7GPiCho0VHMQm6JyXK9X1CvA,32460276
2
+ aplr-10.14.0.dist-info/METADATA,sha256=mQHAdFrGE447S4f98ECp8T8VXyY2mPkMRbO8DvPxbWU,2559
3
+ aplr-10.14.0.dist-info/top_level.txt,sha256=DXVC0RIFGpzVnPeKWAZTXQdJheOEZL51Wip6Fx7zbR4,14
4
+ aplr-10.14.0.dist-info/WHEEL,sha256=ShVzVQkPfax84O2bLLrGj6PpG0rmzqLK0yFHdA32nOU,147
5
+ aplr-10.14.0.dist-info/RECORD,,
6
+ aplr-10.14.0.dist-info/licenses/LICENSE,sha256=g4qcQtkSVPHtGRi3T93DoFCrssvW6ij_emU-2fj_xfY,1113
7
+ aplr/__init__.py,sha256=rRfTgNWnYZlFatyA920lWqBcjwmQUI7FcvEPFUTJgzE,20
8
+ aplr/aplr.py,sha256=ZID8qOCi4UoE6sm9vSIUZvX1W1mrRsnzMacSOAhfl4Q,32828
Binary file
@@ -1,8 +0,0 @@
1
- aplr_cpp.cpython-313-i386-linux-gnu.so,sha256=rRWCgrID-lgusszTWNLXBqwxGZ6Bnae0LI4_CLTr6hY,32460276
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=ShVzVQkPfax84O2bLLrGj6PpG0rmzqLK0yFHdA32nOU,147
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
File without changes