-
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.
feat: update data.py and data_v3 which is unfinish function
- Loading branch information
1 parent
1a68d1e
commit 8b54bb8
Showing
2 changed files
with
98 additions
and
63 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import json | ||
import numpy as np | ||
|
||
|
||
|
||
# Function to save scaler parameters to a JSON file | ||
def save_scaler_params(scaler, path): | ||
params = { | ||
"mean": scaler.mean_.tolist() if hasattr(scaler, 'mean_') else None, | ||
"scale": scaler.scale_.tolist() if hasattr(scaler, 'scale_') else None, | ||
"min": scaler.data_min_.tolist() if hasattr(scaler, 'data_min_') else None, | ||
"max": scaler.data_max_.tolist() if hasattr(scaler, 'data_max_') else None | ||
} | ||
with open(path, 'w') as file: | ||
json.dump(params, file) | ||
|
||
# Function to load scaler parameters from a JSON file | ||
def load_scaler_params(path): | ||
with open(path, 'r') as file: | ||
params = json.load(file) | ||
return params | ||
|
||
|
||
|
||
class HousePriceTestDataset(Dataset): | ||
def __init__(self, dataframe, feature_columns, normalize_columns=None): | ||
self.dataframe = dataframe.copy() # Creating a copy to avoid modifying the original dataframe | ||
|
||
# Applying the specified normalization methods to the specified columns | ||
if normalize_columns: | ||
for column, method in normalize_columns.items(): | ||
if method == 'z-score': | ||
self.dataframe = z_score_normalize(self.dataframe, [column]) | ||
elif method == 'min-max': | ||
self.dataframe = min_max_normalize(self.dataframe, [column]) | ||
|