lecrapaud 0.19.1__py3-none-any.whl → 0.19.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.

lecrapaud/api.py CHANGED
@@ -475,6 +475,9 @@ class ExperimentEngine:
475
475
  # For lightgbm models
476
476
  importances = model.feature_importance(importance_type="split")
477
477
  importance_type = "Split"
478
+ elif hasattr(model, "get_feature_importance"):
479
+ importances = model.get_feature_importance()
480
+ importance_type = "Feature importance"
478
481
  elif hasattr(model, "coef_"):
479
482
  # For linear models
480
483
  importances = np.abs(model.coef_.flatten())
lecrapaud/experiment.py CHANGED
@@ -35,7 +35,7 @@ def create_experiment(
35
35
  groups = {}
36
36
  if group_column:
37
37
  groups["number_of_groups"] = data[group_column].nunique()
38
- groups["list_of_groups"] = data[group_column].unique().tolist().sort()
38
+ groups["list_of_groups"] = sorted(data[group_column].unique().tolist())
39
39
 
40
40
  with get_db() as db:
41
41
  all_targets = Target.get_all(db=db)
@@ -629,6 +629,7 @@ class PreprocessFeature:
629
629
  """
630
630
 
631
631
  pcas_dict = {}
632
+ index_saved = df.index
632
633
 
633
634
  for pca_cross_sectional in self.pca_cross_sectional:
634
635
  name, index_col, columns_col, value_col = (
@@ -659,6 +660,7 @@ class PreprocessFeature:
659
660
  scores_df = pd.DataFrame(scores, index=pivot.index, columns=cols)
660
661
 
661
662
  df = df.merge(scores_df.reset_index(), on=index_col, how="left")
663
+ df.index = index_saved
662
664
  pcas_dict.update({name: pipe})
663
665
 
664
666
  return df, pcas_dict
@@ -110,6 +110,63 @@ def test_hardware():
110
110
  warnings.filterwarnings("ignore", category=UserWarning, module="pydantic")
111
111
 
112
112
 
113
+ class CatBoostWrapper:
114
+ """
115
+ Transparent proxy for a CatBoost model that accepts arbitrary keyword arguments
116
+ as direct attributes, while forwarding all method calls and properties.
117
+ """
118
+
119
+ __slots__ = ("_model", "_extra_attrs")
120
+
121
+ def __init__(self, model, **kwargs):
122
+ object.__setattr__(self, "_model", model)
123
+ object.__setattr__(self, "_extra_attrs", {})
124
+ # Register kwargs as direct attributes
125
+ for key, value in kwargs.items():
126
+ setattr(self, key, value)
127
+
128
+ # ---- Transparent access ----
129
+ def __getattr__(self, name):
130
+ """Forward attribute access to the underlying model if not found."""
131
+ model = object.__getattribute__(self, "_model")
132
+ if hasattr(model, name):
133
+ return getattr(model, name)
134
+ extra_attrs = object.__getattribute__(self, "_extra_attrs")
135
+ if name in extra_attrs:
136
+ return extra_attrs[name]
137
+ raise AttributeError(f"{type(self).__name__!r} has no attribute {name!r}")
138
+
139
+ def __setattr__(self, name, value):
140
+ """Set to wrapper or forward to model when appropriate."""
141
+ if name in CatBoostWrapper.__slots__:
142
+ object.__setattr__(self, name, value)
143
+ return
144
+
145
+ model = object.__getattribute__(self, "_model")
146
+ if hasattr(model, name):
147
+ setattr(model, name, value)
148
+ else:
149
+ extra_attrs = object.__getattribute__(self, "_extra_attrs")
150
+ extra_attrs[name] = value
151
+
152
+ def __dir__(self):
153
+ """Merge dir() from wrapper, model, and custom attributes."""
154
+ base = set(super().__dir__())
155
+ model_attrs = set(dir(object.__getattribute__(self, "_model")))
156
+ extra_attrs = set(object.__getattribute__(self, "_extra_attrs").keys())
157
+ return sorted(base | model_attrs | extra_attrs)
158
+
159
+ def __repr__(self):
160
+ model = object.__getattribute__(self, "_model")
161
+ extras = object.__getattribute__(self, "_extra_attrs")
162
+ return f"CatBoostWrapper(model={model.__class__.__name__}, extras={extras})"
163
+
164
+ @property
165
+ def model(self):
166
+ """Access the raw CatBoost model."""
167
+ return object.__getattribute__(self, "_model")
168
+
169
+
113
170
  class ModelEngine:
114
171
 
115
172
  def __init__(
@@ -296,12 +353,15 @@ class ModelEngine:
296
353
  )
297
354
 
298
355
  # Attach metadata for consistency with sklearn path
299
- model.model_name = self.model_name
300
- model.target_type = self.target_type
301
- logger.info(f"Successfully created a {model.model_name} at {datetime.now()}")
356
+ model_wrapped = CatBoostWrapper(
357
+ model, model_name=self.model_name, target_type=self.target_type
358
+ )
359
+ logger.info(
360
+ f"Successfully created a {model_wrapped.model_name} at {datetime.now()}"
361
+ )
302
362
 
303
- self._model = model
304
- return model
363
+ self._model = model_wrapped
364
+ return model_wrapped
305
365
 
306
366
  def fit_boosting(self, x_train, y_train, x_val, y_val, params):
307
367
  """
@@ -1,8 +1,9 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: lecrapaud
3
- Version: 0.19.1
3
+ Version: 0.19.3
4
4
  Summary: Framework for machine and deep learning, with regression, classification and time series analysis
5
5
  License: Apache License
6
+ License-File: LICENSE
6
7
  Author: Pierre H. Gallet
7
8
  Requires-Python: ==3.12.*
8
9
  Classifier: License :: Other/Proprietary License
@@ -1,5 +1,5 @@
1
1
  lecrapaud/__init__.py,sha256=oCxbtw_nk8rlOXbXbWo0RRMlsh6w-hTiZ6e5PRG_wp0,28
2
- lecrapaud/api.py,sha256=GsylHdScug-D8ePbPKo5r7Wa0myj9Ol0OqNwlNsbgs8,22518
2
+ lecrapaud/api.py,sha256=xPa8GG5o9ngjJaGgBWhojzGzRq1tbFL5nsCv5U1Ehjw,22681
3
3
  lecrapaud/config.py,sha256=itiqC31HB8i2Xo-kn2viCQrg_9tnA07-TJuZ-xdnx44,1126
4
4
  lecrapaud/db/__init__.py,sha256=82o9fMfaqKXPh2_rt44EzNRVZV1R4LScEnQYvj_TjK0,34
5
5
  lecrapaud/db/alembic/README,sha256=MVlc9TYmr57RbhXET6QxgyCcwWP7w-vLkEsirENqiIQ,38
@@ -27,8 +27,8 @@ lecrapaud/db/models/target.py,sha256=DKnfeaLU8eT8J_oh_vuFo5-o1CaoXR13xBbswme6Bgk
27
27
  lecrapaud/db/models/utils.py,sha256=-a-nWWmpJ2XzidIxo2COVUTrGZIPYCfBzjhcszJj_bM,1109
28
28
  lecrapaud/db/session.py,sha256=87W5AkGRYu8b2rF5FNQ0MFC6wtGc-gGagNJQN_0vnDQ,3667
29
29
  lecrapaud/directories.py,sha256=0LrANuDgbuneSLker60c6q2hmGnQ3mKHIztTGzTx6Gw,826
30
- lecrapaud/experiment.py,sha256=1xLWjOrqAxJh9CdXOx9ppQuRFRRj0GH-xYZqg-ty9hI,2463
31
- lecrapaud/feature_engineering.py,sha256=ib1afBrwqePiXUaw0Cpe6hY3VNl5afg8YVntb88SCT4,39199
30
+ lecrapaud/experiment.py,sha256=xj2DAzjWM-FiRcNS8PBE0VotUskKuN8ydMk6THhjGiA,2464
31
+ lecrapaud/feature_engineering.py,sha256=aeK58ahZXFY8AoLiNM2HVBflF9V-E4dUT6XhzHpk2Cs,39265
32
32
  lecrapaud/feature_selection.py,sha256=6ry-oVPQHbipm1XSE5YsH7AY0lQFt4CFbWiHiRs1nxg,43593
33
33
  lecrapaud/integrations/openai_integration.py,sha256=hHLF3fk5Bps8KNbNrEL3NUFa945jwClE6LrLpuMZOd4,7459
34
34
  lecrapaud/jobs/__init__.py,sha256=ZkrsyTOR21c_wN7RY8jPhm8jCrL1oCEtTsf3VFIlQiE,292
@@ -39,10 +39,10 @@ lecrapaud/misc/tabpfn_tests.ipynb,sha256=VkgsCUJ30d8jaL2VaWtQAgb8ngHPNtPgnXLs7QQ
39
39
  lecrapaud/misc/test-gpu-bilstm.ipynb,sha256=4nLuZRJVe2kn6kEmauhRiz5wkWT9AVrYhI9CEk_dYUY,9608
40
40
  lecrapaud/misc/test-gpu-resnet.ipynb,sha256=27Vu7nYwujYeh3fOxBNCnKJn3MXNPKZU-U8oDDUbymg,4944
41
41
  lecrapaud/misc/test-gpu-transformers.ipynb,sha256=k6MBSs_Um1h4PykvE-LTBcdpbWLbIFST_xl_AFW2jgI,8444
42
- lecrapaud/model_selection.py,sha256=z6sMU6ZGaymZOWdJehPw4yaWdzcYTABWweyH5LvCJwk,76980
42
+ lecrapaud/model_selection.py,sha256=tspBjam6FopIwe-7oYaAahr9MTEBz_OJhT6c6dQhmo0,79259
43
43
  lecrapaud/search_space.py,sha256=FCIEHZBK1pUQ4CphJuxwXY2N_BdrCelRzHsCXnNLlVI,36334
44
44
  lecrapaud/utils.py,sha256=ATKu9pbXjYFRa2YzBYjqyLHJrzfnZ7SJrOD_qAnEBYE,8242
45
- lecrapaud-0.19.1.dist-info/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
46
- lecrapaud-0.19.1.dist-info/METADATA,sha256=9wZednrJcXhbqdRGBLxo7pZnm78d8M2Z8lI34wJtR3o,11115
47
- lecrapaud-0.19.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
48
- lecrapaud-0.19.1.dist-info/RECORD,,
45
+ lecrapaud-0.19.3.dist-info/METADATA,sha256=Tm3AmZ3FyxgGxEA9zsa-6CjTHI2V4xYM_pw8fRKczko,11137
46
+ lecrapaud-0.19.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
47
+ lecrapaud-0.19.3.dist-info/licenses/LICENSE,sha256=MImCryu0AnqhJE_uAZD-PIDKXDKb8sT7v0i1NOYeHTM,11350
48
+ lecrapaud-0.19.3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any