custom-sklearn-estimator

Build scikit-learn compatible custom estimators with BaseEstimator inheritance and validation.

5|1|Updated Dec 30, 2024
One-click install
npx skills add https://github.com/crossxwill/IML4Finance --skill custom-sklearn-estimator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: custom-sklearn-estimator
Source: https://github.com/crossxwill/IML4Finance/tree/main/.github/skills/custom-sklearn-estimator
Command: npx skills add https://github.com/crossxwill/IML4Finance --skill custom-sklearn-estimator

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Build scikit-learn compatible custom estimators by following the official “rolling your own estimator” rules for init, fit/predict, validation, learned attributes, tags, and estimator checks; prerequisite for autogluon-sklearn-wrapper or any sklearn-facing wrappers.

Core Features & Use Cases

  • Minimal init with keyword arguments and defaults; assigns each parameter to a corresponding attribute.
  • Implement fit(self, X, y=None, **kwargs) and return self, while validating inputs and creating learned attributes with trailing underscores (e.g., coef_, classes_).
  • Implement prediction/transform methods that use check_is_fitted and validate inputs with check_array, ensuring compatibility with pipelines and estimator checks.
  • Expose parameters via get_params/set_params and support randomness via random_state and check_random_state.
  • Prepare for estimator checks and optional tagging through sklearn_tags and compatibility helpers.

Quick Start

Create a minimal sklearn-compatible estimator by defining init, fit, and predict methods following the rolling your own estimator rules.

Frequently Asked Questions about custom-sklearn-estimator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a custom scikit-learn estimator that passes check_estimator?

To create a custom scikit-learn estimator that passes check_estimator, implement __init__ with keyword arguments, define fit and predict methods with input validation via check_array, and append trailing underscores to learned attributes like coef_.

What are the scikit-learn rules for estimator initialization and fit methods?

Scikit-learn requires __init__ to use keyword arguments with defaults assigned to matching attributes, and fit(self, X, y=None, **kwargs) must validate inputs, set learned attributes with trailing underscores, and return self.

How do I make a custom sklearn estimator work in pipelines and model validation?

To make a custom sklearn estimator work in pipelines, implement get_params and set_params, use check_is_fitted before predictions, and validate inputs with check_array to ensure full compatibility with pipeline tooling.

Does scikit-learn require check_array and check_is_fitted in custom estimator predict methods?

Scikit-learn requires custom estimator predict and transform methods to call check_is_fitted to verify the model is trained, and check_array to validate input data before generating outputs.

How should I handle random_state in a custom scikit-learn estimator?

Handle random_state in a custom scikit-learn estimator by accepting it as a keyword argument in __init__ and passing it to check_random_state during fit to ensure reproducible randomness across pipeline executions.

Why do my custom sklearn estimator learned attributes fail validation checks?

Custom sklearn estimator learned attributes fail validation checks if they lack trailing underscores. You must name learned attributes like classes_ or coef_ to distinguish them from constructor parameters.