Skip to content

Commit d9ac3cb

Browse files
committed
edit ignore col poly
1 parent 0275edb commit d9ac3cb

1 file changed

Lines changed: 1 addition & 50 deletions

File tree

test/test_ignore_columns_polyfeatures.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,4 @@ def test_log_transform_data_ignore():
2929

3030
df_processed = ignore_columns_polyfeatures(df, variables_to_ignore = ['a', 'd', 'e'], n = 2)
3131

32-
assert len(df_processed.columns) == 13
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
def ignore_columns_polyfeatures(X: pd.DataFrame, variables_to_ignore: List[str], n: int) -> pd.DataFrame:
51-
'''
52-
This function takes a dataframe as input and will create n polynomial features for all columns except those specified to ignore
53-
It is intended to be used to ignore binary columns for example and to be included in a Pipeline
54-
55-
Parameters
56-
----------
57-
X : dataframe
58-
It is the dataset we want to selectively create polynomial features
59-
variables_to_ignore : List[str]
60-
a list of column names to ignore in the polynomial feature creation
61-
n : int
62-
the degree for the polynomial fearture creation
63-
64-
65-
Return
66-
----------
67-
df : Dataframe with the changes made
68-
'''
69-
X_poly_features = X.drop(columns = variables_to_ignore)
70-
71-
X_ignore = X[variables_to_ignore].reset_index(drop = True)
72-
73-
poly = PolynomialFeatures(degree = n)
74-
75-
poly_array = poly.fit_transform(X_poly_features)
76-
77-
poly_features_names = poly.get_feature_names_out(X_poly_features.columns)
78-
79-
X_poly_features = pd.DataFrame(poly_array, columns = poly_features_names)
80-
81-
return pd.concat([X_ignore, X_poly_features], axis = 1)
32+
assert len(df_processed.columns) == 13

0 commit comments

Comments
 (0)