Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions cobra/preprocessing/categorical_data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ def _transform_column(self, data: pd.DataFrame,
"""

column_name_clean = column_name + "_processed"
data.loc[:, column_name_clean] = data[column_name].astype(object)
data[column_name_clean] = data[column_name].astype(object)

# Fill missings first
data.loc[:, column_name_clean] = (CategoricalDataProcessor
data[column_name_clean] = (CategoricalDataProcessor
._replace_missings(
data,
column_name_clean
Expand All @@ -329,14 +329,14 @@ def _transform_column(self, data: pd.DataFrame,
"and will be skipped".format(column_name))
return data

data.loc[:, column_name_clean] = (CategoricalDataProcessor
data[column_name_clean] = (CategoricalDataProcessor
._replace_categories(
data[column_name_clean],
categories,
self.regroup_name))

# change data to categorical
data.loc[:, column_name_clean] = (data[column_name_clean]
data[column_name_clean] = (data[column_name_clean]
.astype("category"))

return data
Expand Down
6 changes: 3 additions & 3 deletions cobra/preprocessing/kbins_discretizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,19 @@ def _transform_column(self, data: pd.DataFrame,
column_name_bin = column_name + "_bin"

# use pd.cut to compute bins
data.loc[:, column_name_bin] = pd.cut(x=data[column_name],
data[column_name_bin] = pd.cut(x=data[column_name],
bins=interval_idx)

# Rename bins so that the output has a proper format
bin_labels = self._create_bin_labels(bins)

data.loc[:, column_name_bin] = (data[column_name_bin]
data[column_name_bin] = (data[column_name_bin]
.cat.rename_categories(bin_labels))

if data[column_name_bin].isnull().sum() > 0:

# Add an additional bin for missing values
data[column_name_bin].cat.add_categories(["Missing"], inplace=True)
data[column_name_bin]=data[column_name_bin].cat.add_categories(["Missing"])

# Replace NULL with "Missing"
# Otherwise these will be ignored in groupby
Expand Down
2 changes: 1 addition & 1 deletion tests/preprocessing/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_train_selection_validation_split(
):
X = np.arange(100).reshape(10, 10)
data = pd.DataFrame(X, columns=[f"c{i+1}" for i in range(10)])
data.loc[:, "target"] = np.array([0] * 7 + [1] * 3)
data["target"] = np.array([0] * 7 + [1] * 3)

actual = PreProcessor.train_selection_validation_split(
data, train_prop, selection_prop, validation_prop
Expand Down
6 changes: 2 additions & 4 deletions tests/preprocessing/test_target_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ def test_target_encoder_transform_new_category_binary_classification(self):
'neutral'],
'target': [1, 1, 0, 0, 1, 0, 0, 0, 1, 1]})

df_appended = df.append({"variable": "new", "target": 1},
ignore_index=True)
df_appended = pd.concat([df, pd.DataFrame({"variable": "new", "target": 1}, index=[len(df)])], ignore_index=True)

# inputs of TargetEncoder will be of dtype category
df["variable"] = df["variable"].astype("category")
Expand All @@ -285,8 +284,7 @@ def test_target_encoder_transform_new_category_linear_regression(self):
'neutral', 'positive'],
'target': [5, 4, -5, 0, -4, 5, -5, 0, 1, 0, 4]})

df_appended = df.append({"variable": "new", "target": 10},
ignore_index=True)
df_appended = pd.concat([df, pd.DataFrame({"variable": "new", "target": 10}, index=[len(df)])], ignore_index=True)

# inputs of TargetEncoder will be of dtype category
df["variable"] = df["variable"].astype("category")
Expand Down