Created
November 21, 2021 19:10
-
-
Save dkapitan/fb332df121d9116e9cfe48cc94a9d578 to your computer and use it in GitHub Desktop.
Polynomial
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
def make_polynomial(dataframe, degree=MAX_DEGREE): | |
"""Function for creating higher-order polynomial features from dataframe. | |
Dataframe df should be like [Y, X1, X2, .. Xi]. | |
Returns dataframe polynomial features of X1 ... Xi up to degree polynomials.""" | |
df = dataframe.copy() | |
cols = df.columns[1:] | |
for i in range(2, degree + 1): | |
for col in cols: | |
df["**".join([col, str(i)])] = df[col] ** i | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment