lecrapaud 0.18.1__py3-none-any.whl → 0.18.3__py3-none-any.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 lecrapaud might be problematic. Click here for more details.

@@ -220,7 +220,7 @@ class FeatureEngineeringEngine:
220
220
  Returns:
221
221
  pd.DataFrame: Original dataframe with new encoded columns added
222
222
  """
223
-
223
+ # TODO: target encoding needs to be fit / transform based at inference time.
224
224
  df: pd.DataFrame = self.data
225
225
  columns_te_groupby: list[list[str]] = self.columns_te_groupby
226
226
  columns_te_target: list[str] = self.columns_te_target
@@ -231,6 +231,9 @@ class FeatureEngineeringEngine:
231
231
  for group_cols, stat, target_col in product(
232
232
  columns_te_groupby, statistics, columns_te_target
233
233
  ):
234
+ df[target_col] = pd.to_numeric(
235
+ df[target_col].replace("", "0"), errors="coerce"
236
+ ).fillna(0)
234
237
  col_name = f"{target_col}_{'_'.join(group_cols)}_{stat.upper()}"
235
238
  new_feature_cols[col_name] = df.groupby(group_cols)[target_col].transform(
236
239
  stat
@@ -12,6 +12,7 @@ import glob
12
12
  from pathlib import Path
13
13
  import pickle
14
14
  from pydantic import BaseModel
15
+ import ast
15
16
 
16
17
  os.environ["COVERAGE_FILE"] = str(Path(".coverage").resolve())
17
18
 
@@ -122,6 +123,7 @@ class ModelEngine:
122
123
  plot: bool = False,
123
124
  log_dir: str = None,
124
125
  ):
126
+ self.threshold = None
125
127
  self.path = path
126
128
  if path:
127
129
  self.load()
@@ -152,8 +154,6 @@ class ModelEngine:
152
154
  else:
153
155
  self.scaler_y = None
154
156
 
155
- self.threshold = None
156
-
157
157
  def fit(self, *args):
158
158
  if self.recurrent:
159
159
  fit = self.fit_recurrent
@@ -1070,7 +1070,7 @@ class ModelSelectionEngine:
1070
1070
  best_score_overall = scores_tracking.iloc[0, :]
1071
1071
  best_model_name = best_score_overall["MODEL_NAME"]
1072
1072
  if self.target_type == "classification":
1073
- best_thresholds = best_score_overall["THRESHOLDS"]
1073
+ best_thresholds = ast.literal_eval(best_score_overall["THRESHOLDS"])
1074
1074
  joblib.dump(best_thresholds, f"{self.target_dir}/thresholds.pkl")
1075
1075
  else:
1076
1076
  best_thresholds = None
@@ -1852,7 +1852,9 @@ def apply_thresholds(
1852
1852
  """
1853
1853
 
1854
1854
  # Case 1: Per-class thresholds
1855
- if isinstance(threshold, dict):
1855
+ if not isinstance(threshold, int):
1856
+ if isinstance(threshold, str):
1857
+ threshold = ast.literal_eval(threshold)
1856
1858
  class_predictions = []
1857
1859
  class_probabilities = []
1858
1860
 
@@ -1862,6 +1864,7 @@ def apply_thresholds(
1862
1864
  metrics.get("threshold") if isinstance(metrics, dict) else metrics[0]
1863
1865
  )
1864
1866
  if _threshold is not None:
1867
+ class_label = int(class_label)
1865
1868
  if class_label not in pred_proba.columns:
1866
1869
  continue # skip missing class
1867
1870
  col = pred_proba[class_label]
lecrapaud/utils.py CHANGED
@@ -10,21 +10,27 @@ import unicodedata
10
10
  import re
11
11
  import string
12
12
  import sys
13
+ import tomllib
14
+
13
15
  from lecrapaud.directories import logger_dir
14
16
  from lecrapaud.config import LOGGING_LEVEL, PYTHON_ENV, LECRAPAUD_LOCAL
15
17
 
18
+
16
19
  _LECRAPAUD_LOGGER_ALREADY_CONFIGURED = False
17
20
 
18
21
 
19
22
  def setup_logger():
20
23
 
24
+ with open("pyproject.toml", "rb") as f:
25
+ pyproject_data = tomllib.load(f)
26
+ name = pyproject_data["project"]["name"]
27
+
21
28
  global _LECRAPAUD_LOGGER_ALREADY_CONFIGURED
22
29
  if _LECRAPAUD_LOGGER_ALREADY_CONFIGURED: # ← bail out if done before
23
-
24
- return logging.getLogger("lecrapaud" if PYTHON_ENV != "Worker" else "")
30
+ return logging.getLogger(name if PYTHON_ENV != "Worker" else "")
25
31
 
26
32
  print(
27
- f"Setting up logger lecrapaud with PYTHON_ENV {PYTHON_ENV} and LOGGING_LEVEL {LOGGING_LEVEL}"
33
+ f"Setting up logger for {name} with PYTHON_ENV {PYTHON_ENV} and LOGGING_LEVEL {LOGGING_LEVEL}"
28
34
  )
29
35
  # ------------------------------------------------------------------ #
30
36
  # Real configuration happens only on the FIRST call #
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lecrapaud
3
- Version: 0.18.1
3
+ Version: 0.18.3
4
4
  Summary: Framework for machine and deep learning, with regression, classification and time series analysis
5
5
  License: Apache License
6
6
  Author: Pierre H. Gallet
@@ -26,7 +26,7 @@ lecrapaud/db/models/utils.py,sha256=-a-nWWmpJ2XzidIxo2COVUTrGZIPYCfBzjhcszJj_bM,
26
26
  lecrapaud/db/session.py,sha256=E93WXcFFILFAIeH61ft2Egs7D-6caqs0oi4zCkO5Lq4,2822
27
27
  lecrapaud/directories.py,sha256=0LrANuDgbuneSLker60c6q2hmGnQ3mKHIztTGzTx6Gw,826
28
28
  lecrapaud/experiment.py,sha256=1xLWjOrqAxJh9CdXOx9ppQuRFRRj0GH-xYZqg-ty9hI,2463
29
- lecrapaud/feature_engineering.py,sha256=ey46MqXBC-c-BS6nRA7zo8uafxmDABy5ThIyTfmXoSo,38982
29
+ lecrapaud/feature_engineering.py,sha256=ib1afBrwqePiXUaw0Cpe6hY3VNl5afg8YVntb88SCT4,39199
30
30
  lecrapaud/feature_selection.py,sha256=6ry-oVPQHbipm1XSE5YsH7AY0lQFt4CFbWiHiRs1nxg,43593
31
31
  lecrapaud/integrations/openai_integration.py,sha256=hHLF3fk5Bps8KNbNrEL3NUFa945jwClE6LrLpuMZOd4,7459
32
32
  lecrapaud/jobs/__init__.py,sha256=ZkrsyTOR21c_wN7RY8jPhm8jCrL1oCEtTsf3VFIlQiE,292
@@ -37,10 +37,10 @@ lecrapaud/misc/tabpfn_tests.ipynb,sha256=VkgsCUJ30d8jaL2VaWtQAgb8ngHPNtPgnXLs7QQ
37
37
  lecrapaud/misc/test-gpu-bilstm.ipynb,sha256=4nLuZRJVe2kn6kEmauhRiz5wkWT9AVrYhI9CEk_dYUY,9608
38
38
  lecrapaud/misc/test-gpu-resnet.ipynb,sha256=27Vu7nYwujYeh3fOxBNCnKJn3MXNPKZU-U8oDDUbymg,4944
39
39
  lecrapaud/misc/test-gpu-transformers.ipynb,sha256=k6MBSs_Um1h4PykvE-LTBcdpbWLbIFST_xl_AFW2jgI,8444
40
- lecrapaud/model_selection.py,sha256=QOwOsn1WEBzR-2ZpHvhzv9Qz47delkBdNziHy-auY3o,72302
40
+ lecrapaud/model_selection.py,sha256=WbFn4wiykD8DOJ_7OsZLoocp-q4GDzW0dXCf-hHhl74,72471
41
41
  lecrapaud/search_space.py,sha256=-JkzuMhaomdwiWi4HvVQY5hiw3-oREemJA16tbwEIp4,34854
42
- lecrapaud/utils.py,sha256=g5ZbULUpgUqmKHO4vqjIS6BYlZ9MjQn5cts0GHqiejM,8234
43
- lecrapaud-0.18.1.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
44
- lecrapaud-0.18.1.dist-info/METADATA,sha256=wNG11NG_K0VHJbu4T47Zlh0eam6bxR0JqLc40d_QIjI,11081
45
- lecrapaud-0.18.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
- lecrapaud-0.18.1.dist-info/RECORD,,
42
+ lecrapaud/utils.py,sha256=eMnNVKWTqzXCLaaxSbKLBrThkOWoJrieifr9PNqFD5Y,8375
43
+ lecrapaud-0.18.3.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
44
+ lecrapaud-0.18.3.dist-info/METADATA,sha256=RYBX8NxcLXMDYU4FDkkZW9iIynfLqmpkQd9FozyFPzQ,11081
45
+ lecrapaud-0.18.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
46
+ lecrapaud-0.18.3.dist-info/RECORD,,