autoforge-engine 0.1.0__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.
- autoforge_engine-0.1.0.dist-info/METADATA +105 -0
- autoforge_engine-0.1.0.dist-info/RECORD +32 -0
- autoforge_engine-0.1.0.dist-info/WHEEL +5 -0
- autoforge_engine-0.1.0.dist-info/entry_points.txt +2 -0
- autoforge_engine-0.1.0.dist-info/licenses/LICENSE +0 -0
- autoforge_engine-0.1.0.dist-info/top_level.txt +1 -0
- modelforge/artifact_manager.py +485 -0
- modelforge/automl.py +1472 -0
- modelforge/cli.py +1258 -0
- modelforge/column_intelligence.py +404 -0
- modelforge/config.py +580 -0
- modelforge/cross_validation.py +749 -0
- modelforge/data_audit.py +392 -0
- modelforge/data_loader.py +76 -0
- modelforge/evaluation.py +397 -0
- modelforge/experiment_tracker.py +490 -0
- modelforge/explainability.py +346 -0
- modelforge/feature_engineering.py +393 -0
- modelforge/feature_selection.py +528 -0
- modelforge/hyperparameter_optimization.py +593 -0
- modelforge/model_registry.py +684 -0
- modelforge/model_screening.py +531 -0
- modelforge/persistence.py +456 -0
- modelforge/pipeline_generator.py +278 -0
- modelforge/prediction_validator.py +316 -0
- modelforge/preprocessing.py +179 -0
- modelforge/profiler.py +85 -0
- modelforge/ranking.py +351 -0
- modelforge/reproducibility.py +295 -0
- modelforge/reproducibility_integration.py +192 -0
- modelforge/run_manager.py +200 -0
- modelforge/target_selector.py +108 -0
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any, Type
|
|
5
|
+
|
|
6
|
+
from sklearn.base import BaseEstimator
|
|
7
|
+
from sklearn.ensemble import (
|
|
8
|
+
ExtraTreesClassifier,
|
|
9
|
+
ExtraTreesRegressor,
|
|
10
|
+
GradientBoostingClassifier,
|
|
11
|
+
GradientBoostingRegressor,
|
|
12
|
+
RandomForestClassifier,
|
|
13
|
+
RandomForestRegressor,
|
|
14
|
+
)
|
|
15
|
+
from sklearn.linear_model import (
|
|
16
|
+
ElasticNet,
|
|
17
|
+
Lasso,
|
|
18
|
+
LinearRegression,
|
|
19
|
+
LogisticRegression,
|
|
20
|
+
Ridge,
|
|
21
|
+
)
|
|
22
|
+
from sklearn.neighbors import (
|
|
23
|
+
KNeighborsClassifier,
|
|
24
|
+
KNeighborsRegressor,
|
|
25
|
+
)
|
|
26
|
+
from sklearn.svm import (
|
|
27
|
+
SVC,
|
|
28
|
+
SVR,
|
|
29
|
+
)
|
|
30
|
+
from sklearn.tree import (
|
|
31
|
+
DecisionTreeClassifier,
|
|
32
|
+
DecisionTreeRegressor,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class ModelSpec:
|
|
38
|
+
"""
|
|
39
|
+
Metadata describing a machine-learning model.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
name: str
|
|
43
|
+
estimator: Type[BaseEstimator]
|
|
44
|
+
task_type: str
|
|
45
|
+
category: str
|
|
46
|
+
requires_scaling: bool = False
|
|
47
|
+
supports_probability: bool = False
|
|
48
|
+
default_params: dict[str, Any] = field(
|
|
49
|
+
default_factory=dict
|
|
50
|
+
)
|
|
51
|
+
hyperparameter_space: dict[str, Any] = field(
|
|
52
|
+
default_factory=dict
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def validate(self) -> None:
|
|
56
|
+
"""Validate the model specification."""
|
|
57
|
+
|
|
58
|
+
if not self.name.strip():
|
|
59
|
+
raise ValueError(
|
|
60
|
+
"Model name cannot be empty."
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
if self.task_type not in {
|
|
64
|
+
"regression",
|
|
65
|
+
"classification",
|
|
66
|
+
}:
|
|
67
|
+
raise ValueError(
|
|
68
|
+
"task_type must be 'regression' or 'classification'."
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
if not self.category.strip():
|
|
72
|
+
raise ValueError(
|
|
73
|
+
"Model category cannot be empty."
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if not isinstance(
|
|
77
|
+
self.default_params,
|
|
78
|
+
dict,
|
|
79
|
+
):
|
|
80
|
+
raise TypeError(
|
|
81
|
+
"default_params must be a dictionary."
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if not isinstance(
|
|
85
|
+
self.hyperparameter_space,
|
|
86
|
+
dict,
|
|
87
|
+
):
|
|
88
|
+
raise TypeError(
|
|
89
|
+
"hyperparameter_space must be a dictionary."
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class ModelRegistry:
|
|
94
|
+
"""
|
|
95
|
+
Central registry of models supported by ModelForge.
|
|
96
|
+
|
|
97
|
+
The registry provides model metadata, estimator creation,
|
|
98
|
+
task-based filtering, category filtering, and capability
|
|
99
|
+
discovery for the AutoML pipeline.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def __init__(self):
|
|
103
|
+
self._models = self._build_registry()
|
|
104
|
+
|
|
105
|
+
for spec in self._models.values():
|
|
106
|
+
spec.validate()
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def _build_registry() -> dict[str, ModelSpec]:
|
|
110
|
+
"""Build the default ModelForge model registry."""
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
"linear_regression": ModelSpec(
|
|
114
|
+
name="Linear Regression",
|
|
115
|
+
estimator=LinearRegression,
|
|
116
|
+
task_type="regression",
|
|
117
|
+
category="linear",
|
|
118
|
+
requires_scaling=False,
|
|
119
|
+
default_params={},
|
|
120
|
+
hyperparameter_space={},
|
|
121
|
+
),
|
|
122
|
+
"ridge": ModelSpec(
|
|
123
|
+
name="Ridge Regression",
|
|
124
|
+
estimator=Ridge,
|
|
125
|
+
task_type="regression",
|
|
126
|
+
category="linear",
|
|
127
|
+
requires_scaling=True,
|
|
128
|
+
default_params={
|
|
129
|
+
"alpha": 1.0,
|
|
130
|
+
},
|
|
131
|
+
hyperparameter_space={
|
|
132
|
+
"alpha": [
|
|
133
|
+
0.01,
|
|
134
|
+
0.1,
|
|
135
|
+
1.0,
|
|
136
|
+
10.0,
|
|
137
|
+
100.0,
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
),
|
|
141
|
+
"lasso": ModelSpec(
|
|
142
|
+
name="Lasso Regression",
|
|
143
|
+
estimator=Lasso,
|
|
144
|
+
task_type="regression",
|
|
145
|
+
category="linear",
|
|
146
|
+
requires_scaling=True,
|
|
147
|
+
default_params={
|
|
148
|
+
"alpha": 1.0,
|
|
149
|
+
},
|
|
150
|
+
hyperparameter_space={
|
|
151
|
+
"alpha": [
|
|
152
|
+
0.001,
|
|
153
|
+
0.01,
|
|
154
|
+
0.1,
|
|
155
|
+
1.0,
|
|
156
|
+
10.0,
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
),
|
|
160
|
+
"elasticnet": ModelSpec(
|
|
161
|
+
name="ElasticNet",
|
|
162
|
+
estimator=ElasticNet,
|
|
163
|
+
task_type="regression",
|
|
164
|
+
category="linear",
|
|
165
|
+
requires_scaling=True,
|
|
166
|
+
default_params={
|
|
167
|
+
"alpha": 1.0,
|
|
168
|
+
"l1_ratio": 0.5,
|
|
169
|
+
},
|
|
170
|
+
hyperparameter_space={
|
|
171
|
+
"alpha": [
|
|
172
|
+
0.01,
|
|
173
|
+
0.1,
|
|
174
|
+
1.0,
|
|
175
|
+
10.0,
|
|
176
|
+
],
|
|
177
|
+
"l1_ratio": [
|
|
178
|
+
0.1,
|
|
179
|
+
0.5,
|
|
180
|
+
0.9,
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
),
|
|
184
|
+
"decision_tree_regressor": ModelSpec(
|
|
185
|
+
name="Decision Tree Regressor",
|
|
186
|
+
estimator=DecisionTreeRegressor,
|
|
187
|
+
task_type="regression",
|
|
188
|
+
category="tree",
|
|
189
|
+
requires_scaling=False,
|
|
190
|
+
default_params={
|
|
191
|
+
"random_state": 42,
|
|
192
|
+
},
|
|
193
|
+
hyperparameter_space={
|
|
194
|
+
"max_depth": [
|
|
195
|
+
None,
|
|
196
|
+
5,
|
|
197
|
+
10,
|
|
198
|
+
20,
|
|
199
|
+
],
|
|
200
|
+
"min_samples_split": [
|
|
201
|
+
2,
|
|
202
|
+
5,
|
|
203
|
+
10,
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
),
|
|
207
|
+
"random_forest_regressor": ModelSpec(
|
|
208
|
+
name="Random Forest Regressor",
|
|
209
|
+
estimator=RandomForestRegressor,
|
|
210
|
+
task_type="regression",
|
|
211
|
+
category="ensemble",
|
|
212
|
+
requires_scaling=False,
|
|
213
|
+
default_params={
|
|
214
|
+
"n_estimators": 100,
|
|
215
|
+
"random_state": 42,
|
|
216
|
+
"n_jobs": -1,
|
|
217
|
+
},
|
|
218
|
+
hyperparameter_space={
|
|
219
|
+
"n_estimators": [
|
|
220
|
+
100,
|
|
221
|
+
200,
|
|
222
|
+
],
|
|
223
|
+
"max_depth": [
|
|
224
|
+
None,
|
|
225
|
+
10,
|
|
226
|
+
20,
|
|
227
|
+
],
|
|
228
|
+
"min_samples_split": [
|
|
229
|
+
2,
|
|
230
|
+
5,
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
),
|
|
234
|
+
"extra_trees_regressor": ModelSpec(
|
|
235
|
+
name="Extra Trees Regressor",
|
|
236
|
+
estimator=ExtraTreesRegressor,
|
|
237
|
+
task_type="regression",
|
|
238
|
+
category="ensemble",
|
|
239
|
+
requires_scaling=False,
|
|
240
|
+
default_params={
|
|
241
|
+
"n_estimators": 100,
|
|
242
|
+
"random_state": 42,
|
|
243
|
+
"n_jobs": -1,
|
|
244
|
+
},
|
|
245
|
+
hyperparameter_space={
|
|
246
|
+
"n_estimators": [
|
|
247
|
+
100,
|
|
248
|
+
200,
|
|
249
|
+
],
|
|
250
|
+
"max_depth": [
|
|
251
|
+
None,
|
|
252
|
+
10,
|
|
253
|
+
20,
|
|
254
|
+
],
|
|
255
|
+
"min_samples_split": [
|
|
256
|
+
2,
|
|
257
|
+
5,
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
),
|
|
261
|
+
"gradient_boosting_regressor": ModelSpec(
|
|
262
|
+
name="Gradient Boosting Regressor",
|
|
263
|
+
estimator=GradientBoostingRegressor,
|
|
264
|
+
task_type="regression",
|
|
265
|
+
category="boosting",
|
|
266
|
+
requires_scaling=False,
|
|
267
|
+
default_params={
|
|
268
|
+
"random_state": 42,
|
|
269
|
+
},
|
|
270
|
+
hyperparameter_space={
|
|
271
|
+
"n_estimators": [
|
|
272
|
+
100,
|
|
273
|
+
200,
|
|
274
|
+
],
|
|
275
|
+
"learning_rate": [
|
|
276
|
+
0.01,
|
|
277
|
+
0.05,
|
|
278
|
+
0.1,
|
|
279
|
+
],
|
|
280
|
+
"max_depth": [
|
|
281
|
+
2,
|
|
282
|
+
3,
|
|
283
|
+
5,
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
),
|
|
287
|
+
"knn_regressor": ModelSpec(
|
|
288
|
+
name="K-Nearest Neighbors Regressor",
|
|
289
|
+
estimator=KNeighborsRegressor,
|
|
290
|
+
task_type="regression",
|
|
291
|
+
category="distance_based",
|
|
292
|
+
requires_scaling=True,
|
|
293
|
+
default_params={
|
|
294
|
+
"n_neighbors": 5,
|
|
295
|
+
},
|
|
296
|
+
hyperparameter_space={
|
|
297
|
+
"n_neighbors": [
|
|
298
|
+
3,
|
|
299
|
+
5,
|
|
300
|
+
7,
|
|
301
|
+
11,
|
|
302
|
+
],
|
|
303
|
+
"weights": [
|
|
304
|
+
"uniform",
|
|
305
|
+
"distance",
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
),
|
|
309
|
+
"svr": ModelSpec(
|
|
310
|
+
name="Support Vector Regressor",
|
|
311
|
+
estimator=SVR,
|
|
312
|
+
task_type="regression",
|
|
313
|
+
category="svm",
|
|
314
|
+
requires_scaling=True,
|
|
315
|
+
default_params={
|
|
316
|
+
"kernel": "rbf",
|
|
317
|
+
},
|
|
318
|
+
hyperparameter_space={
|
|
319
|
+
"C": [
|
|
320
|
+
0.1,
|
|
321
|
+
1.0,
|
|
322
|
+
10.0,
|
|
323
|
+
],
|
|
324
|
+
"gamma": [
|
|
325
|
+
"scale",
|
|
326
|
+
"auto",
|
|
327
|
+
],
|
|
328
|
+
"epsilon": [
|
|
329
|
+
0.01,
|
|
330
|
+
0.1,
|
|
331
|
+
0.2,
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
),
|
|
335
|
+
"logistic_regression": ModelSpec(
|
|
336
|
+
name="Logistic Regression",
|
|
337
|
+
estimator=LogisticRegression,
|
|
338
|
+
task_type="classification",
|
|
339
|
+
category="linear",
|
|
340
|
+
requires_scaling=True,
|
|
341
|
+
supports_probability=True,
|
|
342
|
+
default_params={
|
|
343
|
+
"max_iter": 1000,
|
|
344
|
+
},
|
|
345
|
+
hyperparameter_space={
|
|
346
|
+
"C": [
|
|
347
|
+
0.01,
|
|
348
|
+
0.1,
|
|
349
|
+
1.0,
|
|
350
|
+
10.0,
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
),
|
|
354
|
+
"decision_tree_classifier": ModelSpec(
|
|
355
|
+
name="Decision Tree Classifier",
|
|
356
|
+
estimator=DecisionTreeClassifier,
|
|
357
|
+
task_type="classification",
|
|
358
|
+
category="tree",
|
|
359
|
+
requires_scaling=False,
|
|
360
|
+
supports_probability=True,
|
|
361
|
+
default_params={
|
|
362
|
+
"random_state": 42,
|
|
363
|
+
},
|
|
364
|
+
hyperparameter_space={
|
|
365
|
+
"max_depth": [
|
|
366
|
+
None,
|
|
367
|
+
5,
|
|
368
|
+
10,
|
|
369
|
+
20,
|
|
370
|
+
],
|
|
371
|
+
"min_samples_split": [
|
|
372
|
+
2,
|
|
373
|
+
5,
|
|
374
|
+
10,
|
|
375
|
+
],
|
|
376
|
+
},
|
|
377
|
+
),
|
|
378
|
+
"random_forest_classifier": ModelSpec(
|
|
379
|
+
name="Random Forest Classifier",
|
|
380
|
+
estimator=RandomForestClassifier,
|
|
381
|
+
task_type="classification",
|
|
382
|
+
category="ensemble",
|
|
383
|
+
requires_scaling=False,
|
|
384
|
+
supports_probability=True,
|
|
385
|
+
default_params={
|
|
386
|
+
"n_estimators": 100,
|
|
387
|
+
"random_state": 42,
|
|
388
|
+
"n_jobs": -1,
|
|
389
|
+
},
|
|
390
|
+
hyperparameter_space={
|
|
391
|
+
"n_estimators": [
|
|
392
|
+
100,
|
|
393
|
+
200,
|
|
394
|
+
],
|
|
395
|
+
"max_depth": [
|
|
396
|
+
None,
|
|
397
|
+
10,
|
|
398
|
+
20,
|
|
399
|
+
],
|
|
400
|
+
"min_samples_split": [
|
|
401
|
+
2,
|
|
402
|
+
5,
|
|
403
|
+
],
|
|
404
|
+
},
|
|
405
|
+
),
|
|
406
|
+
"extra_trees_classifier": ModelSpec(
|
|
407
|
+
name="Extra Trees Classifier",
|
|
408
|
+
estimator=ExtraTreesClassifier,
|
|
409
|
+
task_type="classification",
|
|
410
|
+
category="ensemble",
|
|
411
|
+
requires_scaling=False,
|
|
412
|
+
supports_probability=True,
|
|
413
|
+
default_params={
|
|
414
|
+
"n_estimators": 100,
|
|
415
|
+
"random_state": 42,
|
|
416
|
+
"n_jobs": -1,
|
|
417
|
+
},
|
|
418
|
+
hyperparameter_space={
|
|
419
|
+
"n_estimators": [
|
|
420
|
+
100,
|
|
421
|
+
200,
|
|
422
|
+
],
|
|
423
|
+
"max_depth": [
|
|
424
|
+
None,
|
|
425
|
+
10,
|
|
426
|
+
20,
|
|
427
|
+
],
|
|
428
|
+
"min_samples_split": [
|
|
429
|
+
2,
|
|
430
|
+
5,
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
),
|
|
434
|
+
"gradient_boosting_classifier": ModelSpec(
|
|
435
|
+
name="Gradient Boosting Classifier",
|
|
436
|
+
estimator=GradientBoostingClassifier,
|
|
437
|
+
task_type="classification",
|
|
438
|
+
category="boosting",
|
|
439
|
+
requires_scaling=False,
|
|
440
|
+
supports_probability=True,
|
|
441
|
+
default_params={
|
|
442
|
+
"random_state": 42,
|
|
443
|
+
},
|
|
444
|
+
hyperparameter_space={
|
|
445
|
+
"n_estimators": [
|
|
446
|
+
100,
|
|
447
|
+
200,
|
|
448
|
+
],
|
|
449
|
+
"learning_rate": [
|
|
450
|
+
0.01,
|
|
451
|
+
0.05,
|
|
452
|
+
0.1,
|
|
453
|
+
],
|
|
454
|
+
"max_depth": [
|
|
455
|
+
2,
|
|
456
|
+
3,
|
|
457
|
+
5,
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
),
|
|
461
|
+
"knn_classifier": ModelSpec(
|
|
462
|
+
name="K-Nearest Neighbors Classifier",
|
|
463
|
+
estimator=KNeighborsClassifier,
|
|
464
|
+
task_type="classification",
|
|
465
|
+
category="distance_based",
|
|
466
|
+
requires_scaling=True,
|
|
467
|
+
supports_probability=True,
|
|
468
|
+
default_params={
|
|
469
|
+
"n_neighbors": 5,
|
|
470
|
+
},
|
|
471
|
+
hyperparameter_space={
|
|
472
|
+
"n_neighbors": [
|
|
473
|
+
3,
|
|
474
|
+
5,
|
|
475
|
+
7,
|
|
476
|
+
11,
|
|
477
|
+
],
|
|
478
|
+
"weights": [
|
|
479
|
+
"uniform",
|
|
480
|
+
"distance",
|
|
481
|
+
],
|
|
482
|
+
},
|
|
483
|
+
),
|
|
484
|
+
"svc": ModelSpec(
|
|
485
|
+
name="Support Vector Classifier",
|
|
486
|
+
estimator=SVC,
|
|
487
|
+
task_type="classification",
|
|
488
|
+
category="svm",
|
|
489
|
+
requires_scaling=True,
|
|
490
|
+
supports_probability=True,
|
|
491
|
+
default_params={
|
|
492
|
+
"kernel": "rbf",
|
|
493
|
+
"probability": True,
|
|
494
|
+
},
|
|
495
|
+
hyperparameter_space={
|
|
496
|
+
"C": [
|
|
497
|
+
0.1,
|
|
498
|
+
1.0,
|
|
499
|
+
10.0,
|
|
500
|
+
],
|
|
501
|
+
"gamma": [
|
|
502
|
+
"scale",
|
|
503
|
+
"auto",
|
|
504
|
+
],
|
|
505
|
+
},
|
|
506
|
+
),
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
def get(
|
|
510
|
+
self,
|
|
511
|
+
model_name: str,
|
|
512
|
+
) -> ModelSpec:
|
|
513
|
+
"""Retrieve a model specification."""
|
|
514
|
+
|
|
515
|
+
if not isinstance(model_name, str):
|
|
516
|
+
raise TypeError(
|
|
517
|
+
"model_name must be a string."
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
if model_name not in self._models:
|
|
521
|
+
raise KeyError(
|
|
522
|
+
f"Unknown model: {model_name}"
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
return self._models[model_name]
|
|
526
|
+
|
|
527
|
+
def get_models(
|
|
528
|
+
self,
|
|
529
|
+
task_type: str | None = None,
|
|
530
|
+
) -> dict[str, ModelSpec]:
|
|
531
|
+
"""Return all models or models for a specific task."""
|
|
532
|
+
|
|
533
|
+
if task_type is None:
|
|
534
|
+
return self._models.copy()
|
|
535
|
+
|
|
536
|
+
if task_type not in {
|
|
537
|
+
"regression",
|
|
538
|
+
"classification",
|
|
539
|
+
}:
|
|
540
|
+
raise ValueError(
|
|
541
|
+
"task_type must be 'regression' "
|
|
542
|
+
"or 'classification'."
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
return {
|
|
546
|
+
name: spec
|
|
547
|
+
for name, spec in self._models.items()
|
|
548
|
+
if spec.task_type == task_type
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
def list_models(
|
|
552
|
+
self,
|
|
553
|
+
task_type: str | None = None,
|
|
554
|
+
) -> list[str]:
|
|
555
|
+
"""Return model identifiers."""
|
|
556
|
+
|
|
557
|
+
return list(
|
|
558
|
+
self.get_models(task_type).keys()
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
def list_by_category(
|
|
562
|
+
self,
|
|
563
|
+
category: str,
|
|
564
|
+
task_type: str | None = None,
|
|
565
|
+
) -> list[str]:
|
|
566
|
+
"""
|
|
567
|
+
Return model identifiers belonging to a category.
|
|
568
|
+
|
|
569
|
+
Examples of categories:
|
|
570
|
+
linear, tree, ensemble, boosting, distance_based, svm
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
if not isinstance(category, str):
|
|
574
|
+
raise TypeError(
|
|
575
|
+
"category must be a string."
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
models = self.get_models(task_type)
|
|
579
|
+
|
|
580
|
+
return [
|
|
581
|
+
name
|
|
582
|
+
for name, spec in models.items()
|
|
583
|
+
if spec.category == category
|
|
584
|
+
]
|
|
585
|
+
|
|
586
|
+
def models_requiring_scaling(
|
|
587
|
+
self,
|
|
588
|
+
task_type: str | None = None,
|
|
589
|
+
) -> list[str]:
|
|
590
|
+
"""Return models that require feature scaling."""
|
|
591
|
+
|
|
592
|
+
models = self.get_models(task_type)
|
|
593
|
+
|
|
594
|
+
return [
|
|
595
|
+
name
|
|
596
|
+
for name, spec in models.items()
|
|
597
|
+
if spec.requires_scaling
|
|
598
|
+
]
|
|
599
|
+
|
|
600
|
+
def models_supporting_probability(
|
|
601
|
+
self,
|
|
602
|
+
task_type: str | None = None,
|
|
603
|
+
) -> list[str]:
|
|
604
|
+
"""Return models supporting probability predictions."""
|
|
605
|
+
|
|
606
|
+
models = self.get_models(task_type)
|
|
607
|
+
|
|
608
|
+
return [
|
|
609
|
+
name
|
|
610
|
+
for name, spec in models.items()
|
|
611
|
+
if spec.supports_probability
|
|
612
|
+
]
|
|
613
|
+
|
|
614
|
+
def get_hyperparameter_space(
|
|
615
|
+
self,
|
|
616
|
+
model_name: str,
|
|
617
|
+
) -> dict[str, Any]:
|
|
618
|
+
"""Return the hyperparameter search space for a model."""
|
|
619
|
+
|
|
620
|
+
return self.get(
|
|
621
|
+
model_name
|
|
622
|
+
).hyperparameter_space.copy()
|
|
623
|
+
|
|
624
|
+
def get_default_params(
|
|
625
|
+
self,
|
|
626
|
+
model_name: str,
|
|
627
|
+
) -> dict[str, Any]:
|
|
628
|
+
"""Return a copy of the model's default parameters."""
|
|
629
|
+
|
|
630
|
+
return self.get(
|
|
631
|
+
model_name
|
|
632
|
+
).default_params.copy()
|
|
633
|
+
|
|
634
|
+
def create(
|
|
635
|
+
self,
|
|
636
|
+
model_name: str,
|
|
637
|
+
**params,
|
|
638
|
+
) -> BaseEstimator:
|
|
639
|
+
"""Create an estimator instance."""
|
|
640
|
+
|
|
641
|
+
spec = self.get(model_name)
|
|
642
|
+
|
|
643
|
+
estimator_params = {
|
|
644
|
+
**spec.default_params,
|
|
645
|
+
**params,
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return spec.estimator(
|
|
649
|
+
**estimator_params
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
def supports_probability(
|
|
653
|
+
self,
|
|
654
|
+
model_name: str,
|
|
655
|
+
) -> bool:
|
|
656
|
+
"""Check whether a model supports probability predictions."""
|
|
657
|
+
|
|
658
|
+
return bool(
|
|
659
|
+
self.get(
|
|
660
|
+
model_name
|
|
661
|
+
).supports_probability
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
def requires_scaling(
|
|
665
|
+
self,
|
|
666
|
+
model_name: str,
|
|
667
|
+
) -> bool:
|
|
668
|
+
"""Check whether a model requires feature scaling."""
|
|
669
|
+
|
|
670
|
+
return bool(
|
|
671
|
+
self.get(
|
|
672
|
+
model_name
|
|
673
|
+
).requires_scaling
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
def count(
|
|
677
|
+
self,
|
|
678
|
+
task_type: str | None = None,
|
|
679
|
+
) -> int:
|
|
680
|
+
"""Return the number of registered models."""
|
|
681
|
+
|
|
682
|
+
return len(
|
|
683
|
+
self.get_models(task_type)
|
|
684
|
+
)
|