Skip to content

Instantly share code, notes, and snippets.

View tiaplagata's full-sized avatar

Tia Plagata tiaplagata

View GitHub Profile
@tiaplagata
tiaplagata / gist:593c6b3c989665d3b528286cbb6f24c4
Created October 19, 2020 14:01
Function to Inverse a Standard Normal Scaled Target
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
@tiaplagata
tiaplagata / gist:77b3eb6a9c7a8a9e1c05cc7958c914bc
Created October 9, 2020 16:07
Standard Normalize Features for Linear Regression
# 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)
@tiaplagata
tiaplagata / gist:9082274f6eb15000d9694f5b699ece20
Created October 9, 2020 15:57
Log Transformation of Target Feature in Linear Model
# 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