[ENH] simplify architecture of containers - #93
Conversation
| # if gpu_imported: | ||
| # KMeans = get_kmeans() |
| # if not gpu_imported: | ||
| # args["n_jobs"] = experiment.n_jobs_param | ||
| # else: | ||
| # DBSCAN = get_dbscan() |
There was a problem hiding this comment.
Pull request overview
This PR refactors PyCaret’s model container architecture (starting with clustering) to reduce duplication by moving model metadata to tags/properties and materializing estimator classes dynamically (e.g., via scikit-base’s tag system and _safe_import), aiming to make containers more extensible across backends (sklearn / sklearnex / cuML).
Changes:
- Refactors clustering model containers to rely on tags/properties for class materialization and parameter/tuning manifests.
- Updates
BaseContainerto inherit fromskbase.base.BaseObjectand introduces legacy-compatible property-based accessors forclass_defandargs. - Loosens
class_defconstructor requirements by making it optional in base container/model classes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pycaret/containers/models/clustering.py | Moves clustering containers toward tag/property-driven manifests and dynamic class materialization. |
| pycaret/containers/models/base_model.py | Makes class_def optional in the base model container constructor. |
| pycaret/containers/base_container.py | Switches to BaseObject and introduces property-based class_def/args access for compatibility and extensibility. |
Suppressed comments (2)
pycaret/containers/models/clustering.py:230
- gpu_imported is set to True unconditionally after _check_soft_dependencies(...). For severity="warning", _check_soft_dependencies returns False when cuml is missing, so this currently misreports GPU availability and may later select a non-importable class path.
if experiment.gpu_param == "force" or experiment.gpu_param:
if experiment.gpu_param == "force":
severity = "error"
else:
severity = "warning"
pycaret/containers/models/clustering.py:349
- Same as above: gpu_imported is set True even when _check_soft_dependencies(..., severity="warning") returns False. Also the log message references KMeans, but this is the DBSCAN container.
if experiment.gpu_param == "force" or experiment.gpu_param:
if experiment.gpu_param == "force":
severity = "error"
else:
severity = "warning"
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
pycaret/containers/models/clustering.py:354
- Same as in KMeans: gpu_imported is set to True even when _check_soft_dependencies(..., severity='warning') returns False, and the log message references KMeans instead of DBSCAN.
_check_soft_dependencies("cuml", extra=None, severity=severity)
logger.info("Imported cuml.cluster.KMeans")
gpu_imported = True
… into simplify-containers
The architecture of the
BaseContainer,ModelContainerand its child classes is highly duplicative and repetitive.This PR aims to reduce the container classes to a minimal manifest and make it as extensible to arbitrary containers for sklearn, sklearnex, cuml etc models as possible.
This is achieved by:
super.__init__calls with different sets of variables for estimatorsBaseObjectfromscikit-basetag system, and_safe_importfor materialization of blueprintsCurrently experimental, with clustering being the scope for trying out new architecture.
Fully aware that parts of the refactor may have to be moved up to parent base classes in the hierarchy eventually, but keeping the scope restricted for now to find the best architecture.