-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [fix] Add check dataset in transform as well for test dataset, which does not require fit * [test] Migrate tests from the francisco's PR without modifications * [fix] Modify so that tests pass * [test] Increase the coverage
- Loading branch information
1 parent
ba9c86a
commit d59538c
Showing
13 changed files
with
730 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
...ch/pipeline/components/preprocessing/tabular_preprocessing/coalescer/MinorityCoalescer.py
This file contains 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,44 @@ | ||
from typing import Any, Dict, Optional, Union | ||
|
||
from ConfigSpace.configuration_space import ConfigurationSpace | ||
from ConfigSpace.hyperparameters import UniformFloatHyperparameter | ||
|
||
import numpy as np | ||
|
||
from autoPyTorch.pipeline.components.preprocessing.tabular_preprocessing.coalescer.base_coalescer import BaseCoalescer | ||
from autoPyTorch.utils.common import HyperparameterSearchSpace, add_hyperparameter | ||
from autoPyTorch.utils.implementations import MinorityCoalesceTransformer | ||
|
||
|
||
class MinorityCoalescer(BaseCoalescer): | ||
"""Group together categories whose occurence is less than a specified min_frac """ | ||
def __init__(self, min_frac: float, random_state: np.random.RandomState): | ||
super().__init__() | ||
self.min_frac = min_frac | ||
self.random_state = random_state | ||
|
||
def fit(self, X: Dict[str, Any], y: Any = None) -> BaseCoalescer: | ||
self.check_requirements(X, y) | ||
self.preprocessor['categorical'] = MinorityCoalesceTransformer(min_frac=self.min_frac) | ||
return self | ||
|
||
@staticmethod | ||
def get_hyperparameter_search_space( | ||
dataset_properties: Optional[Dict[str, Any]] = None, | ||
min_frac: HyperparameterSearchSpace = HyperparameterSearchSpace(hyperparameter='min_frac', | ||
value_range=(1e-4, 0.5), | ||
default_value=1e-2, | ||
), | ||
) -> ConfigurationSpace: | ||
|
||
cs = ConfigurationSpace() | ||
add_hyperparameter(cs, min_frac, UniformFloatHyperparameter) | ||
return cs | ||
|
||
@staticmethod | ||
def get_properties(dataset_properties: Optional[Dict[str, Any]] = None) -> Dict[str, Union[str, bool]]: | ||
return { | ||
'shortname': 'MinorityCoalescer', | ||
'name': 'MinorityCoalescer', | ||
'handles_sparse': False | ||
} |
37 changes: 37 additions & 0 deletions
37
autoPyTorch/pipeline/components/preprocessing/tabular_preprocessing/coalescer/NoCoalescer.py
This file contains 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,37 @@ | ||
from typing import Any, Dict, Optional, Union | ||
|
||
import numpy as np | ||
|
||
from autoPyTorch.pipeline.components.preprocessing.tabular_preprocessing.coalescer.base_coalescer import BaseCoalescer | ||
|
||
|
||
class NoCoalescer(BaseCoalescer): | ||
def __init__(self, random_state: np.random.RandomState): | ||
super().__init__() | ||
self.random_state = random_state | ||
self._processing = False | ||
|
||
def fit(self, X: Dict[str, Any], y: Optional[Any] = None) -> BaseCoalescer: | ||
""" | ||
As no coalescing happens, only check the requirements. | ||
Args: | ||
X (Dict[str, Any]): | ||
fit dictionary | ||
y (Optional[Any]): | ||
Parameter to comply with scikit-learn API. Not used. | ||
Returns: | ||
instance of self | ||
""" | ||
self.check_requirements(X, y) | ||
|
||
return self | ||
|
||
@staticmethod | ||
def get_properties(dataset_properties: Optional[Dict[str, Any]] = None) -> Dict[str, Union[str, bool]]: | ||
return { | ||
'shortname': 'NoCoalescer', | ||
'name': 'NoCoalescer', | ||
'handles_sparse': True | ||
} |
Oops, something went wrong.