Kaggle competition: House Prices - Advanced Regression Techniques
train_ID = train_df['Id']
test_ID = test_df['Id']
train_df.drop("Id", axis = 1, inplace = True)
 test_df.drop("Id", axis = 1, inplace = True)
 train_df = train_df.drop(train_df[(train_df['GrLivArea']>4000)&(train_df['SalePrice']<300000)].index )<prepare_x_and_y>
duplicate_count = train["Id"].nunique() - train.shape[0];
if(duplicate_count == 0):
print("There is no duplicate data in the train data.")
 else:
print("There are %d duplicate data in the train data." %duplicate_count)
 train.drop("Id", axis = 1, inplace = True )
ntrain = train_df.shape[0]
ntest = test_df.shape[0]
y_train = train_df.SalePrice.values
comp_data = pd.concat(( train_df, test_df)).reset_index(drop=True)
 comp_data.drop(['SalePrice'], axis=1, inplace=True)
 print("Comp_data size is : {}".format(comp_data.shape))<create_dataframe>
med = train['SalePrice'].median()
medAbsDev = abs(train['SalePrice'] - med ).median()
ind =(abs(train['SalePrice'] - med)*.6745 / medAbsDev)> 3.5
print("There are suspected %d outliers in the train data." % sum(ind))
train = train[-ind]
train = train[train.GrLivArea < 4000]
missing_val = comp_data.isnull().sum().sort_values(ascending=False)
 missing_val_df = pd.DataFrame({'Feature':missing_val.index, 'Count':missing_val.values})
 missing_val_df = missing_val_df.drop(missing_val_df[missing_val_df.Count == 0].index)
 missing_val_df<data_type_conversions>
train["Alley"].fillna("None", inplace=True)
 train["BsmtQual"].fillna("None", inplace=True)
 train["BsmtCond"].fillna("None", inplace=True)
 train["BsmtExposure"].fillna("None", inplace=True)
 train["BsmtFinType1"].fillna("None", inplace=True)
 train["BsmtFinSF1"].fillna(0, inplace=True)
 train["BsmtFinType2"].fillna("None", inplace=True)
 train["BsmtFinSF2"].fillna(0, inplace=True)
 train["BsmtFullBath"].fillna(0, inplace=True)
 train["BsmtHalfBath"].fillna(0, inplace=True)
 train["BsmtUnfSF"].fillna(0, inplace=True)
 train["TotalBsmtSF"].fillna(0, inplace=True)
 train["KitchenQual"].fillna(0, inplace=True)
 train["Functional"].fillna(0, inplace=True)
 train["FireplaceQu"].fillna("None", inplace=True)
 train["GarageType"].fillna("None", inplace=True)
 train["GarageQual"].fillna(0, inplace=True)
 train["GarageCond"].fillna(0, inplace=True)
 train["GarageYrBlt"].fillna("None", inplace=True)
 train["GarageFinish"].fillna("None", inplace=True)
 train["GarageCars"].fillna(0, inplace=True)
 train["GarageArea"].fillna(0, inplace=True)
 train["PoolQC"].fillna("None", inplace=True)
 train["Fence"].fillna("None", inplace=True)
 train["MiscFeature"].fillna("None", inplace=True)
 train["LotFrontage"].fillna(0, inplace=True)
 train["MasVnrType"].fillna("None", inplace=True)
 train["MasVnrArea"].fillna(0, inplace=True)
 train["Electrical"].fillna("SBrkr", inplace=True)
 train["Utilities"].fillna("None", inplace=True)
comp_data["LotFrontage"] = comp_data.groupby("Neighborhood")["LotFrontage"].transform(
 lambda x: x.fillna(x.median()))
for col in('GarageYrBlt', 'GarageArea', 'GarageCars'):
comp_data[col] = comp_data[col].fillna(0)
 for col in('BsmtFinSF1', 'BsmtFinSF2', 'BsmtUnfSF','TotalBsmtSF', 'BsmtFullBath', 'BsmtHalfBath'):
comp_data[col] = comp_data[col].fillna(0)
 comp_data['MSZoning'] = comp_data['MSZoning'].fillna(comp_data['MSZoning'].mode() [0])
 comp_data["MasVnrArea"] = comp_data["MasVnrArea"].fillna(0)
 comp_data['Electrical'] = comp_data['Electrical'].fillna(comp_data['Electrical'].mode() [0])
 comp_data['SaleType'] = comp_data['SaleType'].fillna(comp_data['SaleType'].mode() [0])
 comp_data['KitchenQual'] = comp_data['KitchenQual'].fillna(comp_data['KitchenQual'].mode() [0])
 comp_data['Exterior1st'] = comp_data['Exterior1st'].fillna(comp_data['Exterior1st'].mode() [0])
 comp_data['Exterior2nd'] = comp_data['Exterior2nd'].fillna(comp_data['Exterior2nd'].mode() [0] )<data_type_conversions>
train = train.replace({"MSSubClass" : {20 : "SC20", 30 : "SC30", 40 : "SC40", 45 : "SC45", 50 : "SC50", 60 : "SC60",
70 : "SC70", 75 : "SC75", 80 : "SC80", 85 : "SC85", 90 : "SC90", 120 : "SC120", 150 : "SC150", 160 : "SC160",
180 : "SC180", 190 : "SC190"},
"MoSold" : {1 : "Jan", 2 : "Feb", 3 : "Mar", 4 : "Apr", 5 : "May", 6 : "Jun", 7 : "Jul", 8 : "Aug", 9 : "Sep",
10 : "Oct", 11 : "Nov", 12 : "Dec"} })
 train = train.replace({"Alley" : {"Grvl" : 1, "Pave" : 2},
"BsmtCond" : {"No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"BsmtExposure" : {"No" : 0, "Mn" : 1, "Av": 2, "Gd" : 3},
"BsmtFinType1" : {"No" : 0, "Unf" : 1, "LwQ": 2, "Rec" : 3, "BLQ" : 4, "ALQ" : 5, "GLQ" : 6},
"BsmtFinType2" : {"No" : 0, "Unf" : 1, "LwQ": 2, "Rec" : 3, "BLQ" : 4, "ALQ" : 5, "GLQ" : 6},
"BsmtQual" : {"No" : 0, "Po" : 1, "Fa" : 2, "TA": 3, "Gd" : 4, "Ex" : 5},
"ExterCond" : {"Po" : 1, "Fa" : 2, "TA": 3, "Gd": 4, "Ex" : 5},
"ExterQual" : {"Po" : 1, "Fa" : 2, "TA": 3, "Gd": 4, "Ex" : 5},
"FireplaceQu" : {"No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"Functional" : {"Sal" : 1, "Sev" : 2, "Maj2" : 3, "Maj1" : 4, "Mod": 5, "Min2" : 6, "Min1" : 7, "Typ" : 8},
"GarageCond" : {"None" : 0, "No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"GarageQual" : {"None" : 0, "No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"HeatingQC" : {"Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"KitchenQual" : {"Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"LandSlope" : {"Sev" : 1, "Mod" : 2, "Gtl" : 3},
"LotShape" : {"IR3" : 1, "IR2" : 2, "IR1" : 3, "Reg" : 4},
"PavedDrive" : {"N" : 0, "P" : 1, "Y" : 2},
"PoolQC" : {"No" : 0, "Fa" : 1, "TA" : 2, "Gd" : 3, "Ex" : 4},
"Street" : {"Grvl" : 1, "Pave" : 2},
"Utilities" : {"None" : 0, "ELO" : 1, "NoSeWa" : 2, "NoSewr" : 3, "AllPub" : 4}} )
for col in('PoolQC', 'MiscFeature', 'Alley'):
comp_data[col] = comp_data[col].fillna('None')
 comp_data["MasVnrType"] = comp_data["MasVnrType"].fillna("None")
 comp_data["Fence"] = comp_data["Fence"].fillna("None")
 comp_data["FireplaceQu"] = comp_data["FireplaceQu"].fillna("None")
 for col in('GarageType', 'GarageFinish', 'GarageQual', 'GarageCond'):
comp_data[col] = comp_data[col].fillna('None')
 for col in('BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2'):
comp_data[col] = comp_data[col].fillna('None')
 comp_data['MSSubClass'] = comp_data['MSSubClass'].fillna("None")
 comp_data['SaleType'] = comp_data['SaleType'].fillna(comp_data['SaleType'].mode() [0])
 comp_data = comp_data.drop(['Utilities'], axis=1)
 comp_data['OverallCond'] = comp_data['OverallCond'].astype(str)
 comp_data["Functional"] = comp_data["Functional"].fillna("Typ")
<data_type_conversions>
train["OverallGrade"] = train["OverallQual"] * train["OverallCond"]
train["GarageGrade"] = train["GarageQual"] * train["GarageCond"]
train["ExterGrade"] = train["ExterQual"] * train["ExterCond"]
train["KitchenScore"] = train["KitchenAbvGr"] * train["KitchenQual"]
train["FireplaceScore"] = train["Fireplaces"] * train["FireplaceQu"]
train["GarageScore"] = train["GarageArea"] * train["GarageQual"]
train["PoolScore"] = train["PoolArea"] * train["PoolQC"]
train["TotalBath"] = train["BsmtFullBath"] + train["BsmtHalfBath"]/2 + train["FullBath"] + train["HalfBath"]/2
train["AllSF"] = train["GrLivArea"] + train["TotalBsmtSF"]
train["AllFlrsSF"] = train["1stFlrSF"] + train["2ndFlrSF"]
train["AllPorchSF"] = train["OpenPorchSF"] + train["EnclosedPorch"] + train["3SsnPorch"] + train["ScreenPorch"]
comp_data['MSSubClass'] = comp_data['MSSubClass'].apply(str)
 comp_data['YrSold'] = comp_data['YrSold'].astype(str)
 comp_data['MoSold'] = comp_data['MoSold'].astype(str)
 columns =('FireplaceQu', 'BsmtQual', 'BsmtCond', 'GarageQual', 'GarageCond',
'ExterQual', 'ExterCond','HeatingQC', 'PoolQC', 'KitchenQual', 'BsmtFinType1',
'BsmtFinType2', 'Functional', 'Fence', 'BsmtExposure', 'GarageFinish', 'LandSlope',
'LotShape', 'PavedDrive', 'Street', 'Alley', 'CentralAir', 'MSSubClass', 'OverallCond',
'YrSold', 'MoSold')
 for col in columns:
labl = LabelEncoder()
labl.fit(list(comp_data[col].values))
comp_data[col] = labl.transform(list(comp_data[col].values))
print('Shape all_data: {}'.format(comp_data.shape))
comp_data['TotalSF'] = comp_data['TotalBsmtSF'] + comp_data['1stFlrSF'] + comp_data['2ndFlrSF']<feature_engineering>
corr = train.corr()
corr.sort_values(["SalePrice"], ascending = False, inplace = True)
 corr.SalePrice
skewness = skewness[abs(skewness)> 0.75]
print("There are {} skewed numerical features to Box Cox transform".format(skewness.shape[0]))
skewed_features = skewness.index
lam = 0.15
for feat in skewed_features:
comp_data[feat] = boxcox1p(comp_data[feat], lam )<categorify>
train["AllSF-s2"] = train["AllSF"] ** 2
train["AllSF-Sq"] = np.sqrt(train["AllSF"])
 train["OverallQual-s2"] = train["OverallQual"] ** 2
train["OverallQual-Sq"] = np.sqrt(train["OverallQual"])
 train["AllFlrsSF-s2"] = train["AllFlrsSF"] ** 2
train["AllFlrsSF-Sq"] = np.sqrt(train["AllFlrsSF"])
 train["GrLivArea-s2"] = train["GrLivArea"] ** 2
train["GrLivArea-Sq"] = np.sqrt(train["GrLivArea"])
 train["ExterQual-s2"] = train["ExterQual"] ** 2
train["ExterQual-Sq"] = np.sqrt(train["ExterQual"] )
comp_data = pd.get_dummies(comp_data)
 print(comp_data.shape )<split>
categorical_features = train.select_dtypes(include = ["object"] ).columns
numerical_features = train.select_dtypes(exclude = ["object"] ).columns
numerical_features = numerical_features.drop("SalePrice")
 train_num = train[numerical_features]
train_cat = train[categorical_features]
skewness = train_num.apply(lambda x: skew(x))
skewness = skewness[abs(skewness)> 0.5]
print("%d out of %d numerical features are skewed.Apply log transform to these features." %(skewness.shape[0],
train_num.shape[1]))
train_num.loc[:,skewness.index] = np.log1p(np.asarray(train_num[skewness.index] , dtype=float))
train_cat = pd.get_dummies(train_cat )
train_df = comp_data[:ntrain]
test_df = comp_data[ntrain:]<compute_train_metric>
y = np.log1p(train["SalePrice"])
 X_train, X_test, y_train, y_test = train_test_split(pd.concat([train_num, train_cat], axis = 1),
y, test_size = 0.3, random_state = 514)
 stdSc = StandardScaler()
X_train.loc[:, numerical_features] = stdSc.fit_transform(X_train.loc[:, numerical_features])
 X_test.loc[:, numerical_features] = stdSc.transform(X_test.loc[:, numerical_features] )
n_folds = 5
def rmsle_cv(model):
kf = KFold(n_folds, shuffle=True, random_state=42 ).get_n_splits(train_df.values)
 rmse= np.sqrt(-cross_val_score(model, train_df.values, y_train, scoring="neg_mean_squared_error", cv = kf))
return(rmse )<choose_model_class>
scorer = make_scorer(mean_squared_error, greater_is_better = True)
 def rmse_cv_train(model):
rmse = np.sqrt(cross_val_score(model, X_train, y_train, scoring = scorer, cv = 10))
return(rmse)
 def rmse_cv_test(model):
rmse = np.sqrt(cross_val_score(model, X_test, y_test, scoring = scorer, cv = 10))
return(rmse )
lasso = make_pipeline(RobustScaler() , Lasso(alpha =0.0005, random_state=1))
ENet = make_pipeline(RobustScaler() , ElasticNet(alpha=0.0005, l1_ratio=.9, random_state=3))
KRR = KernelRidge(alpha=0.6, kernel='polynomial', degree=2, coef0=2.5)
 GBoost = GradientBoostingRegressor(n_estimators=3000, learning_rate=0.05,
max_depth=4, max_features='sqrt',
min_samples_leaf=15, min_samples_split=10,
loss='huber', random_state =5)
 model_xgb = xgb.XGBRegressor(colsample_bytree=0.4603, gamma=0.0468,
learning_rate=0.05, max_depth=3,
min_child_weight=1.7817, n_estimators=2200,
reg_alpha=0.4640, reg_lambda=0.8571,
subsample=0.5213, silent=1,
random_state =7, nthread = -1)
 model_lgb = lgb.LGBMRegressor(objective='regression',num_leaves=5,
learning_rate=0.05, n_estimators=720,
max_bin = 55, bagging_fraction = 0.8,
bagging_freq = 5, feature_fraction = 0.2319,
feature_fraction_seed=9, bagging_seed=9,
min_data_in_leaf =6, min_sum_hessian_in_leaf = 11)
 score = rmsle_cv(lasso)
 print("
Lasso score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))
score = rmsle_cv(ENet)
 print("ElasticNet score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))
score = rmsle_cv(KRR)
 print("Kernel Ridge score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))
score = rmsle_cv(GBoost)
 print("Gradient Boosting score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))
score = rmsle_cv(model_xgb)
 print("Xgboost score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))
score = rmsle_cv(model_lgb)
 print("LGBM score: {:.4f}({:.4f})
 ".format(score.mean() , score.std()))<compute_test_metric>
elasticNet = ElasticNetCV(l1_ratio = [0.1, 0.3, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9, 0.95, 1],
alphas = [0.0001, 0.001, 0.01, 0.1, 1],
max_iter = 50000, cv = 10)
 elasticNet.fit(X_train, y_train)
 alpha = elasticNet.alpha_
ratio = elasticNet.l1_ratio_
print("Best l1_ratio :", ratio)
 print("Best alpha :", alpha )
def rmsle(y, y_pred):
return np.sqrt(mean_squared_error(y, y_pred))<predict_on_test>
print("Try again for more precision with l1_ratio centered around " + str(ratio))
elasticNet = ElasticNetCV(l1_ratio = [ratio *.9, ratio *.95, ratio, ratio * 1.05, ratio * 1.1],
alphas = [0.0001, 0.001, 0.01, 0.1, 1],
max_iter = 50000, cv = 10)
 elasticNet.fit(X_train, y_train)
 alpha = elasticNet.alpha_
ratio = elasticNet.l1_ratio_
print("Best l1_ratio :", ratio)
 print("Best alpha :", alpha )
model_xgb.fit(train_df, y_train)
 xgb_train_pred = model_xgb.predict(train_df)
 xgb_pred = np.expm1(model_xgb.predict(test_df))
print(rmsle(y_train, xgb_train_pred))<predict_on_test>
print("Now try again for more precision on alpha, with l1_ratio fixed at " + str(ratio)+
" and alpha centered around " + str(alpha))
elasticNet = ElasticNetCV(l1_ratio = ratio,
alphas = [alpha *.6, alpha *.7, alpha *.8, alpha *.9,
alpha, alpha * 1.1, alpha * 1.2, alpha * 1.3, alpha * 1.4],
max_iter = 50000, cv = 5)
 elasticNet.fit(X_train, y_train)
 print("Best l1_ratio :", elasticNet.l1_ratio_)
 print("Best alpha :", elasticNet.alpha_)
 print("ElasticNet RMSE on Training set :", rmse_cv_train(elasticNet ).mean())
 print("ElasticNet RMSE on Test set :", rmse_cv_test(elasticNet ).mean())
 y_train_ela = elasticNet.predict(X_train)
 y_test_ela = elasticNet.predict(X_test )
model_lgb.fit(train_df, y_train)
 lgb_train_pred = model_lgb.predict(train_df)
 lgb_pred = np.expm1(model_lgb.predict(test_df.values))
print(rmsle(y_train, lgb_train_pred))<define_variables>
test = pd.read_csv("/kaggle/input/house-prices-advanced-regression-techniques/test.csv")
 test["Alley"].fillna("None", inplace=True)
 test["BsmtQual"].fillna("None", inplace=True)
 test["BsmtCond"].fillna("None", inplace=True)
 test["BsmtExposure"].fillna("None", inplace=True)
 test["BsmtFinType1"].fillna("None", inplace=True)
 test["BsmtFinSF1"].fillna(0, inplace=True)
 test["BsmtFinType2"].fillna("None", inplace=True)
 test["BsmtFinSF2"].fillna(0, inplace=True)
 test["BsmtFullBath"].fillna(0, inplace=True)
 test["BsmtHalfBath"].fillna(0, inplace=True)
 test["BsmtUnfSF"].fillna(0, inplace=True)
 test["TotalBsmtSF"].fillna(0, inplace=True)
 test["KitchenQual"].fillna(0, inplace=True)
 test["Functional"].fillna(0, inplace=True)
 test["FireplaceQu"].fillna("None", inplace=True)
 test["GarageType"].fillna("None", inplace=True)
 test["GarageQual"].fillna(0, inplace=True)
 test["GarageCond"].fillna(0, inplace=True)
 test["GarageYrBlt"].fillna("None", inplace=True)
 test["GarageFinish"].fillna("None", inplace=True)
 test["GarageCars"].fillna(0, inplace=True)
 test["GarageArea"].fillna(0, inplace=True)
 test["PoolQC"].fillna("None", inplace=True)
 test["Fence"].fillna("None", inplace=True)
 test["MiscFeature"].fillna("None", inplace=True)
 test["LotFrontage"].fillna(0, inplace=True)
 test["MasVnrType"].fillna("None", inplace=True)
 test["MasVnrArea"].fillna(0, inplace=True)
 test["Electrical"].fillna("SBrkr", inplace=True)
 test["Utilities"].fillna("None", inplace=True)
 test = test.replace({"MSSubClass" : {20 : "SC20", 30 : "SC30", 40 : "SC40", 45 : "SC45", 50 : "SC50", 60 : "SC60",
70 : "SC70", 75 : "SC75", 80 : "SC80", 85 : "SC85", 90 : "SC90", 120 : "SC120", 150 : "SC150", 160 : "SC160",
180 : "SC180", 190 : "SC190"},
"MoSold" : {1 : "Jan", 2 : "Feb", 3 : "Mar", 4 : "Apr", 5 : "May", 6 : "Jun", 7 : "Jul", 8 : "Aug", 9 : "Sep",
10 : "Oct", 11 : "Nov", 12 : "Dec"} })
 test = test.replace({"Alley" : {"Grvl" : 1, "Pave" : 2},
"BsmtCond" : {"No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"BsmtExposure" : {"No" : 0, "Mn" : 1, "Av": 2, "Gd" : 3},
"BsmtFinType1" : {"No" : 0, "Unf" : 1, "LwQ": 2, "Rec" : 3, "BLQ" : 4, "ALQ" : 5, "GLQ" : 6},
"BsmtFinType2" : {"No" : 0, "Unf" : 1, "LwQ": 2, "Rec" : 3, "BLQ" : 4, "ALQ" : 5, "GLQ" : 6},
"BsmtQual" : {"No" : 0, "Po" : 1, "Fa" : 2, "TA": 3, "Gd" : 4, "Ex" : 5},
"ExterCond" : {"Po" : 1, "Fa" : 2, "TA": 3, "Gd": 4, "Ex" : 5},
"ExterQual" : {"Po" : 1, "Fa" : 2, "TA": 3, "Gd": 4, "Ex" : 5},
"FireplaceQu" : {"No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"Functional" : {"Sal" : 1, "Sev" : 2, "Maj2" : 3, "Maj1" : 4, "Mod": 5, "Min2" : 6, "Min1" : 7, "Typ" : 8},
"GarageCond" : {"None" : 0, "No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"GarageQual" : {"None" : 0, "No" : 0, "Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"HeatingQC" : {"Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"KitchenQual" : {"Po" : 1, "Fa" : 2, "TA" : 3, "Gd" : 4, "Ex" : 5},
"LandSlope" : {"Sev" : 1, "Mod" : 2, "Gtl" : 3},
"LotShape" : {"IR3" : 1, "IR2" : 2, "IR1" : 3, "Reg" : 4},
"PavedDrive" : {"N" : 0, "P" : 1, "Y" : 2},
"PoolQC" : {"No" : 0, "Fa" : 1, "TA" : 2, "Gd" : 3, "Ex" : 4},
"Street" : {"Grvl" : 1, "Pave" : 2},
"Utilities" : {"None" : 0, "ELO" : 1, "NoSeWa" : 2, "NoSewr" : 3, "AllPub" : 4}})
 test["OverallGrade"] = test["OverallQual"] * test["OverallCond"]
test["GarageGrade"] = test["GarageQual"] * test["GarageCond"]
test["ExterGrade"] = test["ExterQual"] * test["ExterCond"]
test["KitchenScore"] = test["KitchenAbvGr"] * test["KitchenQual"]
test["FireplaceScore"] = test["Fireplaces"] * test["FireplaceQu"]
test["GarageScore"] = test["GarageArea"] * test["GarageQual"]
test["PoolScore"] = test["PoolArea"] * test["PoolQC"]
test["TotalBath"] = test["BsmtFullBath"] + test["BsmtHalfBath"]/2 + test["FullBath"] + test["HalfBath"]/2
test["AllSF"] = test["GrLivArea"] + test["TotalBsmtSF"]
test["AllFlrsSF"] = test["1stFlrSF"] + test["2ndFlrSF"]
test["AllPorchSF"] = test["OpenPorchSF"] + test["EnclosedPorch"] + test["3SsnPorch"] + test["ScreenPorch"]
test["AllSF-s2"] = test["AllSF"] ** 2
test["AllSF-Sq"] = np.sqrt(test["AllSF"])
 test["OverallQual-s2"] = test["OverallQual"] ** 2
test["OverallQual-Sq"] = np.sqrt(test["OverallQual"])
 test["AllFlrsSF-s2"] = test["AllFlrsSF"] ** 2
test["AllFlrsSF-Sq"] = np.sqrt(test["AllFlrsSF"])
 test["GrLivArea-s2"] = test["GrLivArea"] ** 2
test["GrLivArea-Sq"] = np.sqrt(test["GrLivArea"])
 test["ExterQual-s2"] = test["ExterQual"] ** 2
test["ExterQual-Sq"] = np.sqrt(test["ExterQual"])
 test_num = test[numerical_features]
test_cat = test[categorical_features]
test_num.loc[:,skewness.index] = np.log1p(np.asarray(test_num[skewness.index] , dtype=float))
test_cat = pd.get_dummies(test_cat)
 test_processed = pd.concat([test_num, test_cat], axis = 1)
 test_processed.loc[:, numerical_features] = stdSc.transform(test_processed.loc[:, numerical_features] )
<save_to_csv><EOS> 
final_train, final_test = X_train.align(test_processed, join='left', axis=1, fill_value=0)
 y_test = elasticNet.predict(final_test)
 sub = pd.DataFrame()
sub['Id'] = test["Id"]
sub['SalePrice'] = np.expm1(y_test)
 sub.to_csv('submission.csv',index=False )