EstimatorConfig¶
sklearn_wrap.config.EstimatorConfig
¶
Bases: BaseModel
Configuration for a scikit-learn compatible estimator.
Validates the structure of estimator configurations and can build instantiated estimators, convert existing estimators to configs, and serialize/deserialize to YAML.
Attributes¶
| Name | Type | Description |
|---|---|---|
estimator_class |
str
|
Fully qualified dotted import path, e.g. |
params |
dict[str, Any]
|
Constructor parameters. Nested dicts with an |
Examples¶
>>> config = EstimatorConfig(
... estimator_class="sklearn.linear_model.Ridge",
... params={"alpha": 1.0},
... )
>>> est = config.build()
>>> est.get_params()["alpha"]
1.0
Source Code¶
Show/Hide source
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
Methods¶
build(*, trusted_modules=None, validate_params=True)
¶
Resolve the configuration into an instantiated estimator.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
trusted_modules
|
frozenset[str] or None
|
Allowed top-level packages for class resolution. When |
None
|
validate_params
|
bool
|
If True, validate that the resolved parameter names match the constructor signature of the target class before instantiation. |
True
|
Returns¶
| Type | Description |
|---|---|
estimator
|
An instantiated scikit-learn compatible estimator. |
Examples¶
>>> config = EstimatorConfig(
... estimator_class="sklearn.linear_model.Ridge",
... params={"alpha": 2.0},
... )
>>> est = config.build()
>>> est.alpha
2.0
See Also¶
EstimatorConfig.from_estimator : Create a config from an existing estimator. EstimatorConfig.from_yaml : Load a config from a YAML file. set_config : Set global trusted modules configuration.
Source Code¶
Show/Hide source
from_estimator(estimator)
classmethod
¶
Create a configuration from an existing estimator instance.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
BaseEstimator
|
A scikit-learn compatible estimator (must implement |
required |
Returns¶
| Type | Description |
|---|---|
EstimatorConfig
|
The configuration capturing the estimator's class and parameters. |
Examples¶
>>> from sklearn.linear_model import Ridge
>>> est = Ridge(alpha=3.0)
>>> config = EstimatorConfig.from_estimator(est)
>>> config.estimator_class
'sklearn.linear_model._ridge.Ridge'
>>> config.params["alpha"]
3.0
See Also¶
EstimatorConfig.build : Instantiate an estimator from a config. EstimatorConfig.to_yaml : Serialize a config to YAML.
Source Code¶
Show/Hide source
to_yaml(path)
¶
Write the configuration to a YAML file.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination file path. |
required |
See Also¶
EstimatorConfig.from_yaml : Load a config from a YAML file.
Source Code¶
Show/Hide source
from_yaml(path)
classmethod
¶
Load a configuration from a YAML file.
Supports YAML anchors, merge keys (<<: *alias), and the
!include tag for multi-file composition.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to the YAML file. |
required |
Returns¶
| Type | Description |
|---|---|
EstimatorConfig
|
The validated configuration. |
See Also¶
EstimatorConfig.to_yaml : Write a config to a YAML file. EstimatorConfig.build : Instantiate an estimator from a config.