Skip to content

Instantly share code, notes, and snippets.

@dkapitan
Created November 21, 2021 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkapitan/fb332df121d9116e9cfe48cc94a9d578 to your computer and use it in GitHub Desktop.
Save dkapitan/fb332df121d9116e9cfe48cc94a9d578 to your computer and use it in GitHub Desktop.
Polynomial
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