Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
359b4c9
Initial try at an enhancement for the tabular validator
ArlindKadra Oct 1, 2021
65e8ffb
Adding a few type annotations
ArlindKadra Oct 1, 2021
217c38d
Fixing bugs in implementation
ArlindKadra Oct 1, 2021
f7dd8fe
Adding wrongly deleted code part during rebase
ArlindKadra Oct 1, 2021
92bd535
Fix bug in _get_args
ravinkohli Oct 2, 2021
5f672b5
Fix bug in _get_args
ravinkohli Oct 2, 2021
223c09e
Addressing Shuhei's comments
ArlindKadra Oct 3, 2021
a1ed883
Address Shuhei's comments
ArlindKadra Oct 3, 2021
f585310
Refactoring code
ArlindKadra Oct 6, 2021
f298c46
Refactoring code
ArlindKadra Oct 6, 2021
03bef16
Typos fix and additional comments
ArlindKadra Oct 6, 2021
a7d01f1
Replace nan in categoricals with simple imputer
ravinkohli Oct 7, 2021
38fe9e8
Remove unused function
ravinkohli Oct 7, 2021
7693753
add comment
ravinkohli Oct 7, 2021
f4cd3a4
Merge branch 'cocktail_fixes_time_debug' into tabular_validator_enhan…
ravinkohli Oct 7, 2021
497c546
Update autoPyTorch/data/tabular_feature_validator.py
ravinkohli Oct 7, 2021
9254eb2
Update autoPyTorch/data/tabular_feature_validator.py
ravinkohli Oct 7, 2021
b63ff3c
Adding unit test for only nall columns in the tabular feature categor…
ArlindKadra Oct 8, 2021
d5bbdbe
fix bug in remove all nan columns
ravinkohli Oct 8, 2021
bfe4899
Bug fix for making tests run by arlind
ravinkohli Oct 8, 2021
369edad
fix flake errors in feature validator
ravinkohli Oct 8, 2021
a4fb0cb
made typing code uniform
ravinkohli Oct 8, 2021
44229a6
Apply suggestions from code review
ravinkohli Oct 8, 2021
ba3c1e7
address comments from shuhei
ravinkohli Oct 8, 2021
10a8441
address comments from shuhei (2)
ravinkohli Oct 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 20 additions & 34 deletions autoPyTorch/data/tabular_feature_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,13 @@ def get_tabular_preprocessors() -> Dict[str, List[BaseEstimator]]:
Dict[str, List[BaseEstimator]]
"""
preprocessors: Dict[str, List[BaseEstimator]] = dict()
preprocessors['numerical'] = list()
preprocessors['categorical'] = list()

preprocessors['categorical'].append(
OneHotEncoder(
categories='auto',
sparse=False,
handle_unknown='ignore',
)
)
preprocessors['numerical'].append(
SimpleImputer(
strategy='median',
copy=False,
)
)
preprocessors['numerical'].append(
StandardScaler(
with_mean=True,
with_std=True,
copy=False,
)
)

onehot_encoder = OneHotEncoder(categories='auto', sparse=False, handle_unknown='ignore')
imputer = SimpleImputer(strategy='median', copy=False)
standard_scaler = StandardScaler(with_mean=True, with_std=True, copy=False)

preprocessors['categorical'] = [onehot_encoder]
preprocessors['numerical'] = [imputer, standard_scaler]

return preprocessors

Expand Down Expand Up @@ -161,7 +145,7 @@ def comparator(cmp1: str, cmp2: str) -> int:

if len(categorical_columns) > 0:
self.categories = [
# We fit an one-hot encoder, where all categorical
# We fit a one-hot encoder, where all categorical
# columns are shifted to the left
list(range(len(cat)))
for cat in self.column_transformer.named_transformers_[
Expand Down Expand Up @@ -477,7 +461,8 @@ def infer_objects(self, X: pd.DataFrame) -> pd.DataFrame:
X[column] = X[column].astype('category')
# only numerical attributes and categories
data_types = X.dtypes
self.object_dtype_mapping = {column: data_types[index] for index, column in enumerate(X.columns)}
self.object_dtype_mapping = {column: data_type for column, data_type in zip(X.columns, X.dtypes)}

self.logger.debug(f"Infer Objects: {self.object_dtype_mapping}")

return X
Expand All @@ -504,13 +489,16 @@ def impute_nan_in_categories(self, X: pd.DataFrame) -> pd.DataFrame:
# TypeError: '<' not supported between instances of 'int' and 'str'
# in the encoding
for column in self.enc_columns:
if X[column].isna().any():
# no missing values for categorical column
if not X[column].isna().any():
continue
else:
Comment thread
ravinkohli marked this conversation as resolved.
Outdated
if column not in self.dict_missing_value_per_col:
try:
first_value = X[column].dropna().values[0]
float(first_value)
can_cast_as_number = True
except Exception:
except ValueError:
can_cast_as_number = False
if can_cast_as_number:
# In this case, we expect to have a number as category
Expand Down Expand Up @@ -555,10 +543,8 @@ def has_object_columns(
True if the DataFrame dtypes contain an object column, False
otherwise.
"""
object_columns_indicator = [True if pd.api.types.is_object_dtype(feature_type) else False
for feature_type in feature_types]

if True in object_columns_indicator:
return True
else:
return False
for feature_type in feature_types:
if pd.api.types.is_object_dtype(feature_type):
return True
else:
return False
Comment thread
ravinkohli marked this conversation as resolved.
Outdated