autoprognosis.studies.regression module

class RegressionStudy(dataset: pandas.core.frame.DataFrame, target: str, num_iter: int = 20, num_study_iter: int = 5, num_ensemble_iter: int = 15, timeout: int = 360, metric: str = 'r2', study_name: Optional[str] = None, feature_scaling: List[str] = ['normal_transform', 'maxabs_scaler', 'feature_normalizer', 'minmax_scaler', 'nop', 'scaler', 'uniform_transform'], feature_selection: List[str] = ['nop', 'pca', 'fast_ica'], regressors: List[str] = ['random_forest_regressor', 'xgboost_regressor', 'linear_regression', 'catboost_regressor'], imputers: List[str] = ['ice'], workspace: pathlib.Path = PosixPath('tmp'), hooks: autoprognosis.hooks.base.Hooks = <autoprognosis.hooks.default.DefaultHooks object>, score_threshold: float = 0.65, nan_placeholder: Optional[Any] = None, group_id: Optional[str] = None, random_state: int = 0, sample_for_search: bool = True, max_search_sample_size: int = 10000, ensemble_size: int = 3, n_folds_cv: int = 5)

Bases: autoprognosis.studies._base.Study

Core logic for regression studies.

A study automatically handles imputation, preprocessing and model selection for a certain dataset. The output is an optimal model architecture, selected by the AutoML logic.

Parameters
  • dataset – DataFrame. The dataset to analyze.

  • target – str. The target column in the dataset.

  • num_iter – int. Maximum Number of optimization trials. This is the limit of trials for each base estimator in the “regressors” list, used in combination with the “timeout” parameter. For each estimator, the search will end after “num_iter” trials or “timeout” seconds.

  • num_study_iter – int. The number of study iterations. This is the limit for the outer optimization loop. After each outer loop, an intermediary model is cached and can be used by another process, while the outer loop continues to improve the result.

  • timeout – int. Maximum wait time(seconds) for each estimator hyperparameter search. This timeout will apply to each estimator in the “regressors” list.

  • metric

    str. The metric to use for optimization. Available metric:

    • ”r2”

  • study_name – str. The name of the study, to be used in the caches.

  • feature_scaling

    list. Plugin search pool to use in the pipeline for scaling. Defaults to : [‘maxabs_scaler’, ‘scaler’, ‘feature_normalizer’, ‘normal_transform’, ‘uniform_transform’, ‘nop’, ‘minmax_scaler’] Available plugins, retrieved using Preprocessors(category=”feature_scaling”).list_available():

    • ’maxabs_scaler’

    • ’scaler’

    • ’feature_normalizer’

    • ’normal_transform’

    • ’uniform_transform’

    • ’nop’ # empty operation

    • ’minmax_scaler’

  • feature_selection

    list. Plugin search pool to use in the pipeline for feature selection. Defaults [“nop”, “variance_threshold”, “pca”, “fast_ica”] Available plugins, retrieved using Preprocessors(category=”dimensionality_reduction”).list_available():

    • ’feature_agglomeration’

    • ’fast_ica’

    • ’variance_threshold’

    • ’gauss_projection’

    • ’pca’

    • ’nop’ # no operation

  • imputers

    list. Plugin search pool to use in the pipeline for imputation. Defaults to [“mean”, “ice”, “missforest”, “hyperimpute”]. Available plugins, retrieved using Imputers().list_available():

    • ’sinkhorn’

    • ’EM’

    • ’mice’

    • ’ice’

    • ’hyperimpute’

    • ’most_frequent’

    • ’median’

    • ’missforest’

    • ’softimpute’

    • ’nop’

    • ’mean’

    • ’gain’

  • regressors

    list. Plugin search pool to use in the pipeline for prediction. Defaults to [“random_forest_regressor”,”xgboost_regressor”, “linear_regression”, “catboost_regressor”] Available plugins, retrieved using Regression().list_available():

    • ’kneighbors_regressor’

    • ’bayesian_ridge’

    • ’tabnet_regressor’

    • ’catboost_regressor’

    • ’random_forest_regressor’

    • ’mlp_regressor’

    • ’xgboost_regressor’

    • ’neural_nets_regression’

    • ’linear_regression’

  • hooks – Hooks. Custom callbacks to be notified about the search progress.

  • workspace – Path. Where to store the output model.

  • score_threshold – float. The minimum metric score for a candidate.

  • id – str. The id column in the dataset.

  • random_state – int Random seed

  • sample_for_search – bool Subsample the evaluation dataset in the search pipeline. Improves the speed of the search.

  • max_search_sample_size – int Subsample size for the evaluation dataset, if sample is True.

Example

>>> import pandas as pd
>>> from autoprognosis.utils.serialization import load_model_from_file
>>> from autoprognosis.utils.tester import evaluate_regression
>>> from autoprognosis.studies.regression import RegressionStudy
>>>
>>> # Load dataset
>>> df = pd.read_csv(
>>>     "https://archive.ics.uci.edu/ml/machine-learning-databases/00291/airfoil_self_noise.dat",
>>>     header=None,
>>>     sep="\t",
>>> )
>>> last_col = df.columns[-1]
>>> y = df[last_col]
>>> X = df.drop(columns=[last_col])
>>>
>>> df = X.copy()
>>> df["target"] = y
>>>
>>> # Search the model
>>>
>>> study_name="regression_example"
>>> study = RegressionStudy(
>>>     study_name=study_name,
>>>     dataset=df,  # pandas DataFrame
>>>     target="target",  # the label column in the dataset
>>> )
>>> model = study.fit()
>>>
>>> # Predict using the model
>>> model.predict(X)
fit() Any

Run the study and train the model. The call returns the fitted model.

run() Any

Run the study. The call returns the optimal model architecture - not fitted.