Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<categorify>
warnings.simplefilter(action="ignore", category=FutureWarning)
 pd.set_option("display.max_rows", 2000)
 pd.set_option("display.max_columns", 500)
 pd.set_option("display.width", 100)
 pd.set_option("display.max_colwidth", 500)
 pd.set_option("display.float_format", lambda x: "%.2f" % x)
 display(HTML("<style>.container { width:100% !important; }</style>"))
cwd = os.getcwd()
print(cwd)
 gc.enable()
BasicTicker,
ColorBar,
ColumnDataSource,
LinearColorMapper,
PrintfTickFormatter, 
)
 random_state = 55
def data_translate(source_data,dest_language):
translator = Translator()
if dest_language == 'zh':
dest_language = 'zh-cn'
dest_data = translator.translate(source_data, dest = dest_language ).text
return dest_data<categorify>
%%javascript
IPython.OutputArea.auto_scroll_threshold = 9999;
def translation_augment(source_data, languages, fraction):
new_df = pd.DataFrame()
for lang in languages:
print(lang)
 sampled_rows = source_data.sample(frac=fraction, replace = False)
 prem_bag = bag.from_sequence(sampled_rows['premise'].tolist() ).map(data_translate, lang)
 hypothesis_bag = bag.from_sequence(sampled_rows['hypothesis'].tolist() ).map(data_translate, lang)
 with diagnostics.ProgressBar() :
prems = prem_bag.compute()
hyps = hypothesis_bag.compute()
aug_df = pd.DataFrame({'id': pd.Series([None]*len(sampled_rows)) ,
'premise': pd.Series(prems),
'hypothesis': pd.Series(hyps),
'lang_abv': pd.Series([lang]*len(sampled_rows)) ,
'language': pd.Series([None]*len(sampled_rows)) ,
'label': pd.Series(sampled_rows['label'].values)
 })
 new_df = new_df.append(aug_df)
 new_df = shuffle(new_df)
 return new_df 
<categorify>
train = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/train.csv")
 test = pd.read_csv(".. /input/house-prices-advanced-regression-techniques/test.csv" )
def data_augment(train_df, fraction):
english_df = train.loc[train.lang_abv == 'en']
languages = list(set(train.lang_abv.values))
languages.remove('en')
 print(languages)
 translated_df = translation_augment(english_df,languages, fraction)
 train_df = train_df.append(translated_df)
 train_df = shuffle(train_df)
 return train_df<load_from_csv>
Id = "Id"
submission_ID = test.loc[:, Id]
train.drop(Id, axis=1, inplace=True)
 test.drop(Id, axis=1, inplace=True)
 train.loc[:, "Train"] = 1
test.loc[:, "Train"] = 0
test["SalePrice"] = 0
stacked_DF = pd.concat([train, test], ignore_index=True)
train = pd.read_csv('/kaggle/input/augment-data20/augmented_data_20percent.csv')
 train.head()
len(train )<categorify>
params = {"axes.labelsize": 20,
"xtick.labelsize": 14,
"ytick.labelsize": 14}
plt.rcParams.update(params)
 features_to_viz = [
"GrLivArea",
"YearBuilt",
"WoodDeckSF",
"LotArea",
"GarageArea",
"1stFlrSF",
"2ndFlrSF",
"TotalBsmtSF",
"LotFrontage",
"GarageYrBlt",
]
features_to_viz = sorted(features_to_viz)
 ncols = 1
nrows = math.ceil(len(features_to_viz)/ ncols)
 unused = nrows * ncols - len(features_to_viz)
 figw = ncols * 10
figh = nrows * 8 
(fig, ax)= plt.subplots(nrows, ncols, sharey=True, figsize=(figw, figh))
fig.subplots_adjust(hspace=0.3)
 ax = ax.flatten()
for i in range(unused, 0, -1):
fig.delaxes(ax[-i])
 for(n, col)in enumerate(features_to_viz):
if n % 2 != 0:
ax[n].yaxis.label.set_visible(False)
 ax[n].set_xlabel(col)
 ax[n].set_ylabel("SalePrice")
 sns.scatterplot(
 x=col,
y="SalePrice",
data=stacked_DF.loc[stacked_DF["Train"] == 1],
hue="SalePrice",
palette="gist_earth",
s=75,
legend=False,
ax=ax[n], 
)
 plt.show()
def bert_encode(premises, hypotheses, tokenizer):
num_examples = len(premises)
 sen1 = tf.ragged.constant([encode_sentence(s)for s in np.array(premises)])
 sen2 = tf.ragged.constant([encode_sentence(s)for s in np.array(hypotheses)])
 cls = [tokenizer.convert_tokens_to_ids(['CLS'])]*sen1.shape[0]
input_word_ids = tf.concat([cls, sen1, sen2], axis = -1)
 input_mask = tf.ones_like(input_word_ids ).to_tensor()
type_cls = tf.zeros_like(cls)
 type_sen1 = tf.zeros_like(sen1)
 type_sen2 = tf.ones_like(sen2)
 input_type_ids = tf.concat([type_cls, type_sen1, type_sen2], axis = -1 ).to_tensor()
inputs = {
'input_word_ids' : input_word_ids.to_tensor() ,
'input_mask': input_mask,
'input_type_ids': input_type_ids
}
return inputs<categorify>
features_to_viz = [
"Neighborhood",
"BsmtQual",
"ExterQual",
"FireplaceQu",
"ExterCond",
"KitchenQual",
"LotShape",
"OverallQual",
"FullBath",
"HalfBath",
"TotRmsAbvGrd",
"Fireplaces",
"KitchenAbvGr",
]
features_to_viz = sorted(features_to_viz)
 ncols = 1
nrows = math.ceil(len(features_to_viz)/ ncols)
 unused = nrows * ncols - len(features_to_viz)
(figw, figh)=(ncols * 10, nrows * 8)
(fig, ax)= plt.subplots(nrows, ncols, figsize=(figw, figh))
fig.subplots_adjust(hspace=0.2, wspace=0.2)
 for(n, col)in enumerate(features_to_viz):
ordering =(
 stacked_DF.loc[stacked_DF["Train"] == 1] 
.groupby(by=col)["SalePrice"] 
.median() 
.sort_values() 
.index 
)
 sns.boxplot(
 x="SalePrice",
y=col,
data=stacked_DF.loc[stacked_DF["Train"] == 1],
order=ordering,
ax=ax[n],
orient="h", 
)
 plt.show()
train_input = bert_encode(train.premise.values, train.hypothesis.values, tokenizer )<categorify>
print("Missing Value Counts in Train DF")
 stacked_DF[stacked_DF["Train"] == 1].isna().sum() [
stacked_DF[stacked_DF["Train"] == 1].isna().sum() > 0
].sort_values(ascending=False )
max_len = 80
def build_model() :
bert_encoder = TFRobertaModel.from_pretrained('jplu/tf-xlm-roberta-large')
 input_word_ids = tf.keras.Input(shape =(max_len,), dtype =tf.int32, name = "input_word_ids")
 input_mask = tf.keras.Input(shape =(max_len,), dtype= tf.int32, name = "input_mask")
 input_type_ids = tf.keras.Input(shape=(max_len,), dtype= tf.int32, name="input_type_ids")
 embedding = bert_encoder([input_word_ids, input_mask, input_type_ids])[0]
output = tf.keras.layers.Dense(3, activation = 'softmax' )(embedding[:,0,:])
 model = tf.keras.Model(inputs= [input_word_ids, input_mask, input_type_ids], outputs=output)
 model.compile(tf.keras.optimizers.Adam(lr=1e-5), loss='sparse_categorical_crossentropy', metrics = 'accuracy')
 return model 
<train_model>
print("Missing Values in Test DF")
 stacked_DF[stacked_DF["Train"] == 0].isna().sum() [
stacked_DF[stacked_DF["Train"] == 0].isna().sum() > 0
].sort_values(ascending=False)
model.fit(train_input, train.label.values, epochs=3, verbose=1, batch_size=16, validation_split=0.2 )<load_pretrained>
lookup =(
 stacked_DF.loc[stacked_DF["Train"] == 1] 
.groupby(by="Neighborhood")["MSZoning"] 
.agg(pd.Series.mode)
)
 stacked_DF["MSZoning"] = stacked_DF["MSZoning"].fillna(
 stacked_DF["Neighborhood"].map(lookup)
)
 lookup =(
 stacked_DF.loc[stacked_DF["Train"] == 1] 
.groupby(by="OverallQual")["KitchenQual"] 
.agg(pd.Series.mode)
)
 stacked_DF["KitchenQual"] = stacked_DF["KitchenQual"].fillna(
 stacked_DF["OverallQual"].map(lookup)
)
 cols_na_to_missing = {
"Alley",
"BsmtCond",
"BsmtExposure",
"BsmtFinType1",
"BsmtFullBath",
"BsmtQual",
"Fence",
"FireplaceQu",
"GarageCond",
"GarageFinish",
"GarageQual",
"GarageType",
"MasVnrType",
"MiscFeature",
"PoolQC",
"BsmtFinType2",
}
cols_na_to_zero = {
"GarageArea",
"GarageCars",
"TotalBsmtSF",
"MasVnrArea",
"BsmtFinSF1",
"BsmtFinSF2",
"BsmtFullBath",
"BsmtHalfBath",
"GarageYrBlt",
}
cols_na_to_mode = {
"Functional",
"Electrical",
"Utilities",
"Exterior1st",
"Exterior2nd",
"SaleType",
}
for col in cols_na_to_missing:
stacked_DF[col] = stacked_DF[col].astype(object ).fillna("Missing")
 for col in cols_na_to_zero:
stacked_DF[col] = stacked_DF[col].astype(object ).fillna(0)
 for col in cols_na_to_mode:
stacked_DF[col] =(
 stacked_DF[col] 
.astype(object)
.fillna(stacked_DF.loc[stacked_DF["Train"] == 1, col].mode() [0])
)
 num_features = stacked_DF.drop(columns=["Train"] ).select_dtypes("number" ).columns
imputer = IterativeImputer(
 RandomForestRegressor(max_depth=8),
n_nearest_features=10,
max_iter=10,
random_state=random_state, 
)
 stacked_DF.loc[stacked_DF["Train"] == 1, num_features] = imputer.fit_transform(
 stacked_DF.loc[stacked_DF["Train"] == 1, num_features].values 
)
 stacked_DF.loc[stacked_DF["Train"] == 0, num_features] = imputer.transform(
 stacked_DF.loc[stacked_DF["Train"] == 0, num_features].values 
)
model.save_weights('RoBertamodel_augmented_data_20_percent_adam_sparse_categorical_entropy.h5' )<load_from_csv>
stacked_DF["WarmSeason"] = np.where(
 stacked_DF["MoSold"].isin([10, 11, 12, 1, 2, 3]), 0, 1 
)
 stacked_DF["SqFtPerRoom"] = stacked_DF["GrLivArea"] /(
 stacked_DF["TotRmsAbvGrd"]
+ stacked_DF["FullBath"]
+ stacked_DF["HalfBath"]
+ stacked_DF["KitchenAbvGr"] 
)
 stacked_DF["MSSubClass"] = stacked_DF["MSSubClass"].astype(str)
 cateogies_to_rank = [
"BsmtQual",
"ExterQual",
"ExterCond",
"Exterior1st",
"FireplaceQu",
"GarageCond",
"GarageQual",
"Heating",
"Fence",
"HeatingQC",
"OverallQual",
"OverallCond",
"HouseStyle",
"KitchenQual",
"LotShape",
"BsmtCond",
"MSSubClass",
"Neighborhood",
"SaleCondition",
"SaleType",
"MasVnrType",
"ExterQual",
]
for col in cateogies_to_rank:
rank = np.array(
 range(0, len(stacked_DF.loc[stacked_DF["Train"] == 1, col].unique())) 
)
 field_val =(
 stacked_DF.loc[stacked_DF["Train"] == 1] 
.groupby(by=col)["SalePrice"] 
.median() 
.sort_values() 
.index 
)
 rankval_mapping = dict(zip(field_val, rank))
stacked_DF[col + "_ranking"] = stacked_DF[col].map(
 rankval_mapping, na_action="ignore" 
)
 stacked_DF.loc[stacked_DF["MSSubClass_ranking"].isna() , "MSSubClass_ranking"] = 10
ext2_map = {"AsphShn": "Oth1", "CBlock": "Oth1", "CmentBd": "Oth2", "Other": "Oth2"}
roofmatl_map = {
"Roll": "Oth1",
"ClyTile": "Oth1",
"Metal": "Oth1",
"CompShg": "Oth1",
"Membran": "Oth2",
"WdShake": "Oth2",
}
cond2_map = {"PosA": "Pos", "PosN": "Pos", "RRAe": "Norm", "RRAn": "Norm"}
stacked_DF["Exterior2nd"] =(
 stacked_DF["Exterior2nd"].map(ext2_map ).fillna(stacked_DF["Exterior2nd"])
)
 stacked_DF["RoofMatl"] =(
 stacked_DF["RoofMatl"].map(roofmatl_map ).fillna(stacked_DF["RoofMatl"])
)
 stacked_DF["Condition2"] =(
 stacked_DF["Condition2"].map(cond2_map ).fillna(stacked_DF["Condition2"])
)
 stacked_DF["QualCond"] =(
 stacked_DF["OverallQual_ranking"] * stacked_DF["OverallCond_ranking"] 
)
 stacked_DF["HighQualSF"] = stacked_DF["1stFlrSF"] + stacked_DF["2ndFlrSF"]
stacked_DF["HoodNExtCond"] =(
 stacked_DF["Neighborhood_ranking"] * stacked_DF["ExterCond_ranking"] 
)
 stacked_DF["HoodNPrivacy"] =(
 stacked_DF["Neighborhood_ranking"] * stacked_DF["Fence_ranking"] 
)
 stacked_DF["AreaOverallQualCond"] =(
 stacked_DF["HighQualSF"]
* stacked_DF["OverallQual_ranking"]
* stacked_DF["OverallCond_ranking"] 
)
 stacked_DF["KitchenQCHighQualSF"] =(
 stacked_DF["HighQualSF"] * stacked_DF["KitchenQual_ranking"] 
)
 stacked_DF["HoodNOverallQual"] =(
 stacked_DF["Neighborhood_ranking"] * stacked_DF["OverallQual_ranking"] 
)
 stacked_DF["HoodNMasVnrType"] =(
 stacked_DF["Neighborhood_ranking"] * stacked_DF["MasVnrType_ranking"] 
)
 stacked_DF["HoodNKitchenQual"] =(
 stacked_DF["Neighborhood_ranking"] * stacked_DF["KitchenQual_ranking"] 
)
 stacked_DF["HoodNCond1"] = stacked_DF["Neighborhood_ranking"] * stacked_DF["Condition1"]
stacked_DF["HoodNCond2"] = stacked_DF["Neighborhood_ranking"] * stacked_DF["Condition2"]
stacked_DF["HoodNPorch"] = stacked_DF["Neighborhood_ranking"] *(
 stacked_DF["3SsnPorch"] + stacked_DF["EnclosedPorch"] + stacked_DF["OpenPorchSF"] 
)
 stacked_DF["Age_YrBuilt"] = stacked_DF["YrSold"] - stacked_DF["YearBuilt"]
stacked_DF["Age_YrRemod"] = stacked_DF["YrSold"] - stacked_DF["YearRemodAdd"]
stacked_DF["Age_Garage"] = stacked_DF["YrSold"] - stacked_DF["GarageYrBlt"]
stacked_DF["Remodeled"] = stacked_DF["YearBuilt"] != stacked_DF["YearRemodAdd"]
stacked_DF["Age_YrBuilt"] = stacked_DF["Age_YrBuilt"].apply(lambda x: 0 if x < 0 else x)
 stacked_DF["Age_YrRemod"] = stacked_DF["Age_YrRemod"].apply(lambda x: 0 if x < 0 else x)
 stacked_DF["Age_Garage"] = stacked_DF["Age_Garage"].apply(lambda x: 0 if x < 0 else x)
 sqft_price_table =(
 stacked_DF.loc[stacked_DF["Train"] == 1] 
.groupby(by="Neighborhood")["SalePrice", "GrLivArea"] 
.agg(pd.Series.sum)
)
 sqft_price_table["AvgPricePerSqFt"] =(
 sqft_price_table["SalePrice"] / sqft_price_table["GrLivArea"] 
)
 sqft_price_table.drop(columns=["SalePrice", "GrLivArea"], inplace=True)
 stacked_DF["AvgPricePerSqFtPerHood"] = stacked_DF["Neighborhood"].map(
 sqft_price_table.to_dict() ["AvgPricePerSqFt"] 
)
 stacked_DF.drop(columns=["GarageYrBlt", "Utilities"], inplace=True)
 cols_to_viz = [
"HighQualSF",
"KitchenQCHighQualSF",
"AreaOverallQualCond",
"HoodNOverallQual",
"HoodNMasVnrType",
"HoodNKitchenQual",
]
test = pd.read_csv('/kaggle/input/contradictory-my-dear-watson/test.csv')
 test.head()<categorify>
highly_skewed_cols =(
 stacked_DF[stacked_DF["Train"] == 1] 
.skew() [abs(stacked_DF[stacked_DF["Train"] == 1].skew())> 5] 
.index.to_list() 
)
 ptransformer = PowerTransformer(standardize=False)
 stacked_DF.loc[
stacked_DF["Train"] == 1, highly_skewed_cols
] = ptransformer.fit_transform(
 stacked_DF.loc[stacked_DF["Train"] == 1, highly_skewed_cols] 
)
 stacked_DF.loc[stacked_DF["Train"] == 0, highly_skewed_cols] = ptransformer.transform(
 stacked_DF.loc[stacked_DF["Train"] == 0, highly_skewed_cols]
)
test_input = bert_encode(test.premise.values, test.hypothesis.values, tokenizer )<predict_on_test>
bool_features = [
col
for col in stacked_DF.select_dtypes(include=["number"] ).columns
if np.array_equal(
 np.sort(stacked_DF[col].unique() , axis=0), np.sort([0, 1], axis=0)
)
 ]
cat_features = [col for col in stacked_DF.select_dtypes(exclude=["number"] ).columns]
num_features = [
col
for col in stacked_DF.select_dtypes(include=["number"] ).columns
if col not in(bool_features)and col != "SalePrice"
]
bool_features.remove("Train")
 X_train_bool = stacked_DF.loc[stacked_DF["Train"] == 1, bool_features]
X_test_bool = stacked_DF.loc[stacked_DF["Train"] == 0, bool_features]
ohe_cols_a = []
ohe_cols_b = []
for col in cat_features:
if set(stacked_DF.loc[stacked_DF["Train"] == 1, col].unique())!= set(
 stacked_DF.loc[stacked_DF["Train"] == 0, col].unique() 
):
ohe_cols_b.append(col)
 ohe_cols_a = list(set(cat_features)- set(ohe_cols_b))
predictions = [np.argmax(i)for i in model.predict(test_input)]<prepare_output>
X_train = stacked_DF.loc[stacked_DF["Train"] == 1].drop(
 labels=["SalePrice", "Train"], axis=1 
)
 y_train = stacked_DF.loc[stacked_DF["Train"] == 1, "SalePrice"].apply(np.log)
 X_test = stacked_DF.loc[stacked_DF["Train"] == 0].drop(
 labels=["SalePrice", "Train"], axis=1 
)
 preprocessor = ColumnTransformer(
 transformers=[ 
("onehota", OneHotEncoder(sparse=False, drop="first"), ohe_cols_a), 
("onehotb", OneHotEncoder(sparse=False, handle_unknown="ignore"), ohe_cols_b), 
("scaler", StandardScaler() , num_features),
],
remainder="drop", 
)
 pipeline = Pipeline(
 [("Preprocessor", preprocessor),("VarThreshold", VarianceThreshold(0.01)) ] 
)
 X_train_preprocessed = pipeline.fit_transform(X_train)
 X_test_preprocessed = pipeline.transform(X_test)
 oh_encoded_a = list(
 preprocessor.named_transformers_.onehota.get_feature_names(ohe_cols_a)
)
 oh_encoded_b = list(
 preprocessor.named_transformers_.onehotb.get_feature_names(ohe_cols_b)
)
 oh_encoded_cols = oh_encoded_a + oh_encoded_b
feature_names = np.array(oh_encoded_cols + num_features, order="K")
 feature_names = feature_names[pipeline.named_steps.VarThreshold.get_support() ]
X_train_preprocessed = pd.DataFrame(data=X_train_preprocessed, columns=feature_names)
 X_test_preprocessed = pd.DataFrame(
 data=X_test_preprocessed, columns=feature_names, index=X_test_bool.index 
)
 X_train = pd.concat([X_train_bool, X_train_preprocessed], axis=1)
 X_test = pd.concat([X_test_bool, X_test_preprocessed], axis=1)
submission = test.id.copy().to_frame()
submission.head() 
<prepare_output>
model = Lasso(alpha=0.01)
 model.fit(X_train, y_train)
 feature_imp = permutation_importance(
 model, X_train, y_train, n_repeats=10, n_jobs=-1, random_state=random_state 
)
 perm_ft_imp_df = pd.DataFrame(
 data=feature_imp.importances_mean, columns=["FeatureImp"], index=X_train.columns
).sort_values(by="FeatureImp", ascending=False)
 model_ft_imp_df = pd.DataFrame(
 data=model.coef_, columns=["FeatureImp"], index=X_train.columns
).sort_values(by="FeatureImp", ascending=False)
 fig, ax = plt.subplots(2, 1, figsize=(12, 22))
perm_ft_imp_df_nonzero = perm_ft_imp_df[perm_ft_imp_df["FeatureImp"] != 0]
model_ft_imp_df_nonzero = model_ft_imp_df[model_ft_imp_df["FeatureImp"] != 0]
sns.barplot(
 x=perm_ft_imp_df_nonzero["FeatureImp"],
y=perm_ft_imp_df_nonzero.index,
ax=ax[0],
palette="vlag", 
)
 sns.barplot(
 x=model_ft_imp_df_nonzero["FeatureImp"],
y=model_ft_imp_df_nonzero.index,
ax=ax[1],
palette=sns.diverging_palette(10, 220, sep=2, n=80), 
)
 ax[0].set_title("Permutation Feature Importance")
 ax[1].set_title("Lasso Feature Importance")
 plt.show()
submission['prediction'] = predictions<save_to_csv>
Optimized parameters: {rf_params}")
submission.to_csv("submission.csv", index = False)
<install_modules>
Optimized parameters: {lgbm_params}")
!pip install -q transformers==3.0.2<load_from_csv>
rf_params = {"max_depth": 8, "max_features": 40, "n_estimators": 132}
svr_params = {
"kernel": "poly",
"C": 0.053677105521141605,
"epsilon": 0.03925943476562099,
"coef0": 0.9486751042886584,
}
ridge_params = {
"alpha": 0.9999189637151178,
"tol": 0.8668539399622242,
"solver": "cholesky",
}
lasso_params = {"alpha": 0.0004342843645993161, "selection": "random"}
lgbm_params = {
"num_leaves": 16,
"max_depth": 6,
"learning_rate": 0.16060612646519587,
"n_estimators": 64,
"min_child_weight": 0.4453842422224686,
}
train = pd.read_csv('/kaggle/input/contradictory-my-dear-watson/train.csv')
 train<load_from_csv>
cv = KFold(n_splits=4, random_state=random_state)
 svr = SVR(**svr_params)
 ridge = Ridge(**ridge_params, random_state=random_state)
 lasso = Lasso(**lasso_params, random_state=random_state)
 lgbm = LGBMRegressor(**lgbm_params, random_state=random_state)
 rf = RandomForestRegressor(**rf_params, random_state=random_state)
 stack = StackingCVRegressor(
 regressors=[svr, ridge, lasso, lgbm, rf],
meta_regressor=LinearRegression(n_jobs=-1),
random_state=random_state,
cv=cv,
n_jobs=-1, 
)
 svr_scores = cross_val_score(
 svr, X_train, y_train, cv=cv, n_jobs=-1, error_score="neg_root_mean_squared_error" 
)
 ridge_scores = cross_val_score(
 ridge, X_train, y_train, cv=cv, n_jobs=-1, error_score="neg_root_mean_squared_error" 
)
 lasso_scores = cross_val_score(
 lasso, X_train, y_train, cv=cv, n_jobs=-1, error_score="neg_root_mean_squared_error" 
)
 lgbm_scores = cross_val_score(
 lgbm, X_train, y_train, cv=cv, n_jobs=-1, error_score="neg_root_mean_squared_error" 
)
 rf_scores = cross_val_score(
 rf, X_train, y_train, cv=cv, n_jobs=-1, error_score="neg_root_mean_squared_error" 
)
 stack_scores = cross_val_score(
 stack, X_train, y_train, cv=cv, n_jobs=-1, error_score="neg_root_mean_squared_error" 
)
 scores = [svr_scores, ridge_scores, lasso_scores, lgbm_scores, rf_scores, stack_scores]
models = ["SVR", "RIDGE", "LASSO", "LGBM", "RF", "STACK"]
score_medians = [
round(np.median([mean for mean in modelscore]), 5)for modelscore in scores
]
test = pd.read_csv('/kaggle/input/contradictory-my-dear-watson/test.csv')
 test<load_from_csv>
stack.fit(X_train.values, y_train.values)
 predictions = stack.predict(X_test.values)
 predictions = np.exp(predictions)
 submission = pd.DataFrame({"Id": submission_ID, "SalePrice": predictions})
 submission.to_csv("submission.csv", index=False )