Skip to content

Predictors

AbstractPredictor

Bases: ABC

Abstract base class for all predictors.

Provides a framework for fitting, predicting, and managing model persistence.

Methods

fit(X, Y, kwargs) Fit the model to the data. predict(X, kwargs) Predict using the model. save(file_path) Save the model to a file. load(file_path) Load the model from a file.

Source code in asf/predictors/abstract_predictor.py
class AbstractPredictor(ABC):
    """
    Abstract base class for all predictors.

    Provides a framework for fitting, predicting, and managing model persistence.

    Methods
    -------
    fit(X, Y, **kwargs)
        Fit the model to the data.
    predict(X, **kwargs)
        Predict using the model.
    save(file_path)
        Save the model to a file.
    load(file_path)
        Load the model from a file.
    """

    def __init__(self, **kwargs: Any) -> None:
        """
        Initialize the predictor.
        """
        pass

    @abstractmethod
    def fit(self, X: Any, Y: Any, **kwargs: Any) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : Any
            Training data.
        Y : Any
            Target values.
        kwargs : Any
            Additional arguments for fitting the model.
        """
        pass

    @abstractmethod
    def predict(self, X: Any, **kwargs: Any) -> Any:
        """
        Predict using the model.

        Parameters
        ----------
        X : Any
            Data to predict on.
        kwargs : Any
            Additional arguments for prediction.

        Returns
        -------
        Any
            Predicted values.
        """
        pass

    @abstractmethod
    def save(self, file_path: str) -> None:
        """
        Save the model to a file.

        Parameters
        ----------
        file_path : str
            Path to the file where the model will be saved.
        """
        pass

    @classmethod
    @abstractmethod
    def load(cls, file_path: str) -> AbstractPredictor:
        """
        Load the model from a file.

        Parameters
        ----------
        file_path : str
            Path to the file from which the model will be loaded.

        Returns
        -------
        AbstractPredictor
            The loaded model.
        """
        pass

__init__(**kwargs)

Initialize the predictor.

Source code in asf/predictors/abstract_predictor.py
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the predictor.
    """
    pass

fit(X, Y, **kwargs) abstractmethod

Fit the model to the data.

Parameters

X : Any Training data. Y : Any Target values. kwargs : Any Additional arguments for fitting the model.

Source code in asf/predictors/abstract_predictor.py
@abstractmethod
def fit(self, X: Any, Y: Any, **kwargs: Any) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : Any
        Training data.
    Y : Any
        Target values.
    kwargs : Any
        Additional arguments for fitting the model.
    """
    pass

load(file_path) abstractmethod classmethod

Load the model from a file.

Parameters

file_path : str Path to the file from which the model will be loaded.

Returns

AbstractPredictor The loaded model.

Source code in asf/predictors/abstract_predictor.py
@classmethod
@abstractmethod
def load(cls, file_path: str) -> AbstractPredictor:
    """
    Load the model from a file.

    Parameters
    ----------
    file_path : str
        Path to the file from which the model will be loaded.

    Returns
    -------
    AbstractPredictor
        The loaded model.
    """
    pass

predict(X, **kwargs) abstractmethod

Predict using the model.

Parameters

X : Any Data to predict on. kwargs : Any Additional arguments for prediction.

Returns

Any Predicted values.

Source code in asf/predictors/abstract_predictor.py
@abstractmethod
def predict(self, X: Any, **kwargs: Any) -> Any:
    """
    Predict using the model.

    Parameters
    ----------
    X : Any
        Data to predict on.
    kwargs : Any
        Additional arguments for prediction.

    Returns
    -------
    Any
        Predicted values.
    """
    pass

save(file_path) abstractmethod

Save the model to a file.

Parameters

file_path : str Path to the file where the model will be saved.

Source code in asf/predictors/abstract_predictor.py
@abstractmethod
def save(self, file_path: str) -> None:
    """
    Save the model to a file.

    Parameters
    ----------
    file_path : str
        Path to the file where the model will be saved.
    """
    pass

EPMRandomForest

Bases: ForestRegressor, AbstractPredictor, ConfigurableMixin

Implementation of Random Forest as an Empirical Performance Model (EPM).

This model follows the approach described in the paper: "Algorithm runtime prediction: Methods & evaluation" by Hutter, Xu, Hoos, and Leyton-Brown (2014).

Parameters

n_estimators : int, default=100 The number of trees in the forest. log : bool, default=False Whether to apply logarithmic transformation to the tree values. return_var : bool, default=False Whether to compute variance across trees. criterion : str, default="squared_error" The function to measure the quality of a split. splitter : str, default="random" The strategy used to choose the split at each node. max_depth : int or None, default=None The maximum depth of the tree. min_samples_split : int, default=2 The minimum number of samples required to split an internal node. min_samples_leaf : int, default=1 The minimum number of samples required to be at a leaf node. min_weight_fraction_leaf : float, default=0.0 The minimum weighted fraction of the sum total of weights required to be at a leaf node. max_features : float, default=1.0 The number of features to consider when looking for the best split. max_leaf_nodes : int or None, default=None Grow trees with max_leaf_nodes in best-first fashion. min_impurity_decrease : float, default=0.0 A node will be split if this split induces a decrease of the impurity. bootstrap : bool, default=False Whether bootstrap samples are used when building trees. oob_score : bool, default=False Whether to use out-of-bag samples to estimate the generalization score. n_jobs : int or None, default=None The number of jobs to run in parallel. random_state : int or None, default=None Controls the randomness of the estimator. verbose : int, default=0 Controls the verbosity when fitting and predicting. warm_start : bool, default=False When set to True, reuse the solution of the previous call to fit. ccp_alpha : float, default=0.0 Complexity parameter used for Minimal Cost-Complexity Pruning. max_samples : int, float or None, default=None The number of samples to draw from X to train each base estimator. monotonic_cst : np.ndarray or None, default=None Constraints for monotonicity of features.

Source code in asf/predictors/epm_random_forest.py
class EPMRandomForest(ForestRegressor, AbstractPredictor, ConfigurableMixin):
    """
    Implementation of Random Forest as an Empirical Performance Model (EPM).

    This model follows the approach described in the paper:
    "Algorithm runtime prediction: Methods & evaluation" by Hutter, Xu, Hoos, and Leyton-Brown (2014).

    Parameters
    ----------
    n_estimators : int, default=100
        The number of trees in the forest.
    log : bool, default=False
        Whether to apply logarithmic transformation to the tree values.
    return_var : bool, default=False
        Whether to compute variance across trees.
    criterion : str, default="squared_error"
        The function to measure the quality of a split.
    splitter : str, default="random"
        The strategy used to choose the split at each node.
    max_depth : int or None, default=None
        The maximum depth of the tree.
    min_samples_split : int, default=2
        The minimum number of samples required to split an internal node.
    min_samples_leaf : int, default=1
        The minimum number of samples required to be at a leaf node.
    min_weight_fraction_leaf : float, default=0.0
        The minimum weighted fraction of the sum total of weights required to be at a leaf node.
    max_features : float, default=1.0
        The number of features to consider when looking for the best split.
    max_leaf_nodes : int or None, default=None
        Grow trees with max_leaf_nodes in best-first fashion.
    min_impurity_decrease : float, default=0.0
        A node will be split if this split induces a decrease of the impurity.
    bootstrap : bool, default=False
        Whether bootstrap samples are used when building trees.
    oob_score : bool, default=False
        Whether to use out-of-bag samples to estimate the generalization score.
    n_jobs : int or None, default=None
        The number of jobs to run in parallel.
    random_state : int or None, default=None
        Controls the randomness of the estimator.
    verbose : int, default=0
        Controls the verbosity when fitting and predicting.
    warm_start : bool, default=False
        When set to True, reuse the solution of the previous call to fit.
    ccp_alpha : float, default=0.0
        Complexity parameter used for Minimal Cost-Complexity Pruning.
    max_samples : int, float or None, default=None
        The number of samples to draw from X to train each base estimator.
    monotonic_cst : np.ndarray or None, default=None
        Constraints for monotonicity of features.
    """

    PREFIX: str = "epm_random_forest"

    def __init__(
        self,
        **kwargs: Any,
    ) -> None:
        n_estimators = kwargs.pop("n_estimators", 100)
        self.log = kwargs.pop("log", False)
        self.return_var = kwargs.pop("return_var", False)
        self.criterion = kwargs.pop("criterion", "squared_error")
        self.max_depth = kwargs.pop("max_depth", None)
        self.min_samples_split = kwargs.pop("min_samples_split", 2)
        self.min_samples_leaf = kwargs.pop("min_samples_leaf", 1)
        self.min_weight_fraction_leaf = kwargs.pop("min_weight_fraction_leaf", 0.0)
        self.max_features = kwargs.pop("max_features", 1.0)
        self.max_leaf_nodes = kwargs.pop("max_leaf_nodes", None)
        self.min_impurity_decrease = kwargs.pop("min_impurity_decrease", 0.0)
        self.ccp_alpha = kwargs.pop("ccp_alpha", 0.0)
        self.monotonic_cst = kwargs.pop("monotonic_cst", None)
        self.splitter = kwargs.pop("splitter", "random")

        # Extract ExtraTreesRegressor specific params
        bootstrap = kwargs.pop("bootstrap", False)
        oob_score = kwargs.pop("oob_score", False)
        n_jobs = kwargs.pop("n_jobs", None)
        random_state = kwargs.pop("random_state", None)
        verbose = kwargs.pop("verbose", 0)
        warm_start = kwargs.pop("warm_start", False)
        max_samples = kwargs.pop("max_samples", None)

        # Filter out parameters that are for the selector/pipeline and not the model
        for k in ["budget", "maximize", "n_algorithms"]:
            kwargs.pop(k, None)

        super().__init__(
            DecisionTreeRegressor(),
            n_estimators,
            estimator_params=(
                "criterion",
                "max_depth",
                "min_samples_split",
                "min_samples_leaf",
                "min_weight_fraction_leaf",
                "max_features",
                "max_leaf_nodes",
                "min_impurity_decrease",
                "random_state",
                "ccp_alpha",
                "monotonic_cst",
            ),
            bootstrap=bootstrap,
            oob_score=oob_score,
            n_jobs=n_jobs,
            random_state=random_state,
            verbose=verbose,
            warm_start=warm_start,
            max_samples=max_samples,
        )

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for EPMRandomForest.

        Parameters
        ----------
        **kwargs : Any
            Additional keyword arguments.

        Returns
        -------
        tuple
            (hyperparameters, conditions, forbiddens)
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Integer("n_estimators", (16, 128), log=True, default=100),
            Integer("min_samples_split", (2, 20), log=False, default=2),
            Integer("min_samples_leaf", (1, 20), log=False, default=1),
            Float("max_features", (0.1, 1.0), log=False, default=1.0),
            Categorical("bootstrap", items=[True, False], default=False),
            Categorical("log", items=[True, False], default=False),
        ]
        return hyperparameters, [], []

    def fit(
        self,
        X: np.ndarray,
        Y: np.ndarray,
        sample_weight: np.ndarray | None = None,
        **kwargs: Any,
    ) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : np.ndarray
            Training data of shape (n_samples, n_features).
        y : np.ndarray
            Target values of shape (n_samples,).
        sample_weight : np.ndarray or None, default=None
            Sample weights. Currently not supported.

        Raises
        ------
        AssertionError
            If sample weights are provided.
        """
        assert sample_weight is None, "Sample weights are not supported"
        super().fit(X=X, y=Y, sample_weight=sample_weight)

        self.trainX = X
        self.trainY = Y
        if self.log:
            for tree, samples_idx in zip(self.estimators_, self.estimators_samples_):
                curX = X[samples_idx]
                curY = Y[samples_idx]
                preds = tree.apply(curX)
                for k in np.unique(preds):
                    tree.tree_.value[k, 0, 0] = np.log(np.exp(curY[preds == k]).mean())

    def predict(
        self, X: np.ndarray, **kwargs: Any
    ) -> np.ndarray | tuple[np.ndarray, np.ndarray]:
        """
        Predict using the model.

        Parameters
        ----------
        X : np.ndarray
            Data to predict on of shape (n_samples, n_features).

        Returns
        -------
        np.ndarray or tuple[np.ndarray, np.ndarray]
            Predicted means, or a tuple of (means, variances) if return_var is True.
        """
        preds = []
        for tree in self.estimators_:
            preds.append(tree.predict(X))
        preds_arr = np.array(preds).T

        means = preds_arr.mean(axis=1)
        vars_arr = preds_arr.var(axis=1)

        if self.return_var:
            return means, vars_arr
        else:
            return means

    def save(self, file_path: str) -> None:
        """
        Save the model to a file.

        Parameters
        ----------
        file_path : str
            Path to the file where the model will be saved.
        """
        joblib.dump(self, file_path)

    @classmethod
    def load(cls, file_path: str) -> EPMRandomForest:
        """
        Load the model from a file.

        Parameters
        ----------
        file_path : str
            Path to the file from which the model will be loaded.

        Returns
        -------
        EPMRandomForest
            The loaded model.
        """
        return joblib.load(file_path)

fit(X, Y, sample_weight=None, **kwargs)

Fit the model to the data.

Parameters

X : np.ndarray Training data of shape (n_samples, n_features). y : np.ndarray Target values of shape (n_samples,). sample_weight : np.ndarray or None, default=None Sample weights. Currently not supported.

Raises

AssertionError If sample weights are provided.

Source code in asf/predictors/epm_random_forest.py
def fit(
    self,
    X: np.ndarray,
    Y: np.ndarray,
    sample_weight: np.ndarray | None = None,
    **kwargs: Any,
) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : np.ndarray
        Training data of shape (n_samples, n_features).
    y : np.ndarray
        Target values of shape (n_samples,).
    sample_weight : np.ndarray or None, default=None
        Sample weights. Currently not supported.

    Raises
    ------
    AssertionError
        If sample weights are provided.
    """
    assert sample_weight is None, "Sample weights are not supported"
    super().fit(X=X, y=Y, sample_weight=sample_weight)

    self.trainX = X
    self.trainY = Y
    if self.log:
        for tree, samples_idx in zip(self.estimators_, self.estimators_samples_):
            curX = X[samples_idx]
            curY = Y[samples_idx]
            preds = tree.apply(curX)
            for k in np.unique(preds):
                tree.tree_.value[k, 0, 0] = np.log(np.exp(curY[preds == k]).mean())

load(file_path) classmethod

Load the model from a file.

Parameters

file_path : str Path to the file from which the model will be loaded.

Returns

EPMRandomForest The loaded model.

Source code in asf/predictors/epm_random_forest.py
@classmethod
def load(cls, file_path: str) -> EPMRandomForest:
    """
    Load the model from a file.

    Parameters
    ----------
    file_path : str
        Path to the file from which the model will be loaded.

    Returns
    -------
    EPMRandomForest
        The loaded model.
    """
    return joblib.load(file_path)

predict(X, **kwargs)

Predict using the model.

Parameters

X : np.ndarray Data to predict on of shape (n_samples, n_features).

Returns

np.ndarray or tuple[np.ndarray, np.ndarray] Predicted means, or a tuple of (means, variances) if return_var is True.

Source code in asf/predictors/epm_random_forest.py
def predict(
    self, X: np.ndarray, **kwargs: Any
) -> np.ndarray | tuple[np.ndarray, np.ndarray]:
    """
    Predict using the model.

    Parameters
    ----------
    X : np.ndarray
        Data to predict on of shape (n_samples, n_features).

    Returns
    -------
    np.ndarray or tuple[np.ndarray, np.ndarray]
        Predicted means, or a tuple of (means, variances) if return_var is True.
    """
    preds = []
    for tree in self.estimators_:
        preds.append(tree.predict(X))
    preds_arr = np.array(preds).T

    means = preds_arr.mean(axis=1)
    vars_arr = preds_arr.var(axis=1)

    if self.return_var:
        return means, vars_arr
    else:
        return means

save(file_path)

Save the model to a file.

Parameters

file_path : str Path to the file where the model will be saved.

Source code in asf/predictors/epm_random_forest.py
def save(self, file_path: str) -> None:
    """
    Save the model to a file.

    Parameters
    ----------
    file_path : str
        Path to the file where the model will be saved.
    """
    joblib.dump(self, file_path)

LinearClassifierWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the SGDClassifier from scikit-learn, providing additional functionality for configuration space generation and parameter extraction.

Source code in asf/predictors/linear_model.py
class LinearClassifierWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the SGDClassifier from scikit-learn, providing additional functionality
    for configuration space generation and parameter extraction.
    """

    PREFIX = "linear_classifier"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the LinearClassifierWrapper.
        """
        super().__init__(SGDClassifier, init_params=init_params, **kwargs)

    @staticmethod
    def _define_hyperparameters(**kwargs):
        """
        Define hyperparameters for the Linear Classifier.
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        alpha = Float(
            "alpha",
            (1e-5, 1),
            log=True,
            default=1e-3,
        )
        eta0 = Float(
            "eta0",
            (1e-5, 1),
            log=True,
            default=1e-2,
        )

        params = [
            alpha,
            eta0,
        ]

        return params, [], []

__init__(init_params=None, **kwargs)

Initialize the LinearClassifierWrapper.

Source code in asf/predictors/linear_model.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the LinearClassifierWrapper.
    """
    super().__init__(SGDClassifier, init_params=init_params, **kwargs)

LinearRegressorWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the SGDRegressor from scikit-learn, providing additional functionality for configuration space generation and parameter extraction.

Source code in asf/predictors/linear_model.py
class LinearRegressorWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the SGDRegressor from scikit-learn, providing additional functionality
    for configuration space generation and parameter extraction.
    """

    PREFIX = "linear_regressor"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the LinearRegressorWrapper.
        """
        super().__init__(SGDRegressor, init_params=init_params, **kwargs)

    @staticmethod
    def _define_hyperparameters(**kwargs):
        """
        Define hyperparameters for the Linear Regressor.
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        alpha = Float(
            "alpha",
            (1e-5, 1),
            log=True,
            default=1e-3,
        )
        eta0 = Float(
            "eta0",
            (1e-5, 1),
            log=True,
            default=1e-2,
        )

        params = [alpha, eta0]
        return params, [], []

__init__(init_params=None, **kwargs)

Initialize the LinearRegressorWrapper.

Source code in asf/predictors/linear_model.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the LinearRegressorWrapper.
    """
    super().__init__(SGDRegressor, init_params=init_params, **kwargs)

MLPClassifierWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the MLPClassifier from scikit-learn.

Source code in asf/predictors/mlp.py
class MLPClassifierWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the MLPClassifier from scikit-learn.
    """

    PREFIX: str = "mlp_classifier"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the MLPClassifierWrapper.
        """
        params = init_params if isinstance(init_params, dict) else {}
        params.update(kwargs)

        if "width" in params and "depth" in params:
            width = params.pop("width")
            depth = params.pop("depth")
            params["hidden_layer_sizes"] = tuple([width] * depth)

        if "activation" not in params:
            params["activation"] = "relu"
        if "solver" not in params:
            params["solver"] = "adam"

        super().__init__(MLPClassifier, **params)

    def fit(
        self,
        X: Any,
        Y: Any,
        sample_weight: Any | None = None,
        **kwargs: Any,
    ) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : array-like
            Training data.
        Y : array-like
            Target values.
        sample_weight : array-like or None, default=None
            Sample weights. Not supported for MLPClassifier.
        **kwargs : Any
            Additional arguments for the fit method.

        Raises
        ------
        AssertionError
            If sample_weight is provided.
        """
        assert sample_weight is None, (
            "Sample weights are not supported for MLPClassifier"
        )
        self.model_class.fit(X, Y, **kwargs)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for the MLP Classifier.

        Parameters
        ----------
        **kwargs : Any
            Additional keyword arguments.

        Returns
        -------
        tuple
            (hyperparameters, conditions, forbiddens)
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        depth = Integer("depth", (1, 3), default=3, log=False)
        width = Integer("width", (16, 1024), default=64, log=True)
        batch_size = Integer(
            "batch_size",
            (256, 1024),
            default=256,
            log=True,
        )
        alpha = Float(
            "alpha",
            (10**-8, 1),
            default=10**-3,
            log=True,
        )
        learning_rate_init = Float(
            "learning_rate_init",
            (10**-5, 1),
            default=10**-3,
            log=True,
        )

        params = [depth, width, batch_size, alpha, learning_rate_init]
        return params, [], []

__init__(init_params=None, **kwargs)

Initialize the MLPClassifierWrapper.

Source code in asf/predictors/mlp.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the MLPClassifierWrapper.
    """
    params = init_params if isinstance(init_params, dict) else {}
    params.update(kwargs)

    if "width" in params and "depth" in params:
        width = params.pop("width")
        depth = params.pop("depth")
        params["hidden_layer_sizes"] = tuple([width] * depth)

    if "activation" not in params:
        params["activation"] = "relu"
    if "solver" not in params:
        params["solver"] = "adam"

    super().__init__(MLPClassifier, **params)

fit(X, Y, sample_weight=None, **kwargs)

Fit the model to the data.

Parameters

X : array-like Training data. Y : array-like Target values. sample_weight : array-like or None, default=None Sample weights. Not supported for MLPClassifier. **kwargs : Any Additional arguments for the fit method.

Raises

AssertionError If sample_weight is provided.

Source code in asf/predictors/mlp.py
def fit(
    self,
    X: Any,
    Y: Any,
    sample_weight: Any | None = None,
    **kwargs: Any,
) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : array-like
        Training data.
    Y : array-like
        Target values.
    sample_weight : array-like or None, default=None
        Sample weights. Not supported for MLPClassifier.
    **kwargs : Any
        Additional arguments for the fit method.

    Raises
    ------
    AssertionError
        If sample_weight is provided.
    """
    assert sample_weight is None, (
        "Sample weights are not supported for MLPClassifier"
    )
    self.model_class.fit(X, Y, **kwargs)

MLPRegressorWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the MLPRegressor from scikit-learn.

Source code in asf/predictors/mlp.py
class MLPRegressorWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the MLPRegressor from scikit-learn.
    """

    PREFIX: str = "mlp_regressor"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the MLPRegressorWrapper.
        """
        params = init_params if isinstance(init_params, dict) else {}
        params.update(kwargs)

        if "width" in params and "depth" in params:
            width = params.pop("width")
            depth = params.pop("depth")
            params["hidden_layer_sizes"] = tuple([width] * depth)

        if "activation" not in params:
            params["activation"] = "relu"
        if "solver" not in params:
            params["solver"] = "adam"

        super().__init__(MLPRegressor, **params)

    def fit(
        self,
        X: Any,
        Y: Any,
        sample_weight: Any | None = None,
        **kwargs: Any,
    ) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : array-like
            Training data.
        Y : array-like
            Target values.
        sample_weight : array-like or None, default=None
            Sample weights. Not supported for MLPRegressor.
        **kwargs : Any
            Additional arguments for the fit method.

        Raises
        ------
        AssertionError
            If sample_weight is provided.
        """
        assert sample_weight is None, (
            "Sample weights are not supported for MLPRegressor"
        )
        self.model_class.fit(X, Y, **kwargs)

    @staticmethod
    def _define_hyperparameters(
        dataset_size: str = "large",
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for the MLP Regressor.

        Parameters
        ----------
        dataset_size : str, default="large"
            The size of the dataset ('small', 'medium', or 'large').
        **kwargs : Any
            Additional keyword arguments.

        Returns
        -------
        tuple
            (hyperparameters, conditions, forbiddens)
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        depth = Integer("depth", (1, 3), default=3, log=False)
        width = Integer("width", (16, 1024), default=64, log=True)

        if dataset_size == "small":
            batch_size = Integer(
                "batch_size",
                (16, 256),
                default=64,
                log=True,
            )
        elif dataset_size == "medium":
            batch_size = Integer(
                "batch_size",
                (128, 512),
                default=128,
                log=True,
            )
        elif dataset_size == "large":
            batch_size = Integer(
                "batch_size",
                (256, 1024),
                default=256,
                log=True,
            )
        else:
            raise ValueError(
                f"Invalid dataset_size: {dataset_size}. Choose from 'small', 'medium', 'large'."
            )

        alpha = Float(
            "alpha",
            (10**-8, 1),
            default=10**-3,
            log=True,
        )

        learning_rate_init = Float(
            "learning_rate_init",
            (10**-5, 1),
            default=10**-3,
            log=True,
        )

        params = [depth, width, batch_size, alpha, learning_rate_init]
        return params, [], []

__init__(init_params=None, **kwargs)

Initialize the MLPRegressorWrapper.

Source code in asf/predictors/mlp.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the MLPRegressorWrapper.
    """
    params = init_params if isinstance(init_params, dict) else {}
    params.update(kwargs)

    if "width" in params and "depth" in params:
        width = params.pop("width")
        depth = params.pop("depth")
        params["hidden_layer_sizes"] = tuple([width] * depth)

    if "activation" not in params:
        params["activation"] = "relu"
    if "solver" not in params:
        params["solver"] = "adam"

    super().__init__(MLPRegressor, **params)

fit(X, Y, sample_weight=None, **kwargs)

Fit the model to the data.

Parameters

X : array-like Training data. Y : array-like Target values. sample_weight : array-like or None, default=None Sample weights. Not supported for MLPRegressor. **kwargs : Any Additional arguments for the fit method.

Raises

AssertionError If sample_weight is provided.

Source code in asf/predictors/mlp.py
def fit(
    self,
    X: Any,
    Y: Any,
    sample_weight: Any | None = None,
    **kwargs: Any,
) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : array-like
        Training data.
    Y : array-like
        Target values.
    sample_weight : array-like or None, default=None
        Sample weights. Not supported for MLPRegressor.
    **kwargs : Any
        Additional arguments for the fit method.

    Raises
    ------
    AssertionError
        If sample_weight is provided.
    """
    assert sample_weight is None, (
        "Sample weights are not supported for MLPRegressor"
    )
    self.model_class.fit(X, Y, **kwargs)

RandomForestClassifierWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the RandomForestClassifier from scikit-learn.

Source code in asf/predictors/random_forest.py
class RandomForestClassifierWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the RandomForestClassifier from scikit-learn.
    """

    PREFIX: str = "rf_classifier"

    def __init__(self, **kwargs: Any):
        """
        Initialize the RandomForestClassifierWrapper.

        Parameters
        ----------
        **kwargs : Any
            Parameters for the RandomForestClassifier.
        """
        super().__init__(RandomForestClassifier, **kwargs)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for RandomForestClassifier.

        Parameters
        ----------
        **kwargs : Any
            Additional keyword arguments.

        Returns
        -------
        tuple
            (hyperparameters, conditions, forbiddens)
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Integer("n_estimators", (16, 128), log=True, default=116),
            Integer("min_samples_split", (2, 20), log=False, default=2),
            Integer("min_samples_leaf", (1, 20), log=False, default=2),
            Float("max_features", (0.1, 1.0), log=False, default=0.17055852159745608),
            Categorical("bootstrap", items=[True, False], default=False),
        ]
        return hyperparameters, [], []

__init__(**kwargs)

Initialize the RandomForestClassifierWrapper.

Parameters

**kwargs : Any Parameters for the RandomForestClassifier.

Source code in asf/predictors/random_forest.py
def __init__(self, **kwargs: Any):
    """
    Initialize the RandomForestClassifierWrapper.

    Parameters
    ----------
    **kwargs : Any
        Parameters for the RandomForestClassifier.
    """
    super().__init__(RandomForestClassifier, **kwargs)

RandomForestRegressorWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the RandomForestRegressor from scikit-learn.

Source code in asf/predictors/random_forest.py
class RandomForestRegressorWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the RandomForestRegressor from scikit-learn.
    """

    PREFIX: str = "rf_regressor"

    def __init__(self, **kwargs: Any):
        """
        Initialize the RandomForestRegressorWrapper.

        Parameters
        ----------
        **kwargs : Any
            Parameters for the RandomForestRegressor.
        """
        super().__init__(RandomForestRegressor, **kwargs)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for RandomForestRegressor.

        Parameters
        ----------
        **kwargs : Any
            Additional keyword arguments.

        Returns
        -------
        tuple
            (hyperparameters, conditions, forbiddens)
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Integer("n_estimators", (16, 128), log=True, default=116),
            Integer("min_samples_split", (2, 20), log=False, default=2),
            Integer("min_samples_leaf", (1, 20), log=False, default=2),
            Float("max_features", (0.1, 1.0), log=False, default=0.17055852159745608),
            Categorical("bootstrap", items=[True, False], default=False),
        ]
        return hyperparameters, [], []

__init__(**kwargs)

Initialize the RandomForestRegressorWrapper.

Parameters

**kwargs : Any Parameters for the RandomForestRegressor.

Source code in asf/predictors/random_forest.py
def __init__(self, **kwargs: Any):
    """
    Initialize the RandomForestRegressorWrapper.

    Parameters
    ----------
    **kwargs : Any
        Parameters for the RandomForestRegressor.
    """
    super().__init__(RandomForestRegressor, **kwargs)

RandomSurvivalForestWrapper

Bases: ConfigurableMixin, AbstractPredictor

Lightweight wrapper around sksurv's RandomSurvivalForest model.

Source code in asf/predictors/survival.py
class RandomSurvivalForestWrapper(ConfigurableMixin, AbstractPredictor):
    """
    Lightweight wrapper around ``sksurv``'s ``RandomSurvivalForest`` model.
    """

    PREFIX: str = "random_survival_forest"

    def __init__(self, **kwargs: Any) -> None:
        """
        Initialize the RandomSurvivalForestWrapper.
        """
        if not SKSURV_AVAILABLE:
            raise ImportError(
                "sksurv is not installed. Install scikit-survival to use RandomSurvivalForestWrapper."
            )
        kwargs = _filter_constructor_kwargs(RandomSurvivalForest, kwargs)
        self.model = RandomSurvivalForest(**kwargs)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for RandomSurvivalForestWrapper.

        Parameters
        ----------
        **kwargs : Any
            Additional keyword arguments.

        Returns
        -------
        tuple
            (hyperparameters, conditions, forbiddens)
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Integer("n_estimators", (10, 100), log=True, default=100),
            Integer("min_samples_split", (1, 50), default=10),
            Integer("min_samples_leaf", (1, 50), default=10),
            Float("max_features", (0.1, 1.0), default=0.5),
            Categorical("bootstrap", items=[True, False], default=True),
        ]
        return hyperparameters, [], []

    def fit(self, X: Any, Y: Any, **kwargs: Any) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : Any
            Training data.
        y : Any
            Target values.
        **kwargs : Any
            Additional arguments for the fit method.
        """
        self.model.fit(X, Y, **kwargs)

    def predict(self, X: Any, **kwargs: Any) -> Any:
        """
        Predict using the model.

        Parameters
        ----------
        X : Any
            Data to predict on.
        **kwargs : Any
            Additional arguments for the predict method.

        Returns
        -------
        Any
            Predicted values.
        """
        return self.model.predict(X, **kwargs)

    def predict_survival_function(self, X: Any, **kwargs: Any) -> Any:
        """
        Predict survival function.
        """
        return self.model.predict_survival_function(X, **kwargs)

    def save(self, file_path: str) -> None:
        """
        Save the model to a file.
        """
        joblib.dump(self, file_path)

    @classmethod
    def load(cls, file_path: str) -> AbstractPredictor:
        """
        Load the model from a file.
        """
        return joblib.load(file_path)

__init__(**kwargs)

Initialize the RandomSurvivalForestWrapper.

Source code in asf/predictors/survival.py
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the RandomSurvivalForestWrapper.
    """
    if not SKSURV_AVAILABLE:
        raise ImportError(
            "sksurv is not installed. Install scikit-survival to use RandomSurvivalForestWrapper."
        )
    kwargs = _filter_constructor_kwargs(RandomSurvivalForest, kwargs)
    self.model = RandomSurvivalForest(**kwargs)

fit(X, Y, **kwargs)

Fit the model to the data.

Parameters

X : Any Training data. y : Any Target values. **kwargs : Any Additional arguments for the fit method.

Source code in asf/predictors/survival.py
def fit(self, X: Any, Y: Any, **kwargs: Any) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : Any
        Training data.
    y : Any
        Target values.
    **kwargs : Any
        Additional arguments for the fit method.
    """
    self.model.fit(X, Y, **kwargs)

load(file_path) classmethod

Load the model from a file.

Source code in asf/predictors/survival.py
@classmethod
def load(cls, file_path: str) -> AbstractPredictor:
    """
    Load the model from a file.
    """
    return joblib.load(file_path)

predict(X, **kwargs)

Predict using the model.

Parameters

X : Any Data to predict on. **kwargs : Any Additional arguments for the predict method.

Returns

Any Predicted values.

Source code in asf/predictors/survival.py
def predict(self, X: Any, **kwargs: Any) -> Any:
    """
    Predict using the model.

    Parameters
    ----------
    X : Any
        Data to predict on.
    **kwargs : Any
        Additional arguments for the predict method.

    Returns
    -------
    Any
        Predicted values.
    """
    return self.model.predict(X, **kwargs)

predict_survival_function(X, **kwargs)

Predict survival function.

Source code in asf/predictors/survival.py
def predict_survival_function(self, X: Any, **kwargs: Any) -> Any:
    """
    Predict survival function.
    """
    return self.model.predict_survival_function(X, **kwargs)

save(file_path)

Save the model to a file.

Source code in asf/predictors/survival.py
def save(self, file_path: str) -> None:
    """
    Save the model to a file.
    """
    joblib.dump(self, file_path)

RankingMLP

Bases: ConfigurableMixin, AbstractPredictor

A ranking-based predictor using a Multi-Layer Percetron (MLP).

This class implements a ranking model that uses an MLP to predict the performance of algorithms based on input features.

Source code in asf/predictors/ranking_mlp.py
class RankingMLP(ConfigurableMixin, AbstractPredictor):
    """
    A ranking-based predictor using a Multi-Layer Percetron (MLP).

    This class implements a ranking model that uses an MLP to predict
    the performance of algorithms based on input features.
    """

    def __init__(
        self,
        init_params: dict[str, Any] | None = None,
        model: Any | None = None,
        input_size: int | None = None,
        loss: Callable | None = None,
        optimizer: Callable[..., Any] | None = None,
        batch_size: int = 128,
        epochs: int = 500,
        seed: int = 42,
        device: str = "cpu",
        compile: bool = True,
        learning_rate: float = 1e-3,
        weight_decay: float = 0.0,
        **kwargs,
    ):
        params = init_params if isinstance(init_params, dict) else {}
        params.update(kwargs)

        # Extract parameters from params with defaults
        model = params.pop("model", model)
        input_size = params.pop("input_size", input_size)
        loss = params.pop("loss", loss)
        optimizer = params.pop("optimizer", optimizer)
        batch_size = params.pop("batch_size", batch_size)
        epochs = params.pop("epochs", epochs)
        seed = params.pop("seed", seed)
        device = params.pop("device", device)
        compile = params.pop("compile", compile)
        learning_rate = params.pop("learning_rate", learning_rate)
        weight_decay = params.pop("weight_decay", weight_decay)

        super().__init__(**params)
        if not TORCH_AVAILABLE:
            raise RuntimeError(
                "PyTorch is not installed. Install it with: pip install torch"
            )

        assert model is not None or input_size is not None, (
            "Either model or input_size must be provided."
        )

        torch.manual_seed(seed)

        if model is None:
            assert input_size is not None
            self.model = get_mlp(input_size=input_size, output_size=1)
        else:
            self.model = model

        self.model.to(device)
        self.device = device

        self.loss = loss or bpr_loss
        self.batch_size = batch_size
        self.optimizer = optimizer or torch.optim.Adam
        self.epochs = epochs
        self.learning_rate = learning_rate
        self.weight_decay = weight_decay

        if compile:
            self.model = torch.compile(self.model)

    def _get_dataloader(
        self,
        features: pd.DataFrame,
        performance: pd.DataFrame,
        algorithm_features: pd.DataFrame,
    ) -> Any:
        dataset = RankingDataset(features, performance, algorithm_features)
        return torch.utils.data.DataLoader(
            dataset, batch_size=self.batch_size, shuffle=True, num_workers=0
        )

    def fit(
        self,
        X: Any,
        Y: Any,
        **kwargs: Any,
    ) -> None:
        # Extract algorithm_features from kwargs
        algorithm_features = kwargs.get("algorithm_features")
        if algorithm_features is None:
            raise ValueError(
                "algorithm_features must be provided in kwargs for RankingMLP.fit"
            )

        dataloader = self._get_dataloader(X, Y, algorithm_features)

        optimizer = self.optimizer(
            self.model.parameters(),
            lr=self.learning_rate,
            weight_decay=self.weight_decay,
        )
        self.model.train()
        for epoch in range(self.epochs):
            total_loss = 0
            for i, ((Xc, Xs, Xl), (yc, ys, yl)) in enumerate(dataloader):
                Xc, Xs, Xl = (
                    Xc.to(self.device),
                    Xs.to(self.device),
                    Xl.to(self.device),
                )
                yc, ys, yl = (
                    yc.to(self.device),
                    ys.to(self.device),
                    yl.to(self.device),
                )

                yc = yc.float().unsqueeze(1)
                ys = ys.float().unsqueeze(1)
                yl = yl.float().unsqueeze(1)

                optimizer.zero_grad()

                y_pred = self.model(Xc)
                y_pred_s = self.model(Xs)
                y_pred_l = self.model(Xl)

                loss = self.loss(y_pred, y_pred_s, y_pred_l, yc, ys, yl)
                total_loss += loss.item()

                loss.backward()
                optimizer.step()

            logging.debug(f"Epoch {epoch}, Loss: {total_loss / len(dataloader)}")

        return None

    def predict(self, X: pd.DataFrame, **kwargs: Any) -> pd.DataFrame:
        self.model.eval()

        features_tensor = torch.from_numpy(X.values).to(self.device).float()
        predictions = self.model(features_tensor).detach().cpu().numpy()

        return predictions

    def save(self, file_path: str) -> None:
        torch.save(self, file_path)

    @classmethod
    def load(cls, file_path: str) -> AbstractPredictor:
        return torch.load(file_path)

    PREFIX = "ranking_mlp"

    @staticmethod
    def _define_hyperparameters(**kwargs):
        """Define hyperparameters for RankingMLP."""
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Integer("batch_size", (32, 256), log=True, default=128),
            Integer("epochs", (50, 1000), log=True, default=500),
            Float("learning_rate", (1e-4, 1e-1), log=True, default=1e-3),
            Float("weight_decay", (1e-6, 1e-2), log=True, default=1e-5),
        ]
        return hyperparameters, [], []

RegressionMLP

Bases: AbstractPredictor, ConfigurableMixin

A regression-based predictor using a Multi-Layer Perceptron (MLP).

Source code in asf/predictors/regression_mlp.py
class RegressionMLP(AbstractPredictor, ConfigurableMixin):
    """
    A regression-based predictor using a Multi-Layer Perceptron (MLP).
    """

    PREFIX: str = "regression_mlp"

    def __init__(
        self,
        init_params: dict[str, Any] | None = None,
        model: torch.nn.Module | None = None,
        loss: torch.nn.modules.loss._Loss | None = None,
        optimizer: type[torch.optim.Optimizer] | None = None,
        batch_size: int = 128,
        epochs: int = 2000,
        seed: int = 42,
        device: str = "cpu",
        compile_model: bool = True,
        learning_rate: float = 1e-3,
        weight_decay: float = 0.0,
        **kwargs: Any,
    ):
        params = init_params if isinstance(init_params, dict) else {}
        params.update(kwargs)

        # Extract parameters from params with defaults
        model = params.pop("model", model)
        loss = params.pop("loss", loss)
        optimizer = params.pop("optimizer", optimizer)
        batch_size = params.pop("batch_size", batch_size)
        epochs = params.pop("epochs", epochs)
        seed = params.pop("seed", seed)
        device = params.pop("device", device)
        compile_model = params.pop("compile_model", compile_model)
        learning_rate = params.pop("learning_rate", learning_rate)
        weight_decay = params.pop("weight_decay", weight_decay)

        super().__init__(**params)
        if not TORCH_AVAILABLE:
            raise RuntimeError(
                "PyTorch is not installed. Install it with: pip install torch"
            )

        torch.manual_seed(seed)

        self.model = model
        self.device = device
        self.loss = loss or torch.nn.MSELoss()
        self.batch_size = batch_size
        self.optimizer = optimizer or torch.optim.Adam
        self.epochs = epochs
        self.compile_model = compile_model
        self.learning_rate = learning_rate
        self.weight_decay = weight_decay

    def _get_dataloader(
        self,
        features: pd.DataFrame,
        performance: pd.DataFrame,
    ) -> torch.utils.data.DataLoader:
        dataset = RegressionDataset(features, performance)
        return torch.utils.data.DataLoader(
            dataset, batch_size=self.batch_size, shuffle=True
        )

    def fit(
        self,
        X: Any,
        Y: Any,
        **kwargs: Any,
    ) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : pd.DataFrame
            The features for each instance.
        Y : pd.DataFrame
            The performance of each algorithm on each instance.
        sample_weight : np.ndarray or None, default=None
            Sample weights. Currently not supported.
        **kwargs : Any
            Additional arguments.

        Returns
        -------
        RegressionMLP
            The fitted model.

        Raises
        ------
        AssertionError
            If sample_weight is provided.
        """
        sample_weight = kwargs.get("sample_weight")
        assert sample_weight is None, "Sample weights are not supported."

        if self.model is None:
            input_size = X.shape[1] if hasattr(X, "shape") else len(X.columns)
            self.model = get_mlp(input_size=input_size, output_size=1)

        self.model.to(self.device)

        if self.compile_model:
            self.model = torch.compile(self.model)

        features_imputed = pd.DataFrame(
            SimpleImputer().fit_transform(X.values),
            index=X.index,
            columns=X.columns,
        )
        dataloader = self._get_dataloader(features_imputed, Y)

        optimizer = self.optimizer(
            self.model.parameters(),
            lr=self.learning_rate,
            weight_decay=self.weight_decay,
        )
        self.model.train()
        for epoch in range(self.epochs):
            total_loss = 0.0
            for i, (X_batch, y_batch) in enumerate(dataloader):
                X_batch, y_batch = X_batch.to(self.device), y_batch.to(self.device)
                X_batch = X_batch.float()
                y_batch = y_batch.unsqueeze(-1).float()
                optimizer.zero_grad()
                y_pred = self.model(X_batch)
                loss = self.loss(y_pred, y_batch)
                total_loss += loss.item()
                loss.backward()
                optimizer.step()

        return None

    def predict(self, X: pd.DataFrame, **kwargs: Any) -> np.ndarray:
        """
        Predict using the model.

        Parameters
        ----------
        X : pd.DataFrame
            The features to predict on.
        **kwargs : Any
            Additional arguments.

        Returns
        -------
        np.ndarray
            The predicted values.
        """
        if self.model is None:
            raise RuntimeError("Model not fitted")
        self.model.eval()

        features_tensor = torch.from_numpy(X.values).to(self.device).float()
        predictions = self.model(features_tensor).detach().cpu().numpy().squeeze(1)

        return predictions

    def save(self, file_path: str) -> None:
        """
        Save the model to a file.
        """
        torch.save(self, file_path)

    @classmethod
    def load(cls, file_path: str) -> AbstractPredictor:
        """
        Load the model from a file.
        """
        return torch.load(file_path)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define hyperparameters for RegressionMLP.
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Integer("batch_size", (32, 256), log=True, default=128),
            Integer("epochs", (200, 2000), log=True, default=500),
            Float("learning_rate", (1e-4, 1e-1), log=True, default=1e-3),
            Float("weight_decay", (1e-6, 1e-2), log=True, default=1e-5),
        ]
        return hyperparameters, [], []

fit(X, Y, **kwargs)

Fit the model to the data.

Parameters

X : pd.DataFrame The features for each instance. Y : pd.DataFrame The performance of each algorithm on each instance. sample_weight : np.ndarray or None, default=None Sample weights. Currently not supported. **kwargs : Any Additional arguments.

Returns

RegressionMLP The fitted model.

Raises

AssertionError If sample_weight is provided.

Source code in asf/predictors/regression_mlp.py
def fit(
    self,
    X: Any,
    Y: Any,
    **kwargs: Any,
) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : pd.DataFrame
        The features for each instance.
    Y : pd.DataFrame
        The performance of each algorithm on each instance.
    sample_weight : np.ndarray or None, default=None
        Sample weights. Currently not supported.
    **kwargs : Any
        Additional arguments.

    Returns
    -------
    RegressionMLP
        The fitted model.

    Raises
    ------
    AssertionError
        If sample_weight is provided.
    """
    sample_weight = kwargs.get("sample_weight")
    assert sample_weight is None, "Sample weights are not supported."

    if self.model is None:
        input_size = X.shape[1] if hasattr(X, "shape") else len(X.columns)
        self.model = get_mlp(input_size=input_size, output_size=1)

    self.model.to(self.device)

    if self.compile_model:
        self.model = torch.compile(self.model)

    features_imputed = pd.DataFrame(
        SimpleImputer().fit_transform(X.values),
        index=X.index,
        columns=X.columns,
    )
    dataloader = self._get_dataloader(features_imputed, Y)

    optimizer = self.optimizer(
        self.model.parameters(),
        lr=self.learning_rate,
        weight_decay=self.weight_decay,
    )
    self.model.train()
    for epoch in range(self.epochs):
        total_loss = 0.0
        for i, (X_batch, y_batch) in enumerate(dataloader):
            X_batch, y_batch = X_batch.to(self.device), y_batch.to(self.device)
            X_batch = X_batch.float()
            y_batch = y_batch.unsqueeze(-1).float()
            optimizer.zero_grad()
            y_pred = self.model(X_batch)
            loss = self.loss(y_pred, y_batch)
            total_loss += loss.item()
            loss.backward()
            optimizer.step()

    return None

load(file_path) classmethod

Load the model from a file.

Source code in asf/predictors/regression_mlp.py
@classmethod
def load(cls, file_path: str) -> AbstractPredictor:
    """
    Load the model from a file.
    """
    return torch.load(file_path)

predict(X, **kwargs)

Predict using the model.

Parameters

X : pd.DataFrame The features to predict on. **kwargs : Any Additional arguments.

Returns

np.ndarray The predicted values.

Source code in asf/predictors/regression_mlp.py
def predict(self, X: pd.DataFrame, **kwargs: Any) -> np.ndarray:
    """
    Predict using the model.

    Parameters
    ----------
    X : pd.DataFrame
        The features to predict on.
    **kwargs : Any
        Additional arguments.

    Returns
    -------
    np.ndarray
        The predicted values.
    """
    if self.model is None:
        raise RuntimeError("Model not fitted")
    self.model.eval()

    features_tensor = torch.from_numpy(X.values).to(self.device).float()
    predictions = self.model(features_tensor).detach().cpu().numpy().squeeze(1)

    return predictions

save(file_path)

Save the model to a file.

Source code in asf/predictors/regression_mlp.py
def save(self, file_path: str) -> None:
    """
    Save the model to a file.
    """
    torch.save(self, file_path)

RidgeRegressorWrapper

Bases: ConfigurableMixin, SklearnWrapper

Wrapper around scikit-learn's Ridge regressor for ASF predictors.

Source code in asf/predictors/linear_model.py
class RidgeRegressorWrapper(ConfigurableMixin, SklearnWrapper):
    """Wrapper around scikit-learn's Ridge regressor for ASF predictors."""

    PREFIX = "ridge_regressor"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        super().__init__(Ridge, init_params=init_params, **kwargs)

    @staticmethod
    def _define_hyperparameters(**kwargs):
        """
        Define hyperparameters for the Ridge Regressor.
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        alpha = Float(
            "alpha",
            (1e-6, 100.0),
            log=True,
            default=1.0,
        )
        fit_intercept = Categorical(
            "fit_intercept",
            [True, False],
            default=True,
        )
        solver = Categorical(
            "solver",
            ["auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga"],
            default="auto",
        )

        params = [alpha, fit_intercept, solver]
        return params, [], []

SVMClassifierWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the Scikit-learn SVC (Support Vector Classifier) model. Provides methods to define a configuration space and create an instance of the classifier from a configuration.

Attributes

PREFIX : str Prefix used for parameter names in the configuration space.

Source code in asf/predictors/svm.py
class SVMClassifierWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the Scikit-learn SVC (Support Vector Classifier) model.
    Provides methods to define a configuration space and create an instance
    of the classifier from a configuration.

    Attributes
    ----------
    PREFIX : str
        Prefix used for parameter names in the configuration space.
    """

    PREFIX = "svm_classifier"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the SVMClassifierWrapper.

        Parameters
        ----------
        init_params : dict or None
            Parameters for the SVC model (backward compatibility).
        **kwargs : Any
            Parameters for the SVC model.
        """
        super().__init__(SVC, init_params=init_params, **kwargs)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define the configuration space for the SVM classifier.
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        # ConfigurableMixin handles prefixes
        max_iter = Constant("max_iter", 20000)
        kernel = Categorical(
            "kernel",
            items=["linear", "rbf", "poly", "sigmoid"],
            default="rbf",
        )
        degree = Integer("degree", (1, 128), log=True, default=1)
        coef0 = Float(
            "coef0",
            (-0.5, 0.5),
            log=False,
            default=0.49070634552851977,
        )
        tol = Float(
            "tol",
            (1e-4, 1e-2),
            log=True,
            default=0.0002154969698207585,
        )
        gamma = Categorical(
            "gamma",
            items=["scale", "auto"],
            default="scale",
        )
        C = Float(
            "C",
            (1.0, 20),
            log=True,
            default=1.0,
        )
        shrinking = Categorical(
            "shrinking",
            items=[True, False],
            default=True,
        )

        params = [kernel, degree, coef0, tol, gamma, C, shrinking, max_iter]

        gamma_cond = InCondition(
            child=gamma,
            parent=kernel,
            values=["rbf", "poly", "sigmoid"],
        )
        degree_cond = InCondition(
            child=degree,
            parent=kernel,
            values=["poly"],
        )
        conditions = [gamma_cond, degree_cond]

        return params, conditions, []

__init__(init_params=None, **kwargs)

Initialize the SVMClassifierWrapper.

Parameters

init_params : dict or None Parameters for the SVC model (backward compatibility). **kwargs : Any Parameters for the SVC model.

Source code in asf/predictors/svm.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the SVMClassifierWrapper.

    Parameters
    ----------
    init_params : dict or None
        Parameters for the SVC model (backward compatibility).
    **kwargs : Any
        Parameters for the SVC model.
    """
    super().__init__(SVC, init_params=init_params, **kwargs)

SVMRegressorWrapper

Bases: ConfigurableMixin, SklearnWrapper

A wrapper for the Scikit-learn SVR (Support Vector Regressor) model. Provides methods to define a configuration space and create an instance of the regressor from a configuration.

Attributes

PREFIX : str Prefix used for parameter names in the configuration space.

Source code in asf/predictors/svm.py
class SVMRegressorWrapper(ConfigurableMixin, SklearnWrapper):
    """
    A wrapper for the Scikit-learn SVR (Support Vector Regressor) model.
    Provides methods to define a configuration space and create an instance
    of the regressor from a configuration.

    Attributes
    ----------
    PREFIX : str
        Prefix used for parameter names in the configuration space.
    """

    PREFIX = "svm_regressor"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the SVMRegressorWrapper.

        Parameters
        ----------
        init_params : dict or None
            Parameters for the SVR model (backward compatibility).
        **kwargs : Any
            Parameters for the SVR model.
        """
        super().__init__(SVR, init_params=init_params, **kwargs)

    @staticmethod
    def _define_hyperparameters(
        **kwargs: Any,
    ) -> tuple[list[Hyperparameter], list[Any], list[Any]]:
        """
        Define the configuration space for the SVM regressor.
        """
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        # ConfigurableMixin handles prefixes
        max_iter = Constant("max_iter", 20000)
        kernel = Categorical(
            "kernel",
            items=["linear", "rbf", "poly", "sigmoid"],
            default="rbf",
        )
        degree = Integer("degree", (1, 128), log=True, default=1)
        coef0 = Float(
            "coef0",
            (-0.5, 0.5),
            log=False,
            default=0.0,
        )
        tol = Float(
            "tol",
            (1e-4, 1e-2),
            log=True,
            default=0.001,
        )
        gamma = Categorical(
            "gamma",
            items=["scale", "auto"],
            default="scale",
        )
        C = Float("C", (1.0, 20), log=True, default=1.0)
        shrinking = Categorical(
            "shrinking",
            items=[True, False],
            default=True,
        )
        epsilon = Float(
            "epsilon",
            (0.01, 0.99),
            log=True,
            default=0.0251,
        )

        params = [kernel, degree, coef0, tol, gamma, C, shrinking, epsilon, max_iter]

        gamma_cond = InCondition(
            child=gamma,
            parent=kernel,
            values=["rbf", "poly", "sigmoid"],
        )
        degree_cond = InCondition(
            child=degree,
            parent=kernel,
            values=["poly"],
        )
        conditions = [gamma_cond, degree_cond]

        return params, conditions, []

__init__(init_params=None, **kwargs)

Initialize the SVMRegressorWrapper.

Parameters

init_params : dict or None Parameters for the SVR model (backward compatibility). **kwargs : Any Parameters for the SVR model.

Source code in asf/predictors/svm.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the SVMRegressorWrapper.

    Parameters
    ----------
    init_params : dict or None
        Parameters for the SVR model (backward compatibility).
    **kwargs : Any
        Parameters for the SVR model.
    """
    super().__init__(SVR, init_params=init_params, **kwargs)

SklearnWrapper

Bases: AbstractPredictor

A generic wrapper for scikit-learn models.

This class allows scikit-learn models to be used with the ASF framework.

Parameters

model_class : type[BaseEstimator] A scikit-learn model class. init_params : dict[str, Any], optional Initialization parameters for the scikit-learn model (default is {}).

Source code in asf/predictors/sklearn_wrapper.py
class SklearnWrapper(AbstractPredictor):
    """
    A generic wrapper for scikit-learn models.

    This class allows scikit-learn models to be used with the ASF framework.

    Parameters
    ----------
    model_class : type[BaseEstimator]
        A scikit-learn model class.
    init_params : dict[str, Any], optional
        Initialization parameters for the scikit-learn model (default is {}).
    """

    def __init__(
        self,
        model_class: Any,
        init_params: dict[str, Any] | None = None,
        **kwargs: Any,
    ):
        super().__init__()
        params = init_params if isinstance(init_params, dict) else {}
        params.update(kwargs)

        # Filter out parameters that are for the selector/pipeline and not the model
        model_params = {
            k: v
            for k, v in params.items()
            if k not in ["budget", "maximize", "n_algorithms"]
        }

        self.model_class: Any = model_class(**model_params)

    def fit(
        self,
        X: np.ndarray,
        Y: np.ndarray,
        sample_weight: np.ndarray | None = None,
        **kwargs: Any,
    ) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : np.ndarray
            Training data of shape (n_samples, n_features).
        Y : np.ndarray
            Target values of shape (n_samples,).
        sample_weight : np.ndarray or None, default=None
            Sample weights of shape (n_samples,).
        **kwargs : Any
            Additional keyword arguments for the scikit-learn model's `fit` method.
        """
        X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
        Y_in = Y.to_numpy() if isinstance(Y, (pd.DataFrame, pd.Series)) else Y
        sw_in = (
            sample_weight.to_numpy()
            if isinstance(sample_weight, (pd.DataFrame, pd.Series))
            else sample_weight
        )
        self.model_class.fit(X_in, Y_in, sample_weight=sw_in, **kwargs)

    def predict(self, X: np.ndarray, **kwargs: Any) -> np.ndarray:
        """
        Predict using the model.

        Parameters
        ----------
        X : np.ndarray
            Data to predict on of shape (n_samples, n_features).
        **kwargs : Any
            Additional keyword arguments for the scikit-learn model's `predict` method.

        Returns
        -------
        np.ndarray
            Predicted values of shape (n_samples,).
        """
        X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
        return self.model_class.predict(X_in, **kwargs)

    def save(self, file_path: str) -> None:
        """
        Save the model to a file.

        Parameters
        ----------
        file_path : str
            Path to the file where the model will be saved.
        """
        joblib.dump(self, file_path)

    @classmethod
    def load(cls, file_path: str) -> SklearnWrapper:
        """
        Load the model from a file.

        Parameters
        ----------
        file_path : str
            Path to the file from which the model will be loaded.

        Returns
        -------
        SklearnWrapper
            The loaded model.
        """
        return joblib.load(file_path)

fit(X, Y, sample_weight=None, **kwargs)

Fit the model to the data.

Parameters

X : np.ndarray Training data of shape (n_samples, n_features). Y : np.ndarray Target values of shape (n_samples,). sample_weight : np.ndarray or None, default=None Sample weights of shape (n_samples,). **kwargs : Any Additional keyword arguments for the scikit-learn model's fit method.

Source code in asf/predictors/sklearn_wrapper.py
def fit(
    self,
    X: np.ndarray,
    Y: np.ndarray,
    sample_weight: np.ndarray | None = None,
    **kwargs: Any,
) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : np.ndarray
        Training data of shape (n_samples, n_features).
    Y : np.ndarray
        Target values of shape (n_samples,).
    sample_weight : np.ndarray or None, default=None
        Sample weights of shape (n_samples,).
    **kwargs : Any
        Additional keyword arguments for the scikit-learn model's `fit` method.
    """
    X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
    Y_in = Y.to_numpy() if isinstance(Y, (pd.DataFrame, pd.Series)) else Y
    sw_in = (
        sample_weight.to_numpy()
        if isinstance(sample_weight, (pd.DataFrame, pd.Series))
        else sample_weight
    )
    self.model_class.fit(X_in, Y_in, sample_weight=sw_in, **kwargs)

load(file_path) classmethod

Load the model from a file.

Parameters

file_path : str Path to the file from which the model will be loaded.

Returns

SklearnWrapper The loaded model.

Source code in asf/predictors/sklearn_wrapper.py
@classmethod
def load(cls, file_path: str) -> SklearnWrapper:
    """
    Load the model from a file.

    Parameters
    ----------
    file_path : str
        Path to the file from which the model will be loaded.

    Returns
    -------
    SklearnWrapper
        The loaded model.
    """
    return joblib.load(file_path)

predict(X, **kwargs)

Predict using the model.

Parameters

X : np.ndarray Data to predict on of shape (n_samples, n_features). **kwargs : Any Additional keyword arguments for the scikit-learn model's predict method.

Returns

np.ndarray Predicted values of shape (n_samples,).

Source code in asf/predictors/sklearn_wrapper.py
def predict(self, X: np.ndarray, **kwargs: Any) -> np.ndarray:
    """
    Predict using the model.

    Parameters
    ----------
    X : np.ndarray
        Data to predict on of shape (n_samples, n_features).
    **kwargs : Any
        Additional keyword arguments for the scikit-learn model's `predict` method.

    Returns
    -------
    np.ndarray
        Predicted values of shape (n_samples,).
    """
    X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
    return self.model_class.predict(X_in, **kwargs)

save(file_path)

Save the model to a file.

Parameters

file_path : str Path to the file where the model will be saved.

Source code in asf/predictors/sklearn_wrapper.py
def save(self, file_path: str) -> None:
    """
    Save the model to a file.

    Parameters
    ----------
    file_path : str
        Path to the file where the model will be saved.
    """
    joblib.dump(self, file_path)

XGBoostClassifierWrapper

Bases: ConfigurableMixin, SklearnWrapper

Wrapper for the XGBoost classifier to integrate with the ASF framework.

Source code in asf/predictors/xgboost.py
class XGBoostClassifierWrapper(ConfigurableMixin, SklearnWrapper):
    """
    Wrapper for the XGBoost classifier to integrate with the ASF framework.
    """

    PREFIX: str = "xgb_classifier"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the XGBoostClassifierWrapper.

        Parameters
        ----------
        init_params : dict or None
            Initialization parameters for the XGBoost classifier (backward compatibility).
        **kwargs : Any
            Initialization parameters for the XGBoost classifier.
        """
        if not XGB_AVAILABLE:
            raise ImportError(
                "XGBoost is not installed. Please install it using pip install asf-lib[xgb]."
            )
        super().__init__(XGBClassifier, init_params=init_params, **kwargs)

    def fit(
        self,
        X: np.ndarray,
        Y: np.ndarray,
        sample_weight: np.ndarray | None = None,
        **kwargs: Any,
    ) -> None:
        """
        Fit the model to the data.

        Parameters
        ----------
        X : np.ndarray
            Training data of shape (n_samples, n_features).
        Y : np.ndarray
            Target values of shape (n_samples,).
        sample_weight : np.ndarray, optional
            Sample weights of shape (n_samples,) (default is None).
        **kwargs : Any
            Additional keyword arguments for the scikit-learn model's `fit` method.
        """
        X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
        Y_in = Y.to_numpy() if isinstance(Y, (pd.DataFrame, pd.Series)) else Y
        Y_in = np.asarray(Y_in)
        if Y_in.ndim > 1:
            Y_in = Y_in.reshape(-1)

        if sample_weight is not None and isinstance(
            sample_weight, (pd.DataFrame, pd.Series)
        ):
            sample_weight = sample_weight.to_numpy()
        if sample_weight is not None:
            sample_weight = np.asarray(sample_weight).reshape(-1)

        if Y_in.dtype == bool:
            self.bool_labels = True
        else:
            self.bool_labels = False

        self.model_class.fit(X_in, Y_in, sample_weight=sample_weight, **kwargs)

    def predict(self, X: np.ndarray, **kwargs: Any) -> np.ndarray:
        """
        Predict using the model.

        Parameters
        ----------
        X : np.ndarray
            Data to predict on of shape (n_samples, n_features).
        **kwargs : Any
            Additional keyword arguments for the scikit-learn model's `predict` method.

        Returns
        -------
        np.ndarray
            Predicted values of shape (n_samples,).
        """
        X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
        if self.bool_labels:
            return self.model_class.predict(X_in, **kwargs).astype(bool)
        return self.model_class.predict(X_in, **kwargs)

    @staticmethod
    def _define_hyperparameters(**kwargs):
        """Define hyperparameters for XGBoost classifier."""
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Constant("booster", "gbtree"),
            Constant("n_estimators", 2000),
            Integer("max_depth", (1, 11), log=False, default=8),
            Integer("min_child_weight", (1, 100), log=True, default=39),
            Float(
                "colsample_bytree", (0.0, 1.0), log=False, default=0.2545374925231651
            ),
            Float(
                "colsample_bylevel", (0.0, 1.0), log=False, default=0.6909224923784677
            ),
            Float("lambda", (0.001, 1000), log=True, default=31.393252465064943),
            Float("alpha", (0.001, 1000), log=True, default=0.24167936088332426),
            Float(
                "learning_rate", (0.001, 0.1), log=True, default=0.008237525103357958
            ),
        ]
        return hyperparameters, [], []

__init__(init_params=None, **kwargs)

Initialize the XGBoostClassifierWrapper.

Parameters

init_params : dict or None Initialization parameters for the XGBoost classifier (backward compatibility). **kwargs : Any Initialization parameters for the XGBoost classifier.

Source code in asf/predictors/xgboost.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the XGBoostClassifierWrapper.

    Parameters
    ----------
    init_params : dict or None
        Initialization parameters for the XGBoost classifier (backward compatibility).
    **kwargs : Any
        Initialization parameters for the XGBoost classifier.
    """
    if not XGB_AVAILABLE:
        raise ImportError(
            "XGBoost is not installed. Please install it using pip install asf-lib[xgb]."
        )
    super().__init__(XGBClassifier, init_params=init_params, **kwargs)

fit(X, Y, sample_weight=None, **kwargs)

Fit the model to the data.

Parameters

X : np.ndarray Training data of shape (n_samples, n_features). Y : np.ndarray Target values of shape (n_samples,). sample_weight : np.ndarray, optional Sample weights of shape (n_samples,) (default is None). **kwargs : Any Additional keyword arguments for the scikit-learn model's fit method.

Source code in asf/predictors/xgboost.py
def fit(
    self,
    X: np.ndarray,
    Y: np.ndarray,
    sample_weight: np.ndarray | None = None,
    **kwargs: Any,
) -> None:
    """
    Fit the model to the data.

    Parameters
    ----------
    X : np.ndarray
        Training data of shape (n_samples, n_features).
    Y : np.ndarray
        Target values of shape (n_samples,).
    sample_weight : np.ndarray, optional
        Sample weights of shape (n_samples,) (default is None).
    **kwargs : Any
        Additional keyword arguments for the scikit-learn model's `fit` method.
    """
    X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
    Y_in = Y.to_numpy() if isinstance(Y, (pd.DataFrame, pd.Series)) else Y
    Y_in = np.asarray(Y_in)
    if Y_in.ndim > 1:
        Y_in = Y_in.reshape(-1)

    if sample_weight is not None and isinstance(
        sample_weight, (pd.DataFrame, pd.Series)
    ):
        sample_weight = sample_weight.to_numpy()
    if sample_weight is not None:
        sample_weight = np.asarray(sample_weight).reshape(-1)

    if Y_in.dtype == bool:
        self.bool_labels = True
    else:
        self.bool_labels = False

    self.model_class.fit(X_in, Y_in, sample_weight=sample_weight, **kwargs)

predict(X, **kwargs)

Predict using the model.

Parameters

X : np.ndarray Data to predict on of shape (n_samples, n_features). **kwargs : Any Additional keyword arguments for the scikit-learn model's predict method.

Returns

np.ndarray Predicted values of shape (n_samples,).

Source code in asf/predictors/xgboost.py
def predict(self, X: np.ndarray, **kwargs: Any) -> np.ndarray:
    """
    Predict using the model.

    Parameters
    ----------
    X : np.ndarray
        Data to predict on of shape (n_samples, n_features).
    **kwargs : Any
        Additional keyword arguments for the scikit-learn model's `predict` method.

    Returns
    -------
    np.ndarray
        Predicted values of shape (n_samples,).
    """
    X_in = X.to_numpy() if isinstance(X, (pd.DataFrame, pd.Series)) else X
    if self.bool_labels:
        return self.model_class.predict(X_in, **kwargs).astype(bool)
    return self.model_class.predict(X_in, **kwargs)

XGBoostRegressorWrapper

Bases: ConfigurableMixin, SklearnWrapper

Wrapper for the XGBoost regressor to integrate with the ASF framework.

Source code in asf/predictors/xgboost.py
class XGBoostRegressorWrapper(ConfigurableMixin, SklearnWrapper):
    """
    Wrapper for the XGBoost regressor to integrate with the ASF framework.
    """

    PREFIX: str = "xgb_regressor"

    def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
        """
        Initialize the XGBoostRegressorWrapper.

        Parameters
        ----------
        init_params : dict or None
            Initialization parameters for the XGBoost regressor (backward compatibility).
        **kwargs : Any
            Initialization parameters for the XGBoost regressor.
        """
        super().__init__(XGBRegressor, init_params=init_params, **kwargs)

    @staticmethod
    def _define_hyperparameters(**kwargs):
        """Define hyperparameters for XGBoost regressor."""
        if not CONFIGSPACE_AVAILABLE:
            return [], [], []

        hyperparameters = [
            Constant("booster", "gbtree"),
            Constant("n_estimators", 2000),
            Integer("max_depth", (1, 11), log=False, default=8),
            Integer("min_child_weight", (1, 100), log=True, default=39),
            Float(
                "colsample_bytree", (0.0, 1.0), log=False, default=0.2545374925231651
            ),
            Float(
                "colsample_bylevel", (0.0, 1.0), log=False, default=0.6909224923784677
            ),
            Float("lambda", (0.001, 1000), log=True, default=31.393252465064943),
            Float("alpha", (0.001, 1000), log=True, default=0.24167936088332426),
            Float(
                "learning_rate", (0.001, 0.1), log=True, default=0.008237525103357958
            ),
        ]
        return hyperparameters, [], []

__init__(init_params=None, **kwargs)

Initialize the XGBoostRegressorWrapper.

Parameters

init_params : dict or None Initialization parameters for the XGBoost regressor (backward compatibility). **kwargs : Any Initialization parameters for the XGBoost regressor.

Source code in asf/predictors/xgboost.py
def __init__(self, init_params: dict[str, Any] | None = None, **kwargs: Any):
    """
    Initialize the XGBoostRegressorWrapper.

    Parameters
    ----------
    init_params : dict or None
        Initialization parameters for the XGBoost regressor (backward compatibility).
    **kwargs : Any
        Initialization parameters for the XGBoost regressor.
    """
    super().__init__(XGBRegressor, init_params=init_params, **kwargs)