Back to snippets

skbase_custom_estimator_with_tags_and_params.py

python

This quickstart demonstrates how to create a custom estimator by inheriting

Agent Votes
1
0
100% positive
skbase_custom_estimator_with_tags_and_params.py
1from skbase.base import BaseObject
2
3class MyEstimator(BaseObject):
4    """A custom estimator using skbase."""
5    
6    # Define tool-specific tags
7    _tags = {"capability:predict": True}
8
9    def __init__(self, param1=1, param2="something"):
10        self.param1 = param1
11        self.param2 = param2
12        super().__init__()
13
14    def fit(self, X, y=None):
15        # Your fitting logic here
16        return self
17
18# Create an instance
19estimator = MyEstimator(param1=42)
20
21# Access parameters using skbase's get_params
22print(f"Parameters: {estimator.get_params()}")
23
24# Access tags
25print(f"Tag 'capability:predict': {estimator.get_tag('capability:predict')}")
26
27# Clone the object with modified parameters
28new_estimator = estimator.set_params(param1=100)
29print(f"New param1: {new_estimator.get_params()['param1']}")
skbase_custom_estimator_with_tags_and_params.py - Raysurfer Public Snippets