-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mykola Lukashchouk
authored and
Mykola Lukashchouk
committed
Mar 25, 2021
1 parent
21182bf
commit cfe2b5a
Showing
3 changed files
with
37 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
import numpy as np | ||
from sklearn.metrics import mean_squared_error, r2_score | ||
|
||
def generate_poly_features(df, cols, max_degree=3): | ||
""" | ||
Function to add polynomial transformation (x -> x^i) for column names in cols (iterable) in df (Dataframe) | ||
max_degree - maximum degree of polynomial features to be added | ||
""" | ||
df = df.copy() | ||
for col in cols: | ||
for degree in range(max_degree): | ||
for degree in range(1, max_degree+1): | ||
df[f"{col}^{degree}"] = df[col]**degree | ||
return df | ||
|
||
def summary_model(estimator, summary_name, X, y): | ||
|
||
y_pred = estimator.predict(X) | ||
r2 = r2_score(y, y_pred) | ||
rmse = np.sqrt(mean_squared_error(y, y_pred)) | ||
|
||
print(f"The model performance for {summary_name}") | ||
print("--------------------------------------") | ||
print('RMSE is {}'.format(rmse)) | ||
print('R2 score is {}'.format(r2)) | ||
print("\n") | ||
|
||
|
||
|
||
|
||
|