This file contains hidden or 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 inv_normalize_price(feature_normalized): | |
""" | |
input the standard normal scaled target feature as an array | |
output the same array without the standard normal scale | |
""" | |
mu = df_log['price_log'].mean() | |
sd = df_log['price_log'].std() | |
return sd*feature_normalized + mu |
This file contains hidden or 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
# Write function to standard normalize one feature | |
def std_normalize_feature(feature): | |
""" | |
input a feature column name | |
returns series of normalized feature values | |
""" | |
return (feature - feature.mean()) / feature.std() | |
# Apply function to our previous log_df | |
df_log_normal = df_log.apply(std_normalize_feature) |
This file contains hidden or 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
# Our main dataframe is df | |
continuous = ['price', 'sqft_living', 'sqft_lot', 'sqft_living15', 'sqft_lot15'] | |
df_log = df[continuous] | |
# Create column names that indicate a log ex. 'price_log' | |
log_names = [f'{column}_log' for column in df_log.columns] | |
df_log = np.log10(df_log) | |
df_log.columns = log_names |
NewerOlder