-
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
- Loading branch information
1 parent
2601421
commit 3efadc3
Showing
12 changed files
with
666 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
29 changes: 29 additions & 0 deletions
29
...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,29 @@ | ||
from typing import Any, Dict, Optional, Union | ||
|
||
import numpy as np | ||
|
||
from autoPyTorch.pipeline.components.preprocessing.tabular_preprocessing.coalescer.base_coalescer import BaseCoalescer | ||
from autoPyTorch.utils.implementations import MinorityCoalesceTransformer | ||
|
||
|
||
class MinorityCoalescer(BaseCoalescer): | ||
"""Group together categories whose occurence is less than a specified min_fraction """ | ||
def __init__(self, min_fraction: float, random_state: np.random.RandomState): | ||
super().__init__() | ||
self.min_fraction = min_fraction | ||
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_fraction=self.min_fraction) | ||
return self | ||
|
||
@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.