-
Notifications
You must be signed in to change notification settings - Fork 303
[ADD] scalers from autosklearn #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d1b0808
Add new scalers
ravinkohli 2af7387
fix flake and mypy
ravinkohli 38e64c8
Apply suggestions from code review
ravinkohli 349a079
add robust scaler
ravinkohli ee923c9
fix documentation
ravinkohli 17b1102
remove power transformer from feature preprocessing
ravinkohli ffdb93d
fix tests
ravinkohli 5c74fc2
check for default in include and exclude
ravinkohli eae79fc
Apply suggestions from code review
ravinkohli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 0 additions & 49 deletions
49
.../components/preprocessing/tabular_preprocessing/feature_preprocessing/PowerTransformer.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
autoPyTorch/pipeline/components/preprocessing/tabular_preprocessing/scaling/RobustScaler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from typing import Any, Dict, Optional, Union | ||
|
|
||
| from ConfigSpace.configuration_space import ConfigurationSpace | ||
| from ConfigSpace.hyperparameters import ( | ||
| UniformFloatHyperparameter, | ||
| ) | ||
|
|
||
| import numpy as np | ||
|
|
||
| from sklearn.preprocessing import RobustScaler as SklearnRobustScaler | ||
|
|
||
| from autoPyTorch.datasets.base_dataset import BaseDatasetPropertiesType | ||
| from autoPyTorch.pipeline.components.preprocessing.tabular_preprocessing.scaling.base_scaler import BaseScaler | ||
| from autoPyTorch.utils.common import FitRequirement, HyperparameterSearchSpace, add_hyperparameter | ||
|
|
||
|
|
||
| class RobustScaler(BaseScaler): | ||
| """ | ||
| Remove the median and scale features according to the quantile_range to make | ||
| the features robust to outliers. | ||
|
|
||
| For more details of the preprocessor, see: | ||
| https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.RobustScaler.html | ||
| """ | ||
| def __init__( | ||
| self, | ||
| q_min: float = 0.25, | ||
| q_max: float = 0.75, | ||
| random_state: Optional[np.random.RandomState] = None | ||
| ): | ||
| super().__init__() | ||
| self.add_fit_requirements([ | ||
| FitRequirement('issparse', (bool,), user_defined=True, dataset_property=True)]) | ||
| self.random_state = random_state | ||
| self.q_min = q_min | ||
| self.q_max = q_max | ||
|
|
||
| def fit(self, X: Dict[str, Any], y: Any = None) -> BaseScaler: | ||
|
|
||
| self.check_requirements(X, y) | ||
| with_centering = False if X['dataset_properties']['issparse'] else True | ||
|
ravinkohli marked this conversation as resolved.
Outdated
|
||
|
|
||
| self.preprocessor['numerical'] = SklearnRobustScaler(quantile_range=(self.q_min, self.q_max), | ||
| with_centering=with_centering, | ||
| copy=False) | ||
|
|
||
| return self | ||
|
|
||
| @staticmethod | ||
| def get_hyperparameter_search_space( | ||
| dataset_properties: Optional[Dict[str, BaseDatasetPropertiesType]] = None, | ||
| q_min: HyperparameterSearchSpace = HyperparameterSearchSpace(hyperparameter="q_min", | ||
| value_range=(0.001, 0.3), | ||
| default_value=0.25), | ||
| q_max: HyperparameterSearchSpace = HyperparameterSearchSpace(hyperparameter="q_max", | ||
| value_range=(0.7, 0.999), | ||
| default_value=0.75) | ||
| ) -> ConfigurationSpace: | ||
| cs = ConfigurationSpace() | ||
|
|
||
| add_hyperparameter(cs, q_min, UniformFloatHyperparameter) | ||
| add_hyperparameter(cs, q_max, UniformFloatHyperparameter) | ||
|
|
||
| return cs | ||
|
|
||
| @staticmethod | ||
| def get_properties(dataset_properties: Optional[Dict[str, BaseDatasetPropertiesType]] = None | ||
| ) -> Dict[str, Union[str, bool]]: | ||
| return { | ||
| 'shortname': 'RobustScaler', | ||
| 'name': 'RobustScaler', | ||
| 'handles_sparse': True | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.