lecrapaud 0.19.2__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 +3 -0
- lecrapaud/experiment.py +1 -1
- lecrapaud/model_selection.py +65 -5
- {lecrapaud-0.19.2.dist-info → lecrapaud-0.19.3.dist-info}/METADATA +1 -1
- {lecrapaud-0.19.2.dist-info → lecrapaud-0.19.3.dist-info}/RECORD +7 -7
- {lecrapaud-0.19.2.dist-info → lecrapaud-0.19.3.dist-info}/WHEEL +0 -0
- {lecrapaud-0.19.2.dist-info → lecrapaud-0.19.3.dist-info}/licenses/LICENSE +0 -0
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()
|
|
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)
|
lecrapaud/model_selection.py
CHANGED
|
@@ -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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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 =
|
|
304
|
-
return
|
|
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,5 +1,5 @@
|
|
|
1
1
|
lecrapaud/__init__.py,sha256=oCxbtw_nk8rlOXbXbWo0RRMlsh6w-hTiZ6e5PRG_wp0,28
|
|
2
|
-
lecrapaud/api.py,sha256=
|
|
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,7 +27,7 @@ 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=
|
|
30
|
+
lecrapaud/experiment.py,sha256=xj2DAzjWM-FiRcNS8PBE0VotUskKuN8ydMk6THhjGiA,2464
|
|
31
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
|
|
@@ -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=
|
|
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.
|
|
46
|
-
lecrapaud-0.19.
|
|
47
|
-
lecrapaud-0.19.
|
|
48
|
-
lecrapaud-0.19.
|
|
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,,
|
|
File without changes
|
|
File without changes
|