Issue
I have read few articles explaining how to create your own custom model using sklearn BaseEstimator class
, but the thing is that I need to use a regression model from the darts api, and in order to optimize its hyperparameters, the model must be a sklearn estimator, so I have to find a way to encapsulate the darts model (for example, LightGBMModel
), into a sklearn.base.BaseEstimator
.
Below is an example of how I tried:
from darts.models import LightGBMModel
from sklearn.base import BaseEstimator
class MyLightGBM(BaseEstimator, LightGBMModel):
def __init__(self, lags=4, random_state=0):
self.lags = lags
self.random_state=random_state
...
Sklearn needs the fit()
and predict()
methods, but the darts LightGBMModel
already has these methods.
Solution
I have tested it with catboost's regressor and this works:
class MyCatBoost(CatBoostRegressor, BaseEstimator):
def __init__(self, random_state=0):
super().__init__()
self.random_state = random_state
Look up MRO(method resolution order) in python to learn why I have changed the order or inheritance.
Answered By - Naveen Reddy Marthala
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.