Kaggle competition: House Prices - Advanced Regression Techniques
oof_nn = np.zeros(len(train))
preds_nn = np.zeros(len(test))<concatenate>
train= pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/train.csv')
 test=pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/test.csv')
%%time
for i in tqdm_notebook(range(512)) :
train2 = train[train['wheezy-copper-turtle-magic']==i]
test2 = test[test['wheezy-copper-turtle-magic']==i]
idx1 = train2.index
idx2 = test2.index
train2.reset_index(drop=True, inplace=True)
 test2.reset_index(drop=True, inplace=True)
 steps = [ 
('vt', VarianceThreshold(threshold=1.5)) , 
('poly', PolynomialFeatures(degree=2)) , 
('sc', StandardScaler())
 ]
pipe = Pipeline(steps=steps)
 data = pd.concat([pd.DataFrame(train2[cols]), pd.DataFrame(test2[cols])])
 data2 = pipe.fit_transform(data[cols])
 train3 = data2[:train2.shape[0]]
test3 = data2[train2.shape[0]:]
skf = StratifiedKFold(n_splits=11, random_state=42, shuffle=True)
 for train_index, test_index in skf.split(train3, train2['target']):
clf = MLPClassifier(random_state=3, activation='relu', solver='lbfgs', tol=1e-06, hidden_layer_sizes=(250,))
clf.fit(train3[train_index,:], train2.loc[train_index]['target'])
 oof_nn[idx1[test_index]] = clf.predict_proba(train3[test_index,:])[:,1]
preds_nn[idx2] += clf.predict_proba(test3)[:,1] / skf.n_splits<compute_test_metric>
corr_matrix=train.corr()
corr_matrix["SalePrice"].sort_values(ascending=False )
print('NN with PolynomialFeatures and StandardScaler CV Score =',round(roc_auc_score(train['target'], oof_nn), 5))<save_to_csv>
train['AllflrSF']=train['TotalBsmtSF']+train['1stFlrSF']+train['2ndFlrSF']
corr_matrix=train.corr()
corr_matrix["SalePrice"].sort_values(ascending=False )
sub['target'] = preds_nn
sub.to_csv('submission_nn.csv', index=False )<define_variables>
all_data = pd.concat(( train.loc[:,'MSSubClass':'SaleCondition'],
test.loc[:,'MSSubClass':'SaleCondition']))
all_data['AllflrSF']=all_data['TotalBsmtSF']+all_data['1stFlrSF']+all_data['2ndFlrSF']
train["SalePrice"] = np.log1p(train["SalePrice"])
 numeric_feats = all_data.dtypes[all_data.dtypes != "object"].index
skewed_feats = train[numeric_feats].apply(lambda x: skew(x.dropna()))
skewed_feats = skewed_feats[skewed_feats > 0.75]
skewed_feats = skewed_feats.index
all_data[skewed_feats] = np.log1p(all_data[skewed_feats])
 all_data = pd.get_dummies(all_data)
 all_data = all_data.fillna(all_data.mean())
 X_train = all_data[:train.shape[0]]
X_test = all_data[train.shape[0]:]
y = train.SalePrice
oof_qda3 = np.zeros(len(train))
preds_qda3 = preds_gmm.copy()<feature_engineering>
dtrain = xgb.DMatrix(X_train, label = y)
 dtest = xgb.DMatrix(X_test)
 params = {"max_depth":2, "eta":0.1}
model = xgb.cv(params, dtrain, num_boost_round=500, early_stopping_rounds=100)
 model1=RandomForestRegressor()
model_xgb = xgb.XGBRegressor(n_estimators=360, max_depth=2, learning_rate=0.1)
 model_xgb.fit(X_train, y)
 model1.fit(X_train,y)
 rf_preds=np.expm1(model1.predict(X_test))
xgb_preds = np.expm1(model_xgb.predict(X_test))
final_preds=rf_preds+xgb_preds/2
test_id=test['Id']
output = pd.DataFrame({"Id" :test_id ,'SalePrice': final_preds})
 output.to_csv('my_submission.csv', index=False)
 print(output)
 print("Your submission was successfully saved!" )