Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<define_variables>
train_df = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test_df = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv' )
FLAGS.vocab_file = '/kaggle/input/bert-config-vocab/vocab-nq.txt'
FLAGS.bert_config_file = '/kaggle/input/bert-config-vocab/bert_config.json'
FLAGS.do_train=False
FLAGS.do_predict=True
FLAGS.predict_batch_size=32
FLAGS.max_seq_length=512
FLAGS.doc_stride=256
FLAGS.output_dir='tfrecords'
FLAGS.use_tpu=False
FLAGS.max_contexts = 80
eval_set = 'test'
FLAGS.predict_file = '/kaggle/input/tensorflow2-question-answering/simplified-nq-test.jsonl'<randomize_order>
def preprocessing_null(data_df):
data_df.drop(['Alley', 'PoolQC', 'Fence', 'MiscFeature', 'Id'], axis=1, inplace=True)
 Bsmtlist = ['BsmtQual', 'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinType2']
Bsmtlist2=['BsmtFinSF1', 'BsmtFinSF2', 'BsmtUnfSF']
Garagelist = ['GarageType', 'GarageFinish', 'GarageQual', 'GarageCond']
Bathlist = ['BsmtFullBath', 'BsmtHalfBath']
Extlist = ['Exterior1st', 'Exterior2nd']
data_df.loc[:, Bsmtlist]=data_df.loc[:, Bsmtlist].fillna('TA')
 data_df['Electrical']=data_df['Electrical'].fillna('SBrkr')
 data_df['LotFrontage']=data_df['LotFrontage'].fillna(data_df['LotFrontage'].mean())
 data_df['FireplaceQu'] = data_df['FireplaceQu'].fillna('NA')
 data_df.loc[:, Garagelist] = data_df.loc[:, Garagelist].fillna('NA')
 data_df['GarageYrBlt']=data_df['GarageYrBlt'].fillna(2005)
 data_df.loc[:, 'MasVnrType'] = data_df.loc[:, 'MasVnrType'].fillna('None')
 data_df['MasVnrArea']=data_df['MasVnrArea'].fillna(0)
 data_df.loc[:, Bsmtlist2]=data_df[Bsmtlist2].fillna(0)
 data_df['TotalBsmtSF']=data_df['TotalBsmtSF'].fillna(0)
 data_df['GarageArea']=data_df['GarageArea'].fillna(data_df['GarageArea'].median())
 data_df['GarageCars']=data_df['GarageCars'].fillna(data_df['GarageCars'].median())
 data_df[Bathlist]=data_df[Bathlist].fillna(0)
 data_df[Extlist]=data_df[Extlist].fillna('VinylSd')
 data_df['MSZoning']=data_df['MSZoning'].fillna('TA')
 data_df['Utilities']=data_df['Utilities'].fillna('AllPub')
 data_df['KitchenQual']=data_df['KitchenQual'].fillna('TA')
 data_df['Functional']=data_df['Functional'].fillna('Typ')
 data_df['SaleType']=data_df['SaleType'].fillna('WD')
 return data_df
%%time
eval_examples = read_nq_examples(input_file=FLAGS.predict_file, is_training=False)
 print(len(eval_examples))<categorify>
train_target = train_df['SalePrice']
train_feature = train_df.drop('SalePrice', axis=1 )
%%time
candidates_dict = read_candidates(FLAGS.predict_file)
 print(len(candidates_dict))<load_pretrained>
train_feature = preprocessing_null(train_feature)
 test_feature = preprocessing_null(test_df )
def main_pred() :
tf.logging.set_verbosity(tf.logging.INFO)
 bert_config = modeling.BertConfig.from_json_file(FLAGS.bert_config_file)
 validate_flags_or_throw(bert_config)
 tf.gfile.MakeDirs(FLAGS.output_dir)
 tokenizer = tokenization.FullTokenizer(
 vocab_file=FLAGS.vocab_file, do_lower_case=FLAGS.do_lower_case)
 FLAGS.use_tpu = False
tpu_cluster_resolver = None
is_per_host = contrib_tpu.InputPipelineConfig.PER_HOST_V2
run_config = contrib_tpu.RunConfig(
 cluster=tpu_cluster_resolver,
master=FLAGS.master,
model_dir=FLAGS.output_dir,
keep_checkpoint_max=100,
save_checkpoints_steps=FLAGS.save_checkpoints_steps,
tpu_config=contrib_tpu.TPUConfig(
 iterations_per_loop=FLAGS.iterations_per_loop,
num_shards=FLAGS.num_tpu_cores,
per_host_input_for_training=is_per_host))
num_train_steps = None
num_warmup_steps = None
model_fn = model_fn_builder(
 bert_config=bert_config,
init_checkpoint=FLAGS.init_checkpoint,
learning_rate=FLAGS.learning_rate,
num_train_steps=num_train_steps,
num_warmup_steps=num_warmup_steps,
use_tpu=FLAGS.use_tpu,
use_one_hot_embeddings=FLAGS.use_tpu)
 estimator = tf.contrib.tpu.TPUEstimator(
 use_tpu=FLAGS.use_tpu,
model_fn=model_fn,
config=run_config,
train_batch_size=FLAGS.train_batch_size,
predict_batch_size=FLAGS.predict_batch_size)
 if FLAGS.do_lower_case:
tfrecord_file = os.path.join(f"{eval_set}.tf_record")
 else:
tfrecord_file = os.path.join(f"{eval_set}_cased.tf_record")
 if not os.path.exists(tfrecord_file):
eval_writer = FeatureWriter(
 filename=tfrecord_file,
is_training=False)
 eval_features = []
def append_feature(feature):
eval_features.append(feature)
 eval_writer.process_feature(feature)
 convert_examples_to_features(
 examples=eval_examples,
tokenizer=tokenizer,
is_training=False,
output_fn=append_feature)
 eval_writer.close()
tf.logging.info("***** Running predictions *****")
 tf.logging.info(" Num orig examples = %d", len(eval_examples))
tf.logging.info(" Batch size = %d", FLAGS.predict_batch_size)
 predict_input_fn = input_fn_builder(
 input_file=tfrecord_file,
seq_length=FLAGS.max_seq_length,
is_training=False,
drop_remainder=False)
 eval_features = [
tf.train.Example.FromString(r)
 for r in tf.python_io.tf_record_iterator(tfrecord_file)
 ]
all_results = []
for result in tqdm(estimator.predict(
 predict_input_fn, yield_single_examples=True),total=len(eval_features)) :
if len(all_results)% 1000 == 0:
tf.logging.info("Processing example: %d" %(len(all_results)))
 unique_id = int(result["unique_ids"])
 start_logits = [float(x)for x in result["start_logits"].flat]
end_logits = [float(x)for x in result["end_logits"].flat]
answer_type_logits = [float(x)for x in result["answer_type_logits"].flat]
all_results.append(
 RawResult(
 unique_id=unique_id,
start_logits=start_logits,
end_logits=end_logits,
answer_type_logits=answer_type_logits))
nq_pred_dict,nbest_summary_dict = compute_pred_dict(candidates_dict, eval_features,
[r._asdict() for r in all_results])
 predictions_json = {"predictions": list(nq_pred_dict.values())}
with open(FLAGS.output_prediction_file, "w")as f:
json.dump(predictions_json, f, indent=4)
 pickle.dump(nbest_summary_dict,open(
 FLAGS.output_prediction_file.replace('pred_jsons/pred','nbest_pkl/nbest_dict' ).replace('.json','.pkl'),
'wb'))<define_variables>
%matplotlib inline
ckpts = ['/kaggle/input/model-l/_wwm_stride_192_neg_0.01_0.04-64-2.00E-05/model.ckpt-7000',
'/kaggle/input/model-o/model.ckpt-9500',
'/kaggle/input/model-r2/model.ckpt-8500'
]
ensemble_wts = [1, 1.1, 0.8]
long_thr = 2.3972
short_thr = 2.895
yes_thr = 5.5
no_thr = 5.5
pred_files = [x.split('/')[-2] for x in ckpts]
pred_files<define_variables>
pd.set_option('display.max_columns', 500)
 corr[corr>0.7]
%%time
FLAGS.do_lower_case = True
FLAGS.vocab_file = '/kaggle/input/bert-config-vocab/vocab-nq.txt'
FLAGS.bert_config_file = '/kaggle/input/bert-config-vocab/bert_config.json'
for i in range(2):
FLAGS.init_checkpoint = ckpts[i]
FLAGS.output_prediction_file = pred_files[i]+'.json'
main_pred()
FLAGS.do_lower_case = False
FLAGS.vocab_file = '/kaggle/input/bert-config-vocab/vocab_cased-nq.txt'
FLAGS.bert_config_file = '/kaggle/input/bert-config-vocab/bert_config_cased.json'
i=2
FLAGS.init_checkpoint = ckpts[i]
FLAGS.output_prediction_file = pred_files[i]+'.json'
main_pred()<define_variables>
def drop_corr_ftr(data_df):
data_df=data_df.drop(['2ndFlrSF', 'TotRmsAbvGrd', 'GarageYrBlt', 'GarageArea'], axis=1)
 return data_df
NQLabel = collections.namedtuple(
 'NQLabel',
[
'example_id',
'long_answer_span',
'short_answer_span_list',
'yes_no_answer',
'long_score',
'short_score'
])
 class uitl_Span(object):

 def __init__(self, start_byte, end_byte, start_token_idx, end_token_idx):
if(( start_byte < 0 and end_byte >= 0)or 
(start_byte >= 0 and end_byte < 0)) :
raise ValueError('Inconsistent Null Spans(Byte ).')
 if(( start_token_idx < 0 and end_token_idx >= 0)or 
(start_token_idx >= 0 and end_token_idx < 0)) :
raise ValueError('Inconsistent Null Spans(Token ).')
 if start_byte >= 0 and end_byte >= 0 and start_byte >= end_byte:
raise ValueError('Invalid byte spans(start_byte >= end_byte ).')
 if(( start_token_idx >= 0 and end_token_idx >= 0)and 
(start_token_idx >= end_token_idx)) :
raise ValueError('Invalid token spans(start_token_idx >= end_token_idx)')
 self.start_byte = start_byte
self.end_byte = end_byte
self.start_token_idx = start_token_idx
self.end_token_idx = end_token_idx
def is_null_span(self):

 if(self.start_byte < 0 and self.end_byte < 0 and
self.start_token_idx < 0 and self.end_token_idx < 0):
return True
return False
def __str__(self):
byte_str = 'byte: [' + str(self.start_byte)+ ',' + str(self.end_byte)+ ')'
tok_str =('tok: [' + str(self.start_token_idx)+ ',' + str(
 self.end_token_idx)+ ')')
 return byte_str + ' ' + tok_str
def __repr__(self):
return self.__str__() 
<categorify>
def split_num_obj(data_df):
df_num = data_df.select_dtypes(exclude='object')
 df_obj = data_df.select_dtypes(include='object')
 return df_num, df_obj
def ensemble_nbest_to_nq_pred_dict(nbest_lst, wts, yes_thr=None, no_thr=None):
def sigmoid(x): return 1 /(1 + np.exp(-x))
assert len(nbest_lst)==len(wts)
 nq_pred_dict = {}
for i in range(1,len(nbest_lst)) : assert set(nbest_lst[0].keys())== set(nbest_lst[i].keys())
 for example_id in nbest_lst[0].keys() :
d_long = {}
d_short = {}
yes_logits,no_logits = 0,0
yes_exception, no_exception = False,False
for i,nbest in enumerate(nbest_lst):
if yes_thr and(not yes_exception):
try:
yes_logits += nbest[example_id][0].answer_type_logits[1] * wts[i]
except:
print("exception yes_logits += nbest[example_id][0].answer_type_logits[1] * wts[i]")
 yes_exception = True
if no_thr and(not no_exception):
try:
no_logits += nbest[example_id][0].answer_type_logits[2] * wts[i]
except:
print("exception no_logits += nbest[example_id][0].answer_type_logits[2] * wts[i]")
 no_exception = True
long_seen = set()
short_seen = set()
for score_summary in nbest[example_id]:
pred_lbl = score_summary.predicted_label
long_ans = pred_lbl['long_answer']
short_ans = pred_lbl['short_answers'][0]
long_key = long_ans['start_token'], long_ans['end_token']
short_key = short_ans['start_token'], short_ans['end_token']
if long_key not in long_seen:
long_seen.add(long_key)
 if long_key not in d_long: d_long[long_key] = sigmoid(pred_lbl['long_answer_score'])* wts[i]
else: d_long[long_key]+= sigmoid(pred_lbl['long_answer_score'])* wts[i]
if short_key not in short_seen:
short_seen.add(short_key)
 if short_key not in d_short: d_short[short_key] = sigmoid(pred_lbl['short_answers_score'])* wts[i]
else: d_short[short_key]+= sigmoid(pred_lbl['short_answers_score'])* wts[i] 
(start_tok_long,end_tok_long),prob_long = sorted(list(d_long.items()),key=lambda x:x[1],reverse=True)[0] 
(start_tok_short,end_tok_short),prob_short = sorted(list(d_short.items()),key=lambda x:x[1],reverse=True)[0]
short_answer_span_list = [uitl_Span(-1,-1,start_tok_short,end_tok_short)]
yes_no_answer='none'
try:
if yes_thr and yes_logits > yes_thr:
yes_no_answer,prob_short = 'yes', 999999
short_answer_span_list = [uitl_Span(-1,-1,-1,-1)]
elif no_thr and no_logits > no_thr:
yes_no_answer,prob_short = 'no', 999999
short_answer_span_list = [uitl_Span(-1,-1,-1,-1)]
except:
print('exception if yes_thr and yes_logits > yes_thr...')
 nq_pred_dict[int(example_id)] = NQLabel(
 example_id=example_id,
long_answer_span = uitl_Span(-1, -1, start_tok_long, end_tok_long),
short_answer_span_list = short_answer_span_list,
yes_no_answer=yes_no_answer,
long_score=prob_long,
short_score=prob_short)
 return nq_pred_dict<define_variables>
train_feature_num, train_feature_obj = split_num_obj(train_feature)
 test_feature_num, test_feature_obj = split_num_obj(test_feature )
pkl_lst = [x+'.pkl' for x in pred_files]
pkl_lst<load_pretrained>
train_dummies = pd.get_dummies(train_feature_obj)
 test_dummies = pd.get_dummies(test_feature_obj)
 not_in_train = [column for column in train_dummies.columns if column not in test_dummies.columns]
not_in_test = [column for column in test_dummies.columns if column not in train_dummies.columns]
print('
',train_dummies.shape, test_dummies.shape, '
')
 print('
', not_in_train, '
')
 print('
', not_in_test )
nbest_test_lst = [pickle.load(open(nbest_file,'rb')) for nbest_file in pkl_lst]
nq_pred_dict_en = ensemble_nbest_to_nq_pred_dict(nbest_test_lst, ensemble_wts, yes_thr, no_thr )<categorify>
df_num_cat_col = df_num_col[[0, 3, 4, 15, 16, 17, 18, 19, 20, 21, 22, 28, 29, 30, 31]]
def nqlabel_to_dict(nqlabel):
nqlabel.example_id
nqlabel.long_answer_span
nqlabel.short_answer_span_list
nqlabel.yes_no_answer
nqlabel.long_score
nqlabel.short_score
return {'example_id': int(nqlabel.example_id),
'long_answer': {'start_token': nqlabel.long_answer_span.start_token_idx,
'end_token': nqlabel.long_answer_span.end_token_idx,
'start_byte': nqlabel.long_answer_span.start_byte,
'end_byte': nqlabel.long_answer_span.end_byte},
'long_answer_score': nqlabel.long_score,
'short_answers': [{'start_token': x.start_token_idx,
'end_token': x.end_token_idx,
'start_byte': x.start_byte,
'end_byte': x.end_byte} for x in nqlabel.short_answer_span_list],
'short_answers_score': nqlabel.short_score,
'yes_no_answer': nqlabel.yes_no_answer.upper()
}
test_answers_df = pd.Series([nqlabel_to_dict(v)for(k,v)in nq_pred_dict_en.items() ] ).to_frame()
test_answers_df = test_answers_df.rename(columns={0:'predictions'} )<string_transform>
def split_num_cat(data_df_num):
data_df_num_cat = data_df_num[df_num_cat_col]
data_df_num_non_cat = data_df_num.drop(df_num_cat_col, axis=1)
 return data_df_num_cat, data_df_num_non_cat
train_feature_num_cat, train_feature_num_non_cat = split_num_cat(train_feature_num)
 test_feature_num_cat, test_feature_num_non_cat = split_num_cat(test_feature_num)
 print(train_feature_num_cat.shape,test_feature_num_cat.shape)
 print(train_feature_num_non_cat.shape, test_feature_num_non_cat.shape )
def create_short_answer(entry):
if entry["short_answers_score"] < short_thr:
return ""
answer = []
for short_answer in entry["short_answers"]:
if short_answer["start_token"] > -1:
answer.append(str(short_answer["start_token"])+ ":" + str(short_answer["end_token"]))
if entry["yes_no_answer"] != "NONE":
answer.append(entry["yes_no_answer"])
 return " ".join(answer)
 def create_long_answer(entry):
if entry["long_answer_score"] < long_thr:
return ""
answer = []
if entry["long_answer"]["start_token"] > -1:
answer.append(str(entry["long_answer"]["start_token"])+ ":" + str(entry["long_answer"]["end_token"]))
return " ".join(answer)
 test_answers_df["long_answer_score"] = test_answers_df["predictions"].apply(lambda q: q["long_answer_score"])
 test_answers_df["short_answer_score"] = test_answers_df["predictions"].apply(lambda q: q["short_answers_score"])
 test_answers_df["long_answer"] = test_answers_df["predictions"].apply(create_long_answer)
 test_answers_df["short_answer"] = test_answers_df["predictions"].apply(create_short_answer)
 test_answers_df["example_id"] = test_answers_df["predictions"].apply(lambda q: str(q["example_id"]))
long_answers = dict(zip(test_answers_df["example_id"], test_answers_df["long_answer"]))
short_answers = dict(zip(test_answers_df["example_id"], test_answers_df["short_answer"]))
sample_submission = pd.read_csv('/kaggle/input/tensorflow2-question-answering/sample_submission.csv')
 long_prediction_strings = sample_submission[sample_submission["example_id"].str.contains("_long")].apply(lambda q: long_answers[q["example_id"].replace("_long", "")], axis=1)
 short_prediction_strings = sample_submission[sample_submission["example_id"].str.contains("_short")].apply(lambda q: short_answers[q["example_id"].replace("_short", "")], axis=1)
 sample_submission.loc[sample_submission["example_id"].str.contains("_long"), "PredictionString"] = long_prediction_strings
sample_submission.loc[sample_submission["example_id"].str.contains("_short"), "PredictionString"] = short_prediction_strings
sample_submission.to_csv('submission.csv',index=False )<count_values>
all_data = pd.concat(( train_df, test_df)).reset_index(drop=True)
 all_data.drop('SalePrice', axis=1, inplace=True)
 print(all_data.shape)
 all_data = preprocessing_null(all_data)
 all_data = drop_corr_ftr(all_data)
 print(all_data.shape)
 all_data_num, all_data_obj = split_num_obj(all_data)
 print(all_data_obj.shape )
pd.read_csv('submission.csv' ).count()<load_from_csv>
warnings.filterwarnings(action='ignore')
 label = LabelEncoder()
for col in all_data_obj.columns:
label.fit(all_data_obj.loc[:, col])
 train_feature_obj.loc[:, col] = label.transform(train_feature_obj.loc[:, col])
 test_feature_obj.loc[:, col] = label.transform(test_feature_obj.loc[:, col] )
( pd.read_csv('submission.csv' ).PredictionString=='YES' ).sum() ,(pd.read_csv('submission.csv' ).PredictionString=='NO' ).sum()<import_modules>
train_target = np.log1p(train_target)
 train_feature_num_non_cat = np.log1p(train_feature_num_non_cat)
 test_feature_num_non_cat = np.log1p(test_feature_num_non_cat )
import os
import sys
import json
import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import absl
import datetime<define_variables>
train_feature_fin = pd.concat([train_feature_num_cat, train_feature_num_non_cat, train_feature_obj], axis=1)
 test_feature_fin = pd.concat([test_feature_num_cat, test_feature_num_non_cat, test_feature_obj], axis=1 )
IS_KAGGLE = True
INPUT_DIR = "/kaggle/input/"
BERT_JOINT_BASE_DIR = os.path.join(INPUT_DIR, "bertjointbaseline")
 NQ_DIR = os.path.join(INPUT_DIR, "nq-competition")
 MY_OWN_NQ_DIR = NQ_DIR
if not os.path.isdir(INPUT_DIR):
IS_KAGGLE = False
INPUT_DIR = "./"
NQ_DIR = "./"
MY_OWN_NQ_DIR = "./"
for dirname, _, filenames in os.walk(INPUT_DIR):
for filename in filenames:
print(os.path.join(dirname, filename))
INPUT_DIR<define_variables>
cond1 = train_target>500000
cond2 = train_feature_num_non_cat['GrLivArea']>4000
PRETRAINED_MODELS = {
"BERT": [
'bert-base-uncased',
'bert-large-uncased',
'bert-base-cased',
'bert-large-cased',
'bert-base-multilingual-uncased',
'bert-base-multilingual-cased',
'bert-base-chinese',
'bert-base-german-cased',
'bert-large-uncased-whole-word-masking',
'bert-large-cased-whole-word-masking',
'bert-large-uncased-whole-word-masking-finetuned-squad',
'bert-large-cased-whole-word-masking-finetuned-squad',
'bert-base-cased-finetuned-mrpc'
],
"DISTILBERT": [
'distilbert-base-uncased',
'distilbert-base-uncased-distilled-squad'
]
}<load_pretrained>
train_feature_fin = train_feature_fin.drop(train_feature_num_non_cat[cond1|cond2].index, axis=0 )
flags = absl.flags
del_all_flags(flags.FLAGS)
 flags.DEFINE_bool(
 "do_lower_case", True,
"Whether to lower case the input text.Should be True for uncased "
"models and False for cased models.")
 vocab_file = os.path.join(NQ_DIR, "vocab-nq.txt")
 flags.DEFINE_string("vocab_file", vocab_file,
"The vocabulary file that the BERT model was trained on.")
 flags.DEFINE_integer(
 "max_seq_length_for_training", 512,
"The maximum total input sequence length after WordPiece tokenization for training examples."
"Sequences longer than this will be truncated, and sequences shorter "
"than this will be padded.")
 flags.DEFINE_integer(
 "max_seq_length", 512,
"The maximum total input sequence length after WordPiece tokenization."
"Sequences longer than this will be truncated, and sequences shorter "
"than this will be padded.")
 flags.DEFINE_integer(
 "doc_stride", 128,
"When splitting up a long document into chunks, how much stride to "
"take between chunks.")
 flags.DEFINE_float(
 "include_unknowns_for_training", 0.02,
"If positive, for converting training dataset, probability of including answers of type `UNKNOWN`.")
 flags.DEFINE_float(
 "include_unknowns", -1.0,
"If positive, probability of including answers of type `UNKNOWN`.")
 flags.DEFINE_boolean(
 "skip_nested_contexts", True,
"Completely ignore context that are not top level nodes in the page.")
 flags.DEFINE_integer("max_contexts", 48,
"Maximum number of contexts to output for an example.")
 flags.DEFINE_integer(
 "max_position", 50,
"Maximum context position for which to generate special tokens.")
 flags.DEFINE_integer(
 "max_query_length", 64,
"The maximum number of tokens for the question.Questions longer than "
"this will be truncated to this length." )<load_from_csv>
def get_best_estimator(model, params):
grid_model = GridSearchCV(model, param_grid=params, scoring="neg_mean_squared_error", cv=5)
 grid_model.fit(train_feature_fin, train_target)
 rmse = np.sqrt(-1*grid_model.best_score_)
 print('{0}, param:{1}, rmse:{2}'.format(model.__class__.__name__, grid_model.best_params_,\
np.round(rmse, 4)))
 return grid_model.best_estimator_
ridge_params = {'alpha':[0.05, 0.1, 1, 5, 8, 10, 15]}
lasso_params = {'alpha':[0.001, 0.005, 0.008, 0.05, 0.1, 0.3, 0.5, 1, 5, 10]}
elastic_params = {'alpha':[0.05, 0.1, 0.5, 1, 3, 5, 8]}
ridge_reg = Ridge()
lasso_reg = Lasso()
elastic_reg = ElasticNet(l1_ratio=0.7)
 lasso_be = get_best_estimator(lasso_reg, lasso_params)
 ridge_be = get_best_estimator(ridge_reg, ridge_params)
 elastic_be = get_best_estimator(elastic_reg, elastic_params )
IS_SUBMITTING = False
test_answers_df = pd.read_csv(FLAGS.sample_submission_csv)
 if IS_KAGGLE and len(test_answers_df)!= 692:
IS_SUBMITTING = True
FLAGS.do_train = False
FLAGS.do_valid = False
FLAGS.do_predict = True 
<define_variables>
lgbm_params = {
'max_depth':[5, 10, 15, 20, 25, 30],
'learning_rate':[0.01, 0.05, 0.1, 0.5, 1],
}
lgbm_reg = LGBMRegressor(n_estimators=1000)
 lgbm_be = get_best_estimator(lgbm_reg, lgbm_params )
print(len(test_answers_df))
print(IS_SUBMITTING)
 print(FLAGS.do_train)
 print(FLAGS.do_valid)
 print(FLAGS.do_predict )<define_variables>
preds = np.expm1(lgbm_be.predict(test_feature_fin))
NB_ANSWER_TYPES = 5<string_transform>
test=pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv')
 my_submission = pd.DataFrame({'Id': test.Id,
'SalePrice': preds})
 my_submission.to_csv('submission.csv', index=False )