Module panama.ml.tunable.regression
Classes
class TunableCatBoostRegressor (name: str = 'catboost_regr', random_state: int = 42)
-
A class for a tunable CatBoost regressor model.
Initializes the TunableCatBoostRegressor with a name and a CatBoostRegressor model.
Args
name
- The name of the model.
Returns
None.
Expand source code
class TunableCatBoostRegressor(BaseTunableModel): """A class for a tunable CatBoost regressor model.""" DEFAULT_SEARCH_DICT = { "iterations": {"type": "int", "min": 100, "max": 1000}, "depth": {"type": "int", "min": 4, "max": 12}, "l2_leaf_reg": {"type": "choice", "values": [0.1, 0.2, 0.5, 1, 3, 4, 5]}, "learning_rate": {"type": "float", "min": 0.001, "max": 0.5}, "border_count": {"type": "int", "min": 1, "max": 255}, "loss_function": {"type": "choice", "values": ["RMSE", "MAE", "MAPE"]}, } def __init__(self, name: str = "catboost_regr", random_state: int = 42): """Initializes the TunableCatBoostRegressor with a name and a CatBoostRegressor model. Args: name: The name of the model. Returns: None. """ self.name = name self.model = CatBoostRegressor(random_state=random_state) def fit(self, X: DataFrame, y: Union[DataFrame, Series]) -> None: """Fits the model to the training data. Args: X: The features for training. y: The target values for training. Returns: None. """ self.model.fit(X, y) def predict(self, X: DataFrame) -> List: """Predicts target values for the given features. Args: X: The features to predict target values for. Returns: List: The predicted target values. """ return self.model.predict(X) def set_params(self, params: Dict) -> None: """Sets the hyperparameters of the model. Args: params: A dictionary of hyperparameters. Returns: None. """ self.model.set_params(**params) def get_params(self, deep: bool = True) -> Dict: """Set the hyperparameters of the model. Args: params: hyperparameters and their values. Returns: None. """ return self.model.get_params(deep)
Ancestors
- BaseTunableModel
- abc.ABC
Class variables
var DEFAULT_SEARCH_DICT
Methods
def fit(self, X: pandas.core.frame.DataFrame, y: Union[pandas.core.frame.DataFrame, pandas.core.series.Series]) ‑> None
-
Fits the model to the training data.
Args
X
- The features for training.
y
- The target values for training.
Returns
None.
def predict(self, X: pandas.core.frame.DataFrame) ‑> List
-
Predicts target values for the given features.
Args
X
- The features to predict target values for.
Returns
List
- The predicted target values.
def set_params(self, params: Dict) ‑> None
-
Sets the hyperparameters of the model.
Args
params
- A dictionary of hyperparameters.
Returns
None.
Inherited members
class TunableLGBMRegressor (name: str = 'lgbm_regr', random_state: int = 42)
-
A base class for tunable machine learning models.
This class defines a set of abstract methods that must be implemented by any concrete subclass.
Attributes
None. Initializes the TunableLGBMRegressor with a name and a LightGBMRegressor model.
Args
name
- The name of the model.
Returns
None.
Expand source code
class TunableLGBMRegressor(BaseTunableModel): DEFAULT_SEARCH_DICT = { "n_estimators": {"type": "int", "min": 100, "max": 1000}, "max_depth": {"type": "int", "min": 4, "max": 12}, "learning_rate": {"type": "float", "min": 0.001, "max": 0.5}, "subsample": {"type": "float", "min": 0.3, "max": 1}, "min_child_samples": {"type": "int", "min": 10, "max": 75}, "num_leaves": {"type": "int", "min": 10, "max": 75}, "boosting_type": {"type": "choice", "values": ["gbdt", "dart", "goss"]}, "objective": {"type": "choice", "values": ["regression", "regression_l1", "mape"]}, } """A class for a tunable LightGBM regressor model.""" def __init__(self, name: str = "lgbm_regr", random_state: int = 42): """Initializes the TunableLGBMRegressor with a name and a LightGBMRegressor model. Args: name: The name of the model. Returns: None. """ self.name = name self.model = LGBMRegressor(random_state=random_state) def fit(self, X: DataFrame, y: Union[DataFrame, Series]) -> None: """Fits the model to the training data. Args: X: The features for training. y: The target values for training. Returns: None. """ self.model.fit(X, y) def predict(self, X: DataFrame) -> List: """Predicts target values for the given features. Args: X: The features to predict target values for. Returns: List: The predicted target values. """ return self.model.predict(X) def set_params(self, params: Dict) -> None: """Sets the hyperparameters of the model. Args: params: A dictionary of hyperparameters. Returns: None. """ self.model.set_params(**params) def get_params(self, deep: bool = True) -> Dict: """Set the hyperparameters of the model. Args: params: hyperparameters and their values. Returns: None. """ return self.model.get_params(deep)
Ancestors
- BaseTunableModel
- abc.ABC
Class variables
var DEFAULT_SEARCH_DICT
-
A class for a tunable LightGBM regressor model.
Methods
def fit(self, X: pandas.core.frame.DataFrame, y: Union[pandas.core.frame.DataFrame, pandas.core.series.Series]) ‑> None
-
Fits the model to the training data.
Args
X
- The features for training.
y
- The target values for training.
Returns
None.
def predict(self, X: pandas.core.frame.DataFrame) ‑> List
-
Predicts target values for the given features.
Args
X
- The features to predict target values for.
Returns
List
- The predicted target values.
def set_params(self, params: Dict) ‑> None
-
Sets the hyperparameters of the model.
Args
params
- A dictionary of hyperparameters.
Returns
None.
Inherited members
class TunableRandomForestRegressor (name: str = 'random_forest_regr', random_state: int = 42)
-
A class for a tunable random forest regressor model.
Initializes the TunableRandomForestRegressor with a name and a RandomForestRegressor model.
Args
name
:str
- The name of the model.
Returns
None.
Expand source code
class TunableRandomForestRegressor(BaseTunableModel): """A class for a tunable random forest regressor model.""" DEFAULT_SEARCH_DICT = { "n_estimators": {"type": "int", "min": 100, "max": 1000}, "max_depth": {"type": "int", "min": 4, "max": 12}, "max_features": {"type": "float", "min": 0.3, "max": 1}, "min_samples_leaf": {"type": "int", "min": 3, "max": 25}, "criterion": {"type": "choice", "values": ["poisson", "absolute_error", "friedman_mse", "squared_error"]}, "bootstrap": {"type": "choice", "values": [True, False]}, } def __init__(self, name: str = "random_forest_regr", random_state: int = 42): """Initializes the TunableRandomForestRegressor with a name and a RandomForestRegressor model. Args: name (str): The name of the model. Returns: None. """ self.name = name self.model = RandomForestRegressor(random_state=random_state) def fit(self, X: DataFrame, y: Union[DataFrame, Series]) -> None: """Fits the model to the training data. Args: X: The features for training. y: The target values for training. Returns: None. """ self.model.fit(X, y) def predict(self, X: DataFrame) -> List: """Predicts target values for the given features. Args: X: The features to predict target values for. Returns: List: The predicted target values. """ return self.model.predict(X) def set_params(self, params: Dict) -> None: """Sets the hyperparameters of the model. Args: params: A dictionary of hyperparameters. Returns: None. """ self.model.set_params(**params) def get_params(self, deep: bool = True) -> Dict: """Set the hyperparameters of the model. Args: params: hyperparameters and their values. Returns: None. """ return self.model.get_params(deep)
Ancestors
- BaseTunableModel
- abc.ABC
Class variables
var DEFAULT_SEARCH_DICT
Methods
def fit(self, X: pandas.core.frame.DataFrame, y: Union[pandas.core.frame.DataFrame, pandas.core.series.Series]) ‑> None
-
Fits the model to the training data.
Args
X
- The features for training.
y
- The target values for training.
Returns
None.
def predict(self, X: pandas.core.frame.DataFrame) ‑> List
-
Predicts target values for the given features.
Args
X
- The features to predict target values for.
Returns
List
- The predicted target values.
def set_params(self, params: Dict) ‑> None
-
Sets the hyperparameters of the model.
Args
params
- A dictionary of hyperparameters.
Returns
None.
Inherited members
class TunableSGDRegressor (name: str = 'sgd_regr', random_state: int = 42)
-
A class for a tunable SGD regressor model.
Initializes the TunableSGDRegressor with a name and an SGDRegressor model.
Args
name
- The name of the model.
Returns
None.
Expand source code
class TunableSGDRegressor(BaseTunableModel): """A class for a tunable SGD regressor model.""" DEFAULT_SEARCH_DICT = { "loss": { "type": "choice", "values": ["squared_error", "huber", "epsilon_insensitive", "squared_epsilon_insensitive"], }, "penalty": {"type": "choice", "values": ["l1", "l2", "elasticnet"]}, "max_iter": {"type": "int", "min": 100, "max": 1000}, "learning_rate": {"type": "choice", "values": ["constant", "invscaling", "optimal", "adaptive"]}, } def __init__(self, name: str = "sgd_regr", random_state: int = 42): """Initializes the TunableSGDRegressor with a name and an SGDRegressor model. Args: name: The name of the model. Returns: None. """ self.name = name self.model = SGDRegressor(random_state=random_state) def fit(self, X: DataFrame, y: Union[DataFrame, Series]) -> None: """Fits the model to the training data. Args: X: The features for training. y: The target values for training. Returns: None. """ self.model.fit(X, y) def predict(self, X: DataFrame) -> List: """Predicts target values for the given features. Args: X: The features to predict target values for. Returns: List: The predicted target values. """ return self.model.predict(X) def set_params(self, params: Dict) -> None: """Sets the hyperparameters of the model. Args: params: A dictionary of hyperparameters. Returns: None. """ self.model.set_params(**params) def get_params(self, deep: bool = True) -> Dict: """Set the hyperparameters of the model. Args: params: hyperparameters and their values. Returns: None. """ return self.model.get_params(deep)
Ancestors
- BaseTunableModel
- abc.ABC
Class variables
var DEFAULT_SEARCH_DICT
Methods
def fit(self, X: pandas.core.frame.DataFrame, y: Union[pandas.core.frame.DataFrame, pandas.core.series.Series]) ‑> None
-
Fits the model to the training data.
Args
X
- The features for training.
y
- The target values for training.
Returns
None.
def predict(self, X: pandas.core.frame.DataFrame) ‑> List
-
Predicts target values for the given features.
Args
X
- The features to predict target values for.
Returns
List
- The predicted target values.
def set_params(self, params: Dict) ‑> None
-
Sets the hyperparameters of the model.
Args
params
- A dictionary of hyperparameters.
Returns
None.
Inherited members
class TunableXGBRegressor (name: str = 'xgb_regr', random_state: int = 42)
-
A class for a tunable XGBoost model.
Initializes the TunableXgbModel with a name and an XGBRegressor model.
Args
name
- The name of the model.
Returns
None.
Expand source code
class TunableXGBRegressor(BaseTunableModel): """A class for a tunable XGBoost model.""" DEFAULT_SEARCH_DICT = { "n_estimators": {"type": "int", "min": 100, "max": 1000}, "max_depth": {"type": "int", "min": 4, "max": 12}, "learning_rate": {"type": "float", "min": 0.001, "max": 0.5}, "objective": {"type": "choice", "values": ["reg:squarederror", "reg:squaredlogerror"]}, "subsample": {"type": "float", "min": 0.3, "max": 1}, "booster": {"type": "choice", "values": ["gbtree", "gblinear", "dart"]}, "tree_method": {"type": "choice", "values": ["exact", "approx", "hist"]}, } def __init__(self, name: str = "xgb_regr", random_state: int = 42): """Initializes the TunableXgbModel with a name and an XGBRegressor model. Args: name: The name of the model. Returns: None. """ self.name = name self.model = XGBRegressor(random_state=random_state) def fit(self, X: DataFrame, y: Union[DataFrame, Series]) -> None: """Fits the model to the training data. Args: X: The features for training. y: The target values for training. Returns: None. """ self.model.fit(X, y) def predict(self, X: DataFrame) -> List: """Predicts target values for the given features. Args: X: The features to predict target values for. Returns: List: The predicted target values. """ return self.model.predict(X) def get_params(self, deep: bool = True) -> Dict: """Set the hyperparameters of the model. Args: params: hyperparameters and their values. Returns: None. """ return self.model.get_params(deep) def set_params(self, params: Dict) -> None: """Sets the hyperparameters of the model. Args: params (Dict): A dictionary of hyperparameters. Returns: None. """ self.model.set_params(**params)
Ancestors
- BaseTunableModel
- abc.ABC
Class variables
var DEFAULT_SEARCH_DICT
Methods
def fit(self, X: pandas.core.frame.DataFrame, y: Union[pandas.core.frame.DataFrame, pandas.core.series.Series]) ‑> None
-
Fits the model to the training data.
Args
X
- The features for training.
y
- The target values for training.
Returns
None.
def predict(self, X: pandas.core.frame.DataFrame) ‑> List
-
Predicts target values for the given features.
Args
X
- The features to predict target values for.
Returns
List
- The predicted target values.
def set_params(self, params: Dict) ‑> None
-
Sets the hyperparameters of the model.
Args
params
:Dict
- A dictionary of hyperparameters.
Returns
None.
Inherited members