Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<feature_engineering>
%matplotlib inline
warnings.filterwarnings('ignore' )
df = pd.DataFrame(train.TARGET.value_counts())
 df['Percentage'] =(df['TARGET']/df['TARGET'].sum())*100
df<count_duplicates>
def fill_missing_data_basic_reg(X_train, y_train, X_test):
rf_reg_est = ensemble.RandomForestRegressor(random_state = 42)
 rf_reg_est.fit(X_train, y_train)
 y_test = rf_reg_est.predict(X_test)
 return y_test
def fill_missing_data_basic_class(X_train, y_train, X_test):
rf_class_est = ensemble.RandomForestClassifier(random_state = 42)
 rf_class_est.fit(X_train, y_train)
 y_test = rf_class_est.predict(X_test)
 return y_test
display(train.shape)
 display(train.duplicated(train.columns[1:],keep=False ).value_counts() [1])
 display(train.duplicated(train.columns[1:],keep='first' ).value_counts() [1])
 train = train.drop(train[train.duplicated(train.columns[1:],keep='first')].index)
 train.reset_index(drop=True,inplace=True)
 display(train.shape )<count_duplicates>
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv" )
noise_indices = train[train.duplicated(train.columns[1:-1],keep=False)&~train.duplicated(train.columns[1:],keep=False)].index
non_noise_indices = train.index.difference(noise_indices)
 f'We have {len(noise_indices)} instances of noise, {len(non_noise_indices)} non_noise' 
<count_duplicates>
print("Total Train Features with NaN Values = " + str(train_df.columns[train_df.isnull().sum() != 0].size))
print("Features with NaN => {}".format(list(train_df.columns[train_df.isnull().sum() != 0])))
 train_df[train_df.columns[train_df.isnull().sum() != 0]].isnull().sum().sort_values(ascending = False )
<train_model>
print("Total Test Features with NaN Values = " + str(test_df.columns[test_df.isnull().sum() != 0].size))
print("Features with NaN => {}".format(list(test_df.columns[test_df.isnull().sum() != 0])))
 test_df[test_df.columns[test_df.isnull().sum() != 0]].isnull().sum().sort_values(ascending = False )
trainNTP1_y = trainNTP1.TARGET
trainNTP1_X = trainNTP1.drop(['ID','TARGET'],axis=1)
 trainNTP1_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP1_xgb.fit(trainNTP1_X, trainNTP1_y)
 trainNTP2_y = trainNTP2.TARGET
trainNTP2_X = trainNTP2.drop(['ID','TARGET'],axis=1)
 trainNTP2_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP2_xgb.fit(trainNTP2_X, trainNTP2_y)
 trainNTP3_y = trainNTP3.TARGET
trainNTP3_X = trainNTP3.drop(['ID','TARGET'],axis=1)
 trainNTP3_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP3_xgb.fit(trainNTP3_X, trainNTP3_y)
 trainNTP4_y = trainNTP4.TARGET
trainNTP4_X = trainNTP4.drop(['ID','TARGET'],axis=1)
 trainNTP4_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP4_xgb.fit(trainNTP4_X, trainNTP4_y)
 trainNTP5_y = trainNTP5.TARGET
trainNTP5_X = trainNTP5.drop(['ID','TARGET'],axis=1)
 trainNTP5_xgb = XGBClassifier(n_estimators=100, max_depth=10, n_jobs=-1, seed=42)
 trainNTP5_xgb.fit(trainNTP5_X, trainNTP5_y )<predict_on_test>
test_df['SalePrice'] = 0
combined_train_test_df = train_df.append(test_df)
 print("Shape of Combined Train and Test Data -> " + str(combined_train_test_df.shape))
noise_y = noise.TARGET
noise_X = noise.drop(['ID','TARGET'],axis=1)
 pred1 = trainNTP1_xgb.predict(noise_X)
 display(pred1)
 pred2 = trainNTP2_xgb.predict(noise_X)
 pred3 = trainNTP3_xgb.predict(noise_X)
 pred4 = trainNTP3_xgb.predict(noise_X)
 pred5 = trainNTP3_xgb.predict(noise_X)
 pd.DataFrame({'pred1':pred1} )<drop_column>
print("Total Features with NaN Values in Test and Train = " + str(combined_train_test_df.columns[combined_train_test_df.isnull().sum() != 0].size))
combined_train_test_df.columns[combined_train_test_df.isnull().sum() != 0]
missing_total = combined_train_test_df[combined_train_test_df.columns[combined_train_test_df.isnull().sum() != 0]].isnull().sum().sort_values(ascending = False)
 missing_percent =(combined_train_test_df[combined_train_test_df.columns[combined_train_test_df.isnull().sum() != 0]].isnull().sum() /combined_train_test_df.shape[0] * 100 ).sort_values(ascending = False )
remove = []
for col in train.columns:
if(train[col].std() ==0):
remove.append(col)
 print(remove)
 print(len(remove))
train.drop(remove, axis=1, inplace=True)
 test.drop(remove, axis=1, inplace=True)
 train.shape 
<drop_column>
missing_features = missing_total.index
missing_features_tot = pd.concat([missing_total, missing_percent], axis = 1)
 print(missing_features_tot )
remove = []
cols = train.columns
for i in range(len(cols)-1):
v = train[cols[i]].values
for j in range(i+1, len(cols)) :
if np.array_equal(v,train[cols[j]].values):
remove.append(cols[j])
 print(remove)
 print(len(remove))
train.drop(remove, axis=1, inplace=True)
 test.drop(remove, axis=1, inplace=True)
 train.shape 
<prepare_x_and_y>
corr.sort_values(["SalePrice"], ascending = False, inplace = True)
 print(corr.SalePrice )
test_ids = test.ID
test.drop(['ID'], axis=1, inplace=True)
 X = train.drop(['ID','TARGET'], axis=1)
 y = train.TARGET<split>
if(combined_train_test_df['BsmtFullBath'].isnull().sum() != 0):
combined_train_test_df['BsmtFullBath'].fillna(combined_train_test_df['BsmtFullBath'].mode().iloc[0], inplace = True )
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
 print(X_train.shape, X_test.shape, test.shape )<train_model>
if(combined_train_test_df['BsmtHalfBath'].isnull().sum() != 0):
combined_train_test_df['BsmtHalfBath'].fillna(combined_train_test_df['BsmtHalfBath'].mode().iloc[0], inplace = True )
etc = ExtraTreesClassifier(random_state=42)
 selector = etc.fit(X_train,y_train )<categorify>
if(combined_train_test_df['TotalBsmtSF'].isnull().sum() != 0):
combined_train_test_df['TotalBsmtSF'].fillna(round(combined_train_test_df['TotalBsmtSF'].mean()), inplace = True )
fs = SelectFromModel(selector, prefit=True)
 X_train = fs.transform(X_train)
 X_test = fs.transform(X_test)
 test = fs.transform(test)
 print(X_train.shape, X_test.shape, test.shape)
<train_model>
if(combined_train_test_df['GarageCars'].isnull().sum() != 0):
combined_train_test_df['GarageCars'].fillna(combined_train_test_df['GarageCars'].mode().iloc[0], inplace = True )
m_xgb = XGBClassifier(n_estimators=100, max_depth=3, n_jobs=-1, seed=42)
 m_xgb.fit(X_train, y_train, eval_set=[(X_test, y_test)], eval_metric='auc')
<predict_on_test>
if(combined_train_test_df['KitchenQual'].isnull().sum() != 0):
combined_train_test_df['KitchenQual'].fillna(combined_train_test_df['KitchenQual'].mode().iloc[0], inplace = True )
m_xgb.predict_proba(X_test)
<compute_test_metric>
if(combined_train_test_df['Electrical'].isnull().sum() != 0):
combined_train_test_df['Electrical'].fillna(combined_train_test_df['Electrical'].mode().iloc[0], inplace = True )
print('ROC AUC score', roc_auc_score(y_true=y_test, y_score=m_xgb.predict_proba(X_test)[:,1], average='macro')) 
<save_to_csv>
if(combined_train_test_df['SaleType'].isnull().sum() != 0):
combined_train_test_df['SaleType'].fillna(combined_train_test_df['SaleType'].mode().iloc[0], inplace = True )
submission = pd.DataFrame({'ID':test_ids,'TARGET': m_xgb.predict_proba(test)[:,1]})
 submission.to_csv('submission.csv',index=False )<import_modules>
if(combined_train_test_df['Exterior1st'].isnull().sum() != 0):
combined_train_test_df['Exterior1st'].fillna(combined_train_test_df['Exterior1st'].mode().iloc[0], inplace = True )
print(os.listdir(".. /input")) 
<train_model>
if(combined_train_test_df['Exterior2nd'].isnull().sum() != 0):
combined_train_test_df['Exterior2nd'].fillna(combined_train_test_df['Exterior2nd'].mode().iloc[0], inplace = True )
class EstimatorSelectionHelper:
def __init__(self, models, params):
if not set(models.keys() ).issubset(set(params.keys())) :
missing_params = list(set(models.keys())- set(params.keys()))
raise ValueError("Some estimators are missing parameters: %s" % missing_params)
 self.models = models
self.params = params
self.keys = models.keys()
self.grid_searches = {}
def fit(self, X, y, cv=3, n_jobs=3, verbose=1, scoring=None, refit=False):
for key in self.keys:
print("Running GridSearchCV for %s." % key)
 model = self.models[key]
params = self.params[key]
gs = GridSearchCV(model, params, cv=cv, n_jobs=n_jobs,
verbose=verbose, scoring=scoring, refit=refit,
return_train_score=True)
 gs.fit(X,y)
 self.grid_searches[key] = gs
def score_summary(self, sort_by='mean_score'):
def row(key, scores, params):
d = {
'estimator': key,
'min_score': min(scores),
'max_score': max(scores),
'mean_score': np.mean(scores),
'std_score': np.std(scores),
}
return pd.Series({**params,**d})
 rows = []
for k in self.grid_searches:
print(k)
 params = self.grid_searches[k].cv_results_['params']
scores = []
for i in range(self.grid_searches[k].cv):
key = "split{}_test_score".format(i)
 r = self.grid_searches[k].cv_results_[key]
scores.append(r.reshape(len(params),1))
all_scores = np.hstack(scores)
 for p, s in zip(params,all_scores):
rows.append(( row(k, s, p)))
 df = pd.concat(rows, axis=1 ).T.sort_values([sort_by], ascending=False)
 columns = ['estimator', 'min_score', 'mean_score', 'max_score', 'std_score']
columns = columns + [c for c in df.columns if c not in columns]
return df[columns]<load_from_csv>
if(combined_train_test_df['Functional'].isnull().sum() != 0):
combined_train_test_df['Functional'].fillna(combined_train_test_df['Functional'].mode().iloc[0], inplace = True )
train_data = pd.read_csv(".. /input/train.csv")
 test_data = pd.read_csv(".. /input/test.csv")
 remove = []
c = train_data.columns
for i in range(len(c)-1):
v = train_data[c[i]].values
for j in range(i+1,len(c)) :
if np.array_equal(v,train_data[c[j]].values):
remove.append(c[j])
 train_data.drop(remove, axis=1, inplace=True)
 train_X, test_X, train_y, test_y = train_test_split(train_data.drop(["TARGET","ID"],axis=1),
train_data.TARGET,
random_state=0,
test_size=0.25 )<choose_model_class>
if(combined_train_test_df['Utilities'].isnull().sum() != 0):
combined_train_test_df['Utilities'].fillna(combined_train_test_df['Utilities'].mode().iloc[0], inplace = True )
models1 = {
'ExtraTreesClassifier': ExtraTreesClassifier() ,
'RandomForestClassifier': RandomForestClassifier() ,
'AdaBoostClassifier': AdaBoostClassifier() ,
'GradientBoostingClassifier': GradientBoostingClassifier() ,
'XGBClassifier': XGBClassifier()
}
params1 = {
'ExtraTreesClassifier': { 'n_estimators': [64, 128, 256, 512, 1024] },
'RandomForestClassifier': { 'n_estimators': [64, 128, 256, 512, 1024], 'min_samples_split': [2, 4, 8, 16] },
'AdaBoostClassifier': { 'n_estimators': [64, 128, 256, 512, 1024] },
'GradientBoostingClassifier': { 'n_estimators': [64, 128, 256, 512, 1024], 'learning_rate': [0.8, 1.0] },
'XGBClassifier': { 'n_estimators': [64, 128, 256, 512, 1024], 'max_depth': [1, 2, 3, 4, 5, 6]}
}
helper1 = EstimatorSelectionHelper(models1, params1)
 helper1.fit(train_X[important_features], train_y, scoring='roc_auc', n_jobs=2, refit= True)
 helper1.score_summary(sort_by='mean_score' )<find_best_params>
if(combined_train_test_df['MSZoning'].isnull().sum() != 0):
combined_train_test_df['MSZoning'].fillna(combined_train_test_df['MSZoning'].mode().iloc[0], inplace = True )
clf = helper1.grid_searches.get('XGBClassifier' ).best_estimator_
print(helper1.grid_searches.get('XGBClassifier' ).best_params_ )<save_to_csv>
if(combined_train_test_df['MasVnrArea'].isnull().sum() != 0):
combined_train_test_df['MasVnrArea'].fillna(0, inplace = True )
clf.fit(train_data.drop(["TARGET","ID"],axis=1)[important_features], train_data.TARGET)
 submission_preds = clf.predict_proba(test_data[important_features])[:,1]
output = pd.DataFrame({'ID': test_data.ID,
'TARGET': submission_preds})
 output.to_csv('submission.csv', index=False )<set_options>
if(combined_train_test_df['MasVnrType'].isnull().sum() != 0):
combined_train_test_df['MasVnrType'].fillna('None', inplace = True )
%matplotlib inline<load_from_csv>
if(combined_train_test_df['BsmtCond'].isnull().sum() != 0):
combined_train_test_df['BsmtCond'].fillna(combined_train_test_df['BsmtCond'].mode().iloc[0], inplace = True )
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 train.head()<count_values>
if(combined_train_test_df['BsmtExposure'].isnull().sum() != 0):
combined_train_test_df['BsmtExposure'].fillna(combined_train_test_df['BsmtExposure'].mode().iloc[0], inplace = True )
train['TARGET'].value_counts()<count_values>
if(combined_train_test_df['BsmtQual'].isnull().sum() != 0):
combined_train_test_df['BsmtQual'].fillna(combined_train_test_df['BsmtQual'].mode().iloc[0], inplace = True )
print(len(train['TARGET'][train.var15<23]))
print(sum(train['TARGET'][train.var15<23]))<drop_column>
if(combined_train_test_df['BsmtFinType1'].isnull().sum() != 0):
combined_train_test_df['BsmtFinType1'].fillna(combined_train_test_df['BsmtFinType1'].mode().iloc[0], inplace = True )
labels = train['TARGET'].values
df_train = train.drop(['TARGET'], axis=1)
 df_test = test.copy()
id_test = test['ID']
piv_train = train.shape[0]<concatenate>
if(combined_train_test_df['BsmtFinType2'].isnull().sum() != 0):
combined_train_test_df['BsmtFinType2'].fillna(combined_train_test_df['BsmtFinType2'].mode().iloc[0], inplace = True )
df_all = pd.concat(( df_train, df_test), axis=0, ignore_index=True)
 df_all = df_all.drop(['ID'], axis=1)
 print(df_all.isnull().sum() / df_all.shape[0])
 df_all.head()<feature_engineering>
if(combined_train_test_df['GarageType'].isnull().sum() != 0):
combined_train_test_df['GarageType'].fillna(combined_train_test_df['GarageType'].mode().iloc[0], inplace = True )
df_all['n0'] =(df_all==0 ).sum(axis=1)
 print(df_all.shape )<drop_column>
if(combined_train_test_df['GarageCond'].isnull().sum() != 0):
combined_train_test_df['GarageCond'].fillna(combined_train_test_df['GarageCond'].mode().iloc[0], inplace = True )
remove = []
for col in df_all.columns:
if df_all[col].std() == 0:
remove.append(col)
 df_all.drop(remove, axis=1, inplace=True)
 print(df_all.shape )<count_unique_values>
if(combined_train_test_df['GarageQual'].isnull().sum() != 0):
combined_train_test_df['GarageQual'].fillna(combined_train_test_df['GarageQual'].mode().iloc[0], inplace = True )
constants = []
for f in df_all.columns:
print(len(np.unique(df_all[f])) , '/', len(df_all[f]))
if len(np.unique(df_all[f])) == 1:
constants.append(f)
 display(constants)
 df_all = df_all.drop(constants, axis=1)
 print(df_all.shape )<count_values>
if(combined_train_test_df['GarageYrBlt'].isnull().sum() != 0):
combined_train_test_df['GarageYrBlt'].fillna(combined_train_test_df['YearBuilt'], inplace = True )
print(( df_all.num_var13_medio ).value_counts())
 print(( df_all.saldo_medio_var13_medio_ult1 ).value_counts() )<define_variables>
if(combined_train_test_df['LotFrontage'].isnull().sum() != 0):
df_LF_LA = combined_train_test_df[['LotFrontage', 'LotArea']]
X_train_LF_LA = df_LF_LA[df_LF_LA['LotFrontage'].notnull() ].drop(labels =('LotFrontage'), axis = 1)
 y_train_LF_LA = df_LF_LA[df_LF_LA['LotFrontage'].notnull() ].drop(labels = ['LotArea'], axis = 1)
 X_test_LF_LA = df_LF_LA[df_LF_LA['LotFrontage'].isnull() ].drop(['LotFrontage'], axis = 1)
 y_test_LF_LA = fill_missing_data_basic_reg(X_train_LF_LA, y_train_LF_LA, X_test_LF_LA)
 combined_train_test_df.loc[(combined_train_test_df.LotFrontage.isnull()), 'LotFrontage'] = y_test_LF_LA
remove += ['num_var13_medio', 'saldo_medio_var13_medio_ult1']
len(remove )<drop_column>
if(combined_train_test_df['FireplaceQu'].isnull().sum().sum() != 0):
combined_train_test_df['FireplaceQu'] = combined_train_test_df['FireplaceQu'].fillna('NoFirePlace' )
df_all.drop(remove, axis=1, inplace=True)
 print(df_all.shape )<feature_engineering>
if(combined_train_test_df['Fence'].isnull().sum().sum() != 0):
combined_train_test_df['Fence'] = combined_train_test_df['Fence'].fillna('NoFence' )
print('Setting min-max lims on test data...')
 st = time.time()
for f in df_all.columns[:-1]:
lim_min = np.min(df_train[f])
 df_all.loc[:, f][df_all[f] < lim_min] = lim_min
lim_max = np.max(df_train[f])
 df_all.loc[:, f][df_all[f] > lim_max] = lim_max
print(time.time() - st )<prepare_x_and_y>
if(combined_train_test_df['Alley'].isnull().sum().sum() != 0):
combined_train_test_df['Alley'] = combined_train_test_df['Alley'].fillna('NoAlley' )
vals = df_all.values
X = vals[:piv_train]
X_test_submit = vals[piv_train:]
y = labels
print(vals.shape)
 print(X.shape)
 print(X_test_submit.shape )<normalization>
if(combined_train_test_df['MiscFeature'].isnull().sum().sum() != 0):
combined_train_test_df['MiscFeature'] = combined_train_test_df['MiscFeature'].fillna('NoMiscFeature' )
df_norm = normalize(df_all, axis=0 )<prepare_x_and_y>
if(combined_train_test_df['PoolQC'].isnull().sum().sum() != 0):
combined_train_test_df['PoolQC'] = combined_train_test_df['PoolQC'].fillna('NoPoolQC' )
vals = df_norm
X = vals[:piv_train]
X_test_submit = vals[piv_train:]
y = labels<init_hyperparams>
assert(combined_train_test_df.columns[combined_train_test_df.isnull().sum() != 0].size == 0)
 print("Total Features with NaN in Test and Train After Imputation = " + str(combined_train_test_df.columns[combined_train_test_df.isnull().sum() != 0].size))
ratio = float(np.sum(y == 1)) / np.sum(y==0)
 est = XGBClassifier(max_depth=5, learning_rate=0.0202, n_estimators=556,
objective='binary:logistic', subsample=0.69, colsample_bytree=0.81,
scale_pos_weight=ratio, seed=1776)
 param = {
'objective':'multi:softprob',
'max_depth':6,
'learning_rate':0.25,
'min_child_weight': 3,
'n_estimators':43,
'subsample':0.6,
'colsample_bytree':0.6,
'num_class' :12
}<train_model>
category_cols = ['MSSubClass', 'MSZoning', 'Street', 'Alley', 'LotShape', 'LandContour', 'Utilities', 'LotConfig', 'LandSlope', 'Neighborhood', 'Condition1', 'Condition2', 'BldgType', 'HouseStyle', 'OverallQual', 'OverallCond', 'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd', 'MasVnrType', 'ExterQual', 'ExterCond', 'Foundation', 'BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2', 'Heating', 'HeatingQC', 'CentralAir', 'Electrical', 'BsmtFullBath', 'BsmtHalfBath', 'FullBath', 'HalfBath', 'BedroomAbvGr', 'KitchenAbvGr', 'KitchenQual', 'TotRmsAbvGrd', 'Functional', 'Fireplaces', 'FireplaceQu', 'GarageType', 'GarageFinish', 'GarageCars', 'GarageQual', 'GarageCond', 'PavedDrive', 'PoolQC', 'Fence', 'MiscFeature', 'SaleType', 'SaleCondition']
continuos_cols = ['LotFrontage', 'LotArea', 'YearBuilt', 'YearRemodAdd', 'MasVnrArea', 'BsmtFinSF1', 'BsmtFinSF2', 'BsmtUnfSF', 'TotalBsmtSF', '1stFlrSF', '2ndFlrSF', 'LowQualFinSF', 'GrLivArea', 'GarageYrBlt', 'GarageArea', 'WoodDeckSF', 'OpenPorchSF', 'EnclosedPorch', '3SsnPorch', 'ScreenPorch', 'PoolArea', 'MiscVal', 'MoSold', 'YrSold', 'SalePrice']
eval_set = [(X_train,y_train),(X_valid,y_valid)]
est = XGBClassifier()
est.fit(X_train, y_train, eval_set=eval_set, early_stopping_rounds=100, eval_metric='logloss' )<compute_train_metric>
cmb_log_df = combined_train_test_df.select_dtypes(include=[np.number])
 cmb_log_df = cmb_log_df.drop(['Id', 'SalePrice'], axis=1)
 for col in cmb_log_df.columns:
cmb_log_df[col] = np.log1p(cmb_log_df[col] )
print(metrics.classification_report(y, est.predict(X)) )<compute_train_metric>
rob_sca = RobustScaler()
rob_sca.fit(cmb_log_df)
 cmb_sca_df = pd.DataFrame(rob_sca.transform(cmb_log_df), index=cmb_log_df.index, columns=cmb_log_df.columns )
ypred = est.predict_proba(X)
 print(metrics.roc_auc_score(y, ypred[:,1]))<define_variables>
category_cols_dummies_df = pd.get_dummies(combined_train_test_df[category_cols])
 cmb_sca_df = pd.concat([cmb_sca_df, category_cols_dummies_df], axis = 1 )
var15 = test['var15']
saldo_medio_var5_hace2 = test['saldo_medio_var5_hace2']
saldo_var33 = test['saldo_var33']
var38 = test['var38']
var21 = test['var21']
num_var30 = test['num_var30']
num_var13_0 = test['num_var13_0']
num_var33_0 = test['num_var33_0']
imp_ent_var16_ult1 = test['imp_ent_var16_ult1']
imp_op_var39_comer_ult3 = test['imp_op_var39_comer_ult3']
saldo_medio_var5_ult3 = test['saldo_medio_var5_ult3']<predict_on_test>
train_data = cmb_sca_df[:1460]
test_data = cmb_sca_df[1460:]
ypred_submit = est.predict_proba(X_test_submit)
 print(X_test_submit.shape)
 print(ypred_submit.shape)
 print(ypred_submit[:7] )<define_variables>
train_data['SalePrice'] = np.log1p(train_df['SalePrice'] )
zero_feats = [('saldo_medio_var5_hace2', 160000), 
('saldo_var33', 0), 
('var38', 3988596), 
('var21', 7500), 
('num_var30', 9), 
('num_var13_0', 6), 
('num_var33_0', 0), 
('imp_ent_var16_ult1', 51003), 
('imp_op_var39_comer_ult3', 13184), 
('saldo_medio_var5_ult3', 108251),
]
for x,y in zero_feats:
print(x, train[(train[x] > y)&(train.TARGET==1)].shape )<feature_engineering>
train_data_X = train_data.drop(['SalePrice'], axis = 1)
 train_data_y = train_data['SalePrice']
test_data_X = test_data
ypred_submit[list(var15.index[var15 < 23]), 1] = 0
ypred_submit[list(saldo_var33.index[saldo_var33 > 0]), 1] = 0
ypred_submit[list(var38.index[var38 > 3988596]), 1] = 0
ypred_submit[list(var21.index[var21 > 7500]), 1] = 0
ypred_submit[list(num_var30.index[num_var30 > 9]), 1] = 0
ypred_submit[list(num_var13_0.index[num_var13_0 > 6]), 1] = 0
ypred_submit[list(num_var33_0.index[num_var33_0 > 0]), 1] = 0
ypred_submit[list(imp_ent_var16_ult1.index[imp_ent_var16_ult1 > 51003]), 1] = 0
ypred_submit[list(imp_op_var39_comer_ult3.index[imp_op_var39_comer_ult3 > 13184]), 1] = 0
ypred_submit[list(saldo_medio_var5_ult3.index[saldo_medio_var5_ult3 > 108251]), 1] = 0
ypred_submit[:7]<save_to_csv>
def RMSE(estimator,X_train,Y_train,cv=5,n_jobs=-1):
cv_results = cross_val_score(estimator,X_train,Y_train,cv=cv,scoring="neg_mean_squared_error",n_jobs=n_jobs)
 return(np.sqrt(-cv_results)).mean()
sub = pd.concat([id_test, pd.Series(ypred_submit[:,1], name='TARGET')], axis=1)
 sub.to_csv('submission.csv',index=False, float_format='%.16f' )<import_modules>
clf = LassoCV(random_state=42)
 clf.fit(train_data_X, train_data_y )
<set_options><EOS> 
df_pred = pd.DataFrame()
df_pred['SalePrice'] = clf.predict(test_data_X)
 df_pred['SalePrice'] = np.expm1(df_pred['SalePrice'])
 test_data_X['SalePrice'] = df_pred[['SalePrice']]
submission = pd.DataFrame({'Id': test_df.loc[:, 'Id'],
'SalePrice': test_data_X.loc[:, 'SalePrice']})
 submission.to_csv(".. /working/submission.csv", index = False )