Kaggle competition: OSIC Pulmonary Fibrosis Progression
<SOS> metric: LaplaceLogLikelihood Kaggle data source: osic-pulmonary-fibrosis-progression<set_options>
!pip install.. /input/kerasapplications/keras-team-keras-applications-3b180cb -f./ --no-index
!pip install.. /input/efficientnet/efficientnet-1.1.0/ -f./ --no-index
%matplotlib inline<load_from_csv>
def seed_everything(seed=2020):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 tf.random.set_seed(seed)
 seed_everything(42 )
train_df = pd.read_csv('.. /input/train.csv')
 train_df.fillna(0,inplace=True)
 train_df<categorify>
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config )
le = LabelEncoder().fit(train_df.species)
 labels = le.transform(train_df.species)
 labels<normalization>
train = pd.read_csv('.. /input/osic-pulmonary-fibrosis-progression/train.csv' )
df.ix[:,2:] = MinMaxScaler().fit_transform(train_df.ix[:,2:])
 df<prepare_x_and_y>
A = {}
TAB = {}
P = []
for i, p in tqdm(enumerate(train.Patient.unique())) :
sub = train.loc[train.Patient == p, :]
fvc = sub.FVC.values
weeks = sub.Weeks.values
c = np.vstack([weeks, np.ones(len(weeks)) ] ).T
a, b = np.linalg.lstsq(c, fvc)[0]
A[p] = a
TAB[p] = get_tab(sub)
 P.append(p )
X = df.as_matrix() [:,2:]
y = df.as_matrix() [:,1]<train_on_grid>
class IGenerator(Sequence):
BAD_ID = ['ID00011637202177653955184', 'ID00052637202186188008618']
def __init__(self, keys, a, tab, batch_size=32):
self.keys = [k for k in keys if k not in self.BAD_ID]
self.a = a
self.tab = tab
self.batch_size = batch_size
self.train_data = {}
for p in train.Patient.values:
self.train_data[p] = os.listdir(f'.. /input/osic-pulmonary-fibrosis-progression/train/{p}/')
 def __len__(self):
return 1000
def __getitem__(self, idx):
x = []
a, tab = [], []
keys = np.random.choice(self.keys, size = self.batch_size)
 for k in keys:
try:
i = np.random.choice(self.train_data[k], size=1)[0]
img = get_img(f'.. /input/osic-pulmonary-fibrosis-progression/train/{k}/{i}')
 x.append(img)
 a.append(self.a[k])
 tab.append(self.tab[k])
 except:
print(k, i)
 x,a,tab = np.array(x), np.array(a), np.array(tab)
 x = np.expand_dims(x, axis=-1)
 return [x, tab] , a
params = {'C':[1500, 2000, 2500], 'tol': [0.0001]}
log_reg = linear_model.LogisticRegression(solver='lbfgs', multi_class='multinomial', max_iter=400)
 clf = GridSearchCV(log_reg, params, scoring='log_loss', refit='True', n_jobs=-1, cv=5)
 clf.fit(X, y)
 print("best params: " + str(clf.best_params_))
for params, mean_score, scores in clf.grid_scores_:
print("%0.3f(+/-%0.03f)for %r" %(mean_score, scores.std() , params))
print(scores )<train_model>
Dense, Dropout, Activation, Flatten, Input, BatchNormalization, GlobalAveragePooling2D, Add, Conv2D, AveragePooling2D,
LeakyReLU, Concatenate 
)
 def get_efficientnet(model, shape):
models_dict = {
'b0': efn.EfficientNetB0(input_shape=shape,weights=None,include_top=False),
'b1': efn.EfficientNetB1(input_shape=shape,weights=None,include_top=False),
'b2': efn.EfficientNetB2(input_shape=shape,weights=None,include_top=False),
'b3': efn.EfficientNetB3(input_shape=shape,weights=None,include_top=False),
'b4': efn.EfficientNetB4(input_shape=shape,weights=None,include_top=False),
'b5': efn.EfficientNetB5(input_shape=shape,weights=None,include_top=False),
'b6': efn.EfficientNetB6(input_shape=shape,weights=None,include_top=False),
'b7': efn.EfficientNetB7(input_shape=shape,weights=None,include_top=False)
 }
return models_dict[model]
def build_model(shape=(512, 512, 1), model_class=None):
inp = Input(shape=shape)
 base = get_efficientnet(model_class, shape)
 x = base(inp)
 x = GlobalAveragePooling2D()(x)
 inp2 = Input(shape=(4,))
x2 = tf.keras.layers.GaussianNoise(0.2 )(inp2)
 x = Concatenate()([x, x2])
 x = Dropout(0.25 )(x)
 x = Dense(1 )(x)
 model = Model([inp, inp2] , x)
 weights = [w for w in os.listdir('.. /input/osic-model-weights')if model_class in w][0]
model.load_weights('.. /input/osic-model-weights/' + weights)
 return model
model_classes = ['b5']
models = [build_model(shape=(512, 512, 1), model_class=m)for m in model_classes]
print('Number of models: ' + str(len(models)) )
estimator = clf 
<load_from_csv>
tr_p, vl_p = train_test_split(P,shuffle=True, train_size= 0.8 )
test_data = pd.read_csv('.. /input/test.csv')
 test_df = DataFrame(MinMaxScaler().fit_transform(test_data.ix[:,1:]))
test_df<predict_on_test>
def score(fvc_true, fvc_pred, sigma):
sigma_clip = np.maximum(sigma, 70)
 delta = np.abs(fvc_true - fvc_pred)
 delta = np.minimum(delta, 1000)
 sq2 = np.sqrt(2)
 metric =(delta / sigma_clip)*sq2 + np.log(sigma_clip* sq2)
 return np.mean(metric )
species = train_df.species.unique()
species.sort()
predict = estimator.predict_proba(test_df.as_matrix())
 result = DataFrame(predict,columns=species)
 result 
<save_to_csv>
subs = []
for model in models:
metric = []
for q in tqdm(range(1, 10)) :
m = []
for p in vl_p:
x = []
tab = []
if p in ['ID00011637202177653955184', 'ID00052637202186188008618']:
continue
ldir = os.listdir(f'.. /input/osic-pulmonary-fibrosis-progression/train/{p}/')
 for i in ldir:
if int(i[:-4])/ len(ldir)< 0.8 and int(i[:-4])/ len(ldir)> 0.15:
x.append(get_img(f'.. /input/osic-pulmonary-fibrosis-progression/train/{p}/{i}'))
tab.append(get_tab(train.loc[train.Patient == p, :]))
if len(x)< 1:
continue
tab = np.array(tab)
 x = np.expand_dims(x, axis=-1)
 _a = model.predict([x, tab])
 a = np.quantile(_a, q / 10)
 percent_true = train.Percent.values[train.Patient == p]
fvc_true = train.FVC.values[train.Patient == p]
weeks_true = train.Weeks.values[train.Patient == p]
fvc = a *(weeks_true - weeks_true[0])+ fvc_true[0]
percent = percent_true[0] - a * abs(weeks_true - weeks_true[0])
 m.append(score(fvc_true, fvc, percent))
print(np.mean(m))
metric.append(np.mean(m))
q =(np.argmin(metric)+ 1)/ 10
sub = pd.read_csv('.. /input/osic-pulmonary-fibrosis-progression/sample_submission.csv')
 test = pd.read_csv('.. /input/osic-pulmonary-fibrosis-progression/test.csv')
 A_test, B_test, P_test,W, FVC= {}, {}, {},{},{}
STD, WEEK = {}, {}
for p in test.Patient.unique() :
x = []
tab = []
ldir = os.listdir(f'.. /input/osic-pulmonary-fibrosis-progression/test/{p}/')
 for i in ldir:
if int(i[:-4])/ len(ldir)< 0.8 and int(i[:-4])/ len(ldir)> 0.15:
x.append(get_img(f'.. /input/osic-pulmonary-fibrosis-progression/test/{p}/{i}'))
tab.append(get_tab(test.loc[test.Patient == p, :]))
if len(x)<= 1:
continue
tab = np.array(tab)
 x = np.expand_dims(x, axis=-1)
 _a = model.predict([x, tab])
 a = np.quantile(_a, q)
 A_test[p] = a
B_test[p] = test.FVC.values[test.Patient == p] - a*test.Weeks.values[test.Patient == p]
P_test[p] = test.Percent.values[test.Patient == p]
WEEK[p] = test.Weeks.values[test.Patient == p]
for k in sub.Patient_Week.values:
p, w = k.split('_')
 w = int(w)
 fvc = A_test[p] * w + B_test[p]
sub.loc[sub.Patient_Week == k, 'FVC'] = fvc
sub.loc[sub.Patient_Week == k, 'Confidence'] =(
 P_test[p] - A_test[p] * abs(WEEK[p] - w)
)
 _sub = sub[["Patient_Week","FVC","Confidence"]].copy()
subs.append(_sub )
result.insert(0,'id',test_data.id)
 result.to_csv('result.csv',index=False )<load_from_csv>
N = len(subs)
 sub = subs[0].copy()
sub["FVC"] = 0
sub["Confidence"] = 0
for i in range(N):
sub["FVC"] += subs[0]["FVC"] *(1/N)
 sub["Confidence"] += subs[0]["Confidence"] *(1/N )
train = pd.read_csv(".. /input/elo-merchant-category-recommendation/train.csv")
 test = pd.read_csv(".. /input/elo-merchant-category-recommendation/test.csv")
 train_df = pd.read_csv(".. /input/fork-of-stacked-lgbm-reduced-models/trainconsol.csv")
 test_df = pd.read_csv(".. /input/fork-of-stacked-lgbm-reduced-models/testconsol.csv")
 train_rfm = pd.read_csv(".. /input/customer-loyalty-based-on-rfm-analysis/trainrfm.csv")
 test_rfm = pd.read_csv(".. /input/customer-loyalty-based-on-rfm-analysis/testrfm.csv")
 feat_imp = pd.read_csv(".. /input/feature-importance-selection/scores_df.csv" )<define_variables>
sub[["Patient_Week","FVC","Confidence"]].to_csv("submission_img.csv", index=False )
<drop_column>
img_sub = sub[["Patient_Week","FVC","Confidence"]].copy()
train_rfm.drop(columns=['first_active_month', 'feature_1', 'feature_2', 'feature_3',
'target', 'year', 'month', 'weekday', 'frequency',
'value', 'recency', 'frequency_new', 'value_new', 'recency_new',
'reference_date', 'category_month_lag','elapsedtime'],inplace= True)
 test_rfm.drop(columns=['first_active_month', 'feature_1', 'feature_2', 'feature_3',
'year', 'month', 'weekday', 'frequency',
'value', 'recency', 'frequency_new', 'value_new', 'recency_new',
'reference_date', 'category_month_lag','elapsedtime'],inplace= True )<merge>
ROOT = ".. /input/osic-pulmonary-fibrosis-progression"
BATCH_SIZE=128
tr = pd.read_csv(f"{ROOT}/train.csv")
 tr.drop_duplicates(keep=False, inplace=True, subset=['Patient','Weeks'])
 chunk = pd.read_csv(f"{ROOT}/test.csv")
 print("add infos")
 sub = pd.read_csv(f"{ROOT}/sample_submission.csv")
 sub['Patient'] = sub['Patient_Week'].apply(lambda x:x.split('_')[0])
 sub['Weeks'] = sub['Patient_Week'].apply(lambda x: int(x.split('_')[-1]))
sub = sub[['Patient','Weeks','Confidence','Patient_Week']]
sub = sub.merge(chunk.drop('Weeks', axis=1), on="Patient" )
train_df= pd.merge(train_df,train_rfm,on='card_id',how='left')
 test_df= pd.merge(test_df,test_rfm,on='card_id',how='left' )<feature_engineering>
tr['WHERE'] = 'train'
chunk['WHERE'] = 'val'
sub['WHERE'] = 'test'
data = tr.append([chunk, sub] )
<drop_column>
print(tr.shape, chunk.shape, sub.shape, data.shape)
 print(tr.Patient.nunique() , chunk.Patient.nunique() , sub.Patient.nunique() ,
data.Patient.nunique() )
target = train_df.target
train_df= train_df.drop(['card_id','target'],axis=1)
 card_id = test_df['card_id']
test_df= test_df.drop(['card_id'],axis=1 )<define_variables>
data['min_week'] = data['Weeks']
data.loc[data.WHERE=='test','min_week'] = np.nan
data['min_week'] = data.groupby('Patient')['min_week'].transform('min' )
features = [c for c in train_df.columns if c not in lessimp_feature ]
categorical_feats = ['feature_2','feature_1','feature_comb_index', 'month','category_month_lag','f_quantile','r_quantile','RFMScore','rnew_quantile','vnew_quantile' ]<init_hyperparams>
base = data.loc[data.Weeks == data.min_week]
base = base[['Patient','FVC']].copy()
base.columns = ['Patient','min_FVC']
base['nb'] = 1
base['nb'] = base.groupby('Patient')['nb'].transform('cumsum')
 base = base[base.nb==1]
base.drop('nb', axis=1, inplace=True )
param = {
'objective':'regression',
'learning_rate': 0.01,
'boosting': 'gbdt',
'num_leaves': 31,
'colsample_bytree': 0.5178284844630764,
'subsample': 0.6701600397051216,
'max_depth': 10,
'reg_alpha': 2.5056142297682493,
'reg_lambda': 2.4364948978876253,
'min_split_gain': 4.947802532689812,
'min_child_weight': 43.41313044141597,
'min_data_in_leaf': 40,
"metric": 'rmse',
'bagging_seed':11,
"verbosity": -1
}
param1= {'num_leaves': 50,
'min_data_in_leaf': 30,
'objective':'regression',
'max_depth': 10,
'learning_rate': 0.005,
"min_child_samples": 100,
"boosting": "gbdt",
"metric": 'rmse',
"feature_fraction": 0.9,
"bagging_freq": 1,
"bagging_fraction": 0.9 ,
"bagging_seed": 11,
"lambda_l1": 0.1,
"verbosity": -1
}<split>
data = data.merge(base, on='Patient', how='left')
 data['base_week'] = data['Weeks'] - data['min_week']
del base
folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=15)
 oof = np.zeros(len(train_df))
predictions = np.zeros(len(test_df))
start = time.time()
feature_importance_df = pd.DataFrame()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_df.values,train_df['feature_comb_index'].values)) :
print("fold n°{}".format(fold_))
trn_data = lgb.Dataset(train_df.iloc[trn_idx][features], label=target.iloc[trn_idx], categorical_feature=categorical_feats)
 val_data = lgb.Dataset(train_df.iloc[val_idx][features], label=target.iloc[val_idx], categorical_feature=categorical_feats)
 num_round = 10000
params= param
clf = lgb.train(params, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=-1, early_stopping_rounds = 200)
 oof[val_idx] = clf.predict(train_df.iloc[val_idx][features], num_iteration=clf.best_iteration)
 fold_importance_df = pd.DataFrame()
fold_importance_df["feature"] = features
fold_importance_df["importance"] = clf.feature_importance()
fold_importance_df["fold"] = fold_ + 1
feature_importance_df = pd.concat([feature_importance_df, fold_importance_df], axis=0)
 predictions += clf.predict(test_df[features], num_iteration=clf.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(mean_squared_error(oof, target)**0.5))<save_to_csv>
COLS = ['Sex','SmokingStatus']
FE = []
for col in COLS:
for mod in data[col].unique() :
FE.append(mod)
 data[mod] =(data[col] == mod ).astype(int )
submit = pd.DataFrame({'card_id':card_id,'target':predictions})
 submit.to_csv("featurecombLGBM1.csv",index=False )<split>
data['age'] =(data['Age'] - data['Age'].min())/(data['Age'].max() - data['Age'].min())
 data['BASE'] =(data['min_FVC'] - data['min_FVC'].min())/(data['min_FVC'].max() - data['min_FVC'].min())
 data['week'] =(data['base_week'] - data['base_week'].min())/(data['base_week'].max() - data['base_week'].min())
 data['percent'] =(data['Percent'] - data['Percent'].min())/(data['Percent'].max() - data['Percent'].min())
 FE += ['age','percent','week','BASE']
folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=15)
 oof1 = np.zeros(len(train_df))
predictions1 = np.zeros(len(test_df))
start = time.time()
feature_importance_df1 = pd.DataFrame()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_df.values,train_df['category_month_lag'].values)) :
print("fold n°{}".format(fold_))
trn_data = lgb.Dataset(train_df.iloc[trn_idx][features], label=target.iloc[trn_idx], categorical_feature=categorical_feats)
 val_data = lgb.Dataset(train_df.iloc[val_idx][features], label=target.iloc[val_idx], categorical_feature=categorical_feats)
 num_round = 10000
params= param
clf1 = lgb.train(params, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=-1, early_stopping_rounds = 200)
 oof1[val_idx] = clf1.predict(train_df.iloc[val_idx][features], num_iteration=clf1.best_iteration)
 fold_importance_df1 = pd.DataFrame()
fold_importance_df1["feature"] = features
fold_importance_df1["importance"] = clf1.feature_importance()
fold_importance_df1["fold"] = fold_ + 1
feature_importance_df1 = pd.concat([feature_importance_df1, fold_importance_df1], axis=0)
 predictions1 += clf1.predict(test_df[features], num_iteration=clf1.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(mean_squared_error(oof1, target)**0.5))<save_to_csv>
tr = data.loc[data.WHERE=='train']
chunk = data.loc[data.WHERE=='val']
sub = data.loc[data.WHERE=='test']
del data
submissioncatmonth = pd.read_csv('.. /input/elo-merchant-category-recommendation/sample_submission.csv')
 submissioncatmonth['target'] = predictions1
submissioncatmonth.to_csv('LGBMcategorymonthlag1.csv', index=False)
<split>
C1, C2 = tf.constant(70, dtype='float32'), tf.constant(1000, dtype="float32")
 def score(y_true, y_pred):
tf.dtypes.cast(y_true, tf.float32)
 tf.dtypes.cast(y_pred, tf.float32)
 sigma = y_pred[:, 2] - y_pred[:, 0]
fvc_pred = y_pred[:, 1]
sigma_clip = tf.maximum(sigma, C1)
 delta = tf.abs(y_true[:, 0] - fvc_pred)
 delta = tf.minimum(delta, C2)
 sq2 = tf.sqrt(tf.dtypes.cast(2, dtype=tf.float32))
metric =(delta / sigma_clip)*sq2 + tf.math.log(sigma_clip* sq2)
 return K.mean(metric)
 def qloss(y_true, y_pred):
qs = [0.2, 0.50, 0.8]
q = tf.constant(np.array([qs]), dtype=tf.float32)
 e = y_true - y_pred
v = tf.maximum(q*e,(q-1)*e)
 return K.mean(v)
 def mloss(_lambda):
def loss(y_true, y_pred):
return _lambda * qloss(y_true, y_pred)+(1 - _lambda)*score(y_true, y_pred)
 return loss
def make_model(nh):
z = L.Input(( nh,), name="Patient")
 x = L.Dense(100, activation="relu", name="d1" )(z)
 x = L.Dense(100, activation="relu", name="d2" )(x)
 p1 = L.Dense(3, activation="linear", name="p1" )(x)
 p2 = L.Dense(3, activation="relu", name="p2" )(x)
 preds = L.Lambda(lambda x: x[0] + tf.cumsum(x[1], axis=1),
name="preds" )([p1, p2])
 model = M.Model(z, preds, name="CNN")
 model.compile(loss=mloss(0.8), optimizer=tf.keras.optimizers.Adam(lr=0.1, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.01, amsgrad=False), metrics=[score])
 return model
folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=15)
 oof2 = np.zeros(len(train_df))
predictions2 = np.zeros(len(test_df))
start = time.time()
feature_importance_df2 = pd.DataFrame()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_df.values,train_df['RFMScore'].values)) :
print("fold n°{}".format(fold_))
trn_data = lgb.Dataset(train_df.iloc[trn_idx][features], label=target.iloc[trn_idx], categorical_feature=categorical_feats)
 val_data = lgb.Dataset(train_df.iloc[val_idx][features], label=target.iloc[val_idx], categorical_feature=categorical_feats)
 num_round = 10000
params= param
clf2 = lgb.train(params, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=-1, early_stopping_rounds = 200)
 oof2[val_idx] = clf2.predict(train_df.iloc[val_idx][features], num_iteration=clf2.best_iteration)
 fold_importance_df2 = pd.DataFrame()
fold_importance_df2["feature"] = features
fold_importance_df2["importance"] = clf2.feature_importance()
fold_importance_df2["fold"] = fold_ + 1
feature_importance_df2 = pd.concat([feature_importance_df2, fold_importance_df2], axis=0)
 predictions2 += clf2.predict(test_df[features], num_iteration=clf2.best_iteration)/ folds.n_splits
print("CV score: {:<8.5f}".format(mean_squared_error(oof2, target)**0.5))<save_to_csv>
y = tr['FVC'].values
z = tr[FE].values
ze = sub[FE].values
nh = z.shape[1]
pe = np.zeros(( ze.shape[0], 3))
pred = np.zeros(( z.shape[0], 3))
submissionrfm = pd.read_csv('.. /input/elo-merchant-category-recommendation/sample_submission.csv')
 submissionrfm['target'] = predictions2
submissionrfm.to_csv('LGBMrfmscore1.csv', index=False)
<create_dataframe>
NFOLD = 5
kf = KFold(n_splits=NFOLD )
folds = RepeatedKFold(n_splits=5, n_repeats=2, random_state=15)
 oof3 = np.zeros(len(train_df))
predictions3 = np.zeros(len(test_df))
start = time.time()
feature_importance_df3 = pd.DataFrame()
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_df.values,target.values)) :
print("fold n°{}".format(fold_))
trn_data = lgb.Dataset(train_df.iloc[trn_idx][features], label=target.iloc[trn_idx], categorical_feature=categorical_feats)
 val_data = lgb.Dataset(train_df.iloc[val_idx][features], label=target.iloc[val_idx], categorical_feature=categorical_feats)
 num_round = 10000
params= param
clf3 = lgb.train(params, trn_data, num_round, valid_sets = [trn_data, val_data], verbose_eval=-1, early_stopping_rounds = 200)
 oof3[val_idx] = clf3.predict(train_df.iloc[val_idx][features], num_iteration=clf3.best_iteration)
 fold_importance_df3 = pd.DataFrame()
fold_importance_df3["feature"] = features
fold_importance_df3["importance"] = clf3.feature_importance()
fold_importance_df3["fold"] = fold_ + 1
feature_importance_df3 = pd.concat([feature_importance_df3, fold_importance_df3], axis=0)
 predictions3 += clf3.predict(test_df[features], num_iteration=clf3.best_iteration)/(5 * 2)
 print("CV score: {:<8.5f}".format(mean_squared_error(oof3, target)**0.5))<save_to_csv>
%%time
cnt = 0
EPOCHS = 1500
for tr_idx, val_idx in kf.split(z):
cnt += 1
print(f"FOLD {cnt}")
 net = make_model(nh)
 net.fit(z[tr_idx], y[tr_idx], batch_size=BATCH_SIZE, epochs=EPOCHS,
validation_data=(z[val_idx], y[val_idx]), verbose=0)
 print("train", net.evaluate(z[tr_idx], y[tr_idx], verbose=0, batch_size=BATCH_SIZE))
print("val", net.evaluate(z[val_idx], y[val_idx], verbose=0, batch_size=BATCH_SIZE))
print("predict val...")
 pred[val_idx] = net.predict(z[val_idx], batch_size=BATCH_SIZE, verbose=0)
 print("predict test...")
 pe += net.predict(ze, batch_size=BATCH_SIZE, verbose=0)/ NFOLD
submissiontarget = pd.read_csv('.. /input/elo-merchant-category-recommendation/sample_submission.csv')
 submissiontarget['target'] = predictions3
submissiontarget.to_csv('LGBMfinal1.csv', index=False)
<save_to_csv>
sigma_opt = mean_absolute_error(y, pred[:, 1])
 unc = pred[:,2] - pred[:, 0]
sigma_mean = np.mean(unc)
 print(sigma_opt, sigma_mean )
oof.to_csv("oof.csv",index=False)
 oof1.to_csv("oof1.csv",index=False)
 oof2.to_csv("oof2.csv",index=False)
 oof3.to_csv("oof3.csv",index=False )<prepare_x_and_y>
sub['FVC1'] = 1.*pe[:, 1]
sub['Confidence1'] = pe[:, 2] - pe[:, 0]
subm = sub[['Patient_Week','FVC','Confidence','FVC1','Confidence1']].copy()
subm.loc[~subm.FVC1.isnull() ].head(10 )
train_stack = np.vstack([oof,oof1,oof2,oof3] ).transpose()
test_stack = np.vstack([predictions, predictions1, predictions2,predictions3] ).transpose()
folds_stack = RepeatedKFold(n_splits=5, n_repeats=1, random_state=4590)
 oof_stack = np.zeros(train_stack.shape[0])
 predictions4 = np.zeros(test_stack.shape[0])
 for fold_,(trn_idx, val_idx)in enumerate(folds_stack.split(train_stack,target)) :
print("fold {}".format(fold_))
trn_data, trn_y = train_stack[trn_idx], target.iloc[trn_idx].values
val_data, val_y = train_stack[val_idx], target.iloc[val_idx].values
clf4 = BayesianRidge()
clf4.fit(trn_data, trn_y)
 oof_stack[val_idx] = clf4.predict(val_data)
 predictions4 += clf4.predict(test_stack)/ 5
np.sqrt(mean_squared_error(target.values, oof_stack))<save_to_csv>
subm.loc[~subm.FVC1.isnull() ,'FVC'] = subm.loc[~subm.FVC1.isnull() ,'FVC1']
if sigma_mean<70:
subm['Confidence'] = sigma_opt
else:
subm.loc[~subm.FVC1.isnull() ,'Confidence'] = subm.loc[~subm.FVC1.isnull() ,'Confidence1']
sample_submission = pd.read_csv('.. /input/elo-merchant-category-recommendation/sample_submission.csv')
 sample_submission['target'] = predictions4
sample_submission.to_csv('LGBMstacksubmissionfinal1.csv', index=False )<define_variables>
otest = pd.read_csv('.. /input/osic-pulmonary-fibrosis-progression/test.csv')
 for i in range(len(otest)) :
subm.loc[subm['Patient_Week']==otest.Patient[i]+'_'+str(otest.Weeks[i]), 'FVC'] = otest.FVC[i]
subm.loc[subm['Patient_Week']==otest.Patient[i]+'_'+str(otest.Weeks[i]), 'Confidence'] = 0.1
List = ['old_duration_min', 'old_purchase_date_uptonow', 'new_purchase_date_uptonow', 'old_category_1__1_count', 'old_authorized_flag__0_fraction', 'new_purchase_amount_max', 'new_weekofyear_mean', 'old_authorized_flag__0_count', 'new_purchase_date_diff', 'old_subsector_id_bins__(11.614, 12.465]_fraction', 'new_weekofyear_max', 'old_merchant_id_bins__(3.091, 4.111]_fraction', 'new_duration_max', 'old_amount_month_ratio_min', 'new_day_mean', 'old_merchant_category_id_bins__(9.368, 10.692]_fraction', 'old_duration_mean', 'old_purchase_date_month_diff_max', 'old_purchase_amount_median', 'old_purchase_date_month_diff_median', 'old_category_1__1_fraction', 'new_month_mean', 'old_Children_day_2017_mean', 'days_feature2', 'old_category_1__0_fraction', 'old_subsector_id_bins__(12.465, 13.476]_fraction', 'days_feature1', 'old_category_3__C_fraction', 'old_day_mean', 'new_amount_month_ratio_max', 'old_purchase_date_month_diff_std', 'old_price_var', 'new_Christmas_Day_2017_mean', 'old_hour_mean', 'old_installments_sum', 'old_subsector_id_bins__(13.476, 15.537]_fraction', 'new_Black_Friday_2017_mean', 'old_purchase_date_month_diff_sum', 'old_month_lag_skew', 'new_duration_mean', 'old_month_lag_mad', 'new_weekofyear_min', 'new_day_max', 'old_merchant_id_bins__(2.197, 3.091]_fraction', 'new_hour_mean', 'old_category_3__B_count', 'old_merchant_category_id_bins__(10.692, 15.53]_fraction', 'old_purchase_date_diff', 'old_weekday_mean', 'old_subsector_id_bins__(12.465, 13.476]_count', 'old_subsector_id_bins__(10.06, 11.614]_fraction', 'old_month_lag_sum', 'old_weekofyear_nunique', 'old_category_3__C_count', 'new_purchase_amount_median', 'days_feature2_ratio', 'old_purchase_date_uptomin', 'old_weekend_mean', 'new_duration_min', 'old_month_lag_std', 'days_feature1_ratio', 'days_feature3', 'old_purchase_date_month_diff_mean', 'new_purchase_amount_mean', 'old_Black_Friday_2017_mean', 'old_category_3__B_fraction', 'new_Children_day_2017_mean', 'old_merchant_id_bins__(1.099, 2.197]_fraction', 'new_purchase_date_uptomin', 'old_purchase_date_month_diff_min', 'new_Mothers_Day_2018_mean', 'old_merchant_category_id_bins__(7.849, 9.368]_fraction', 'old_price_mean', 'old_purchase_amount_skew', 'new_duration_var', 'old_duration_max', 'old_merchant_id_bins__(4.111, 14.042]_fraction', 'new_price_var', 'new_month_lag_std', 'old_category_2__1.0_count', 'old_purchase_amount_mean', 'old_amount_month_ratio_mean', 'new_month_lag_max', 'new_amount_month_ratio_mean', 'old_amount_month_ratio_skew', 'old_installments_std', 'old_city_id_bins__(11.183, 15.391]_fraction', 'old_authorized_flag__1_fraction', 'new_hour_min', 'new_purchase_amount_sum', 'old_category_1__0_count', 'old_city_id_bins__(10.474, 11.183]_fraction', 'new_month_lag_skew', 'new_price_min', 'old_merchant_category_id_bins__(9.368, 10.692]_count', 'old_duration_skew', 'old_Christmas_Day_2017_mean', 'old_city_id_bins__(11.183, 15.391]_count', 'new_amount_month_ratio_var', 'new_amount_month_ratio_min', 'old_category_3__A_fraction', 'old_installments_skew', 'new_day_min', 'old_state_id_bins__(14.065, 16.173]_count', 'old_subsector_id_bins__(11.614, 12.465]_count', 'old_installments_mad', 'new_weekday_mean', 'old_merchant_id_bins__(-0.001, 1.099]_fraction', 'new_subsector_id_bins__(11.111, 12.737]_fraction', 'old_category_2__1.0_fraction', 'old_merchant_id_bins__(3.091, 4.111]_count', 'old_city_id_bins__(9.928, 10.474]_fraction', 'old_amount_month_ratio_max', 'old_purchase_amount_sum', 'elapsed_time', 'old_month_mean', 'old_subsector_id_bins__(4.819, 10.06]_fraction', 'old_weekofyear_max', 'old_weekofyear_min', 'old_month_lag_median', 'old_purchase_amount_mad', 'old_price_max', 'old_weekofyear_mean', 'new_category_3__A_count', 'new_hour_max', 'new_purchase_amount_mad', 'old_category_3__A_count', 'old_amount_month_ratio_var', 'new_purchase_amount_std', 'old_category_2__4.0_fraction', 'old_subsector_id_bins__(13.476, 15.537]_count', 'old_purchase_amount_max', 'new_month_lag_median', 'old_state_id_bins__(13.479, 14.065]_fraction', 'old_subsector_id_bins__(10.06, 11.614]_count', 'old_city_id_bins__(9.441, 9.928]_fraction', 'old_duration_var', 'new_subsector_id_bins__(10.053, 11.111]_fraction', 'old_category_2__5.0_fraction', 'new_purchase_amount_skew', 'old_category_2__4.0_count', 'old_state_id_bins__(14.065, 16.173]_fraction', 'old_city_id_bins__(10.474, 11.183]_count', 'old_category_2__3.0_fraction', 'new_category_3__B_fraction', 'new_price_mean', 'old_city_id_bins__(9.928, 10.474]_count', 'new_merchant_id_bins__(2.079, 10.804]_fraction', 'new_duration_skew', 'new_price_max', 'old_merchant_category_id_bins__(5.533, 7.849]_fraction', 'old_hour_nunique', 'old_Mothers_Day_2018_mean', 'old_state_id_bins__(12.236, 12.862]_fraction', 'old_merchant_id_bins__(2.197, 3.091]_count', 'old_price_min', 'old_purchase_amount_std', 'new_amount_month_ratio_skew', 'old_state_id_bins__(12.862, 13.479]_fraction', 'old_state_id_bins__(8.885, 12.236]_count', 'new_merchant_category_id_bins__(8.485, 12.163]_fraction', 'new_subsector_id_bins__(9.477, 10.053]_fraction', 'old_day_max', 'old_merchant_category_id_bins__(10.692, 15.53]_count', 'old_city_id_bins__(3.806, 9.441]_fraction', 'new_merchant_category_id_bins__(8.485, 12.163]_count', 'old_hour_min', 'old_category_2__2.0_fraction', 'days_feature3_ratio', 'old_state_id_bins__(12.862, 13.479]_count', 'new_merchant_id_bins__(0.693, 1.386]_fraction', 'old_day_nunique', 'old_authorized_flag__1_count', 'new_subsector_id_bins__(11.111, 12.737]_count', 'old_state_id_bins__(13.479, 14.065]_count', 'new_category_2__1.0_count', 'new_installments_std', 'new_month_max', 'new_merchant_category_id_bins__(7.156, 8.485]_fraction', 'new_month_lag_sum', 'old_merchant_id_bins__(4.111, 14.042]_count', 'old_category_2__5.0_count', 'new_category_3__B_count', 'new_month_lag_mean', 'old_state_id_bins__(8.885, 12.236]_fraction', 'new_installments_sum', 'old_category_2__3.0_count', 'new_merchant_id_bins__(2.079, 10.804]_count', 'new_merchant_id_bins__(1.386, 2.079]_fraction', 'new_hist_count', 'new_installments_mad', 'old_merchant_category_id_bins__(7.849, 9.368]_count', 'old_month_lag_mean', 'new_merchant_id_bins__(-0.001, 0.693]_fraction', 'new_installments_skew', 'new_city_id_bins__(8.641, 12.704]_count', 'old_month_lag_max', 'new_installments_median', 'old_merchant_id_bins__(1.099, 2.197]_count', 'new_state_id_bins__(11.433, 13.505]_count', 'old_day_min', 'new_weekday_min', 'new_weekday_max', 'old_state_id_bins__(12.236, 12.862]_count', 'old_installments_max', 'feature_var', 'new_category_2__5.0_fraction', 'old_merchant_category_id_bins__(-0.001, 5.533]_fraction', 'quarter', 'new_month_lag_mad', 'new_category_3__C_fraction', 'new_weekend_mean', 'new_installments_max', 'old_city_id_bins__(9.441, 9.928]_count', 'old_merchant_category_id_bins__(5.533, 7.849]_count', 'old_category_2__2.0_count', 'new_category_2__1.0_fraction', 'new_state_id_bins__(11.433, 13.505]_fraction', 'new_city_id_bins__(8.641, 12.704]_fraction', 'new_weekofyear_nunique', 'new_category_3__A_fraction', 'feature_sum', 'new_installments_mean', 'new_city_id_bins__(7.249, 7.814]_fraction', 'old_hist_count', 'old_hour_max', 'new_subsector_id_bins__(7.706, 9.477]_fraction', 'new_day_nunique', 'new_subsector_id_bins__(10.053, 11.111]_count', 'new_category_2__4.0_fraction', 'old_city_id_bins__(3.806, 9.441]_count', 'new_state_id_bins__(9.474, 10.222]_fraction', 'new_hour_nunique', 'new_merchant_category_id_bins__(5.822, 7.156]_fraction', 'old_subsector_id_bins__(4.819, 10.06]_count', 'new_city_id_bins__(7.814, 8.641]_fraction', 'new_state_id_bins__(10.886, 11.433]_fraction', 'new_merchant_category_id_bins__(3.434, 5.822]_fraction', 'feature1_3', 'new_month_min', 'old_month_min', 'new_city_id_bins__(6.778, 7.249]_fraction', 'new_category_2__4.0_count', 'feature1_1', 'new_merchant_id_bins__(0.693, 1.386]_count', 'old_month_max', 'new_category_2__2.0_fraction', 'new_state_id_bins__(9.474, 10.222]_count', 'old_merchant_id_bins__(-0.001, 1.099]_count', 'new_state_id_bins__(10.886, 11.433]_count', 'new_state_id_bins__(10.222, 10.886]_fraction', 'new_category_2__5.0_count', 'old_installments_median', 'new_category_2__3.0_count', 'new_category_3__C_count', 'feature1_4', 'new_city_id_bins__(7.814, 8.641]_count', 'new_state_id_bins__(5.877, 9.474]_fraction', 'new_merchant_category_id_bins__(7.156, 8.485]_count', 'new_city_id_bins__(6.778, 7.249]_count', 'new_state_id_bins__(10.222, 10.886]_count', 'new_category_2__3.0_fraction', 'feature1_2', 'new_merchant_id_bins__(-0.001, 0.693]_count', 'new_merchant_id_bins__(1.386, 2.079]_count', 'new_category_2__2.0_count', 'new_city_id_bins__(1.608, 6.778]_fraction', 'old_merchant_category_id_bins__(-0.001, 5.533]_count', 'feature_2', 'new_city_id_bins__(7.249, 7.814]_count', 'old_weekday_max', 'feature_1', 'new_merchant_category_id_bins__(-0.001, 3.434]_fraction', 'new_subsector_id_bins__(9.477, 10.053]_count', 'new_state_id_bins__(5.877, 9.474]_count', 'old_weekday_min', 'feature2_2', 'new_subsector_id_bins__(2.0780000000000003, 7.706]_fraction', 'new_subsector_id_bins__(7.706, 9.477]_count', 'new_merchant_category_id_bins__(5.822, 7.156]_count', 'feature_max', 'feature_mean', 'feature_3', 'new_city_id_bins__(1.608, 6.778]_count', 'new_merchant_category_id_bins__(3.434, 5.822]_count', 'old_installments_mean', 'feature2_3', 'feature3_1', 'feature1_5', 'new_subsector_id_bins__(2.0780000000000003, 7.706]_count', 'feature2_1', 'new_merchant_category_id_bins__(-0.001, 3.434]_count', 'feature3_0', 'feature_min']
All_feature_new_extra = ['new_hist_purchase_amount_max', 'hist_month_diff_mean', 'hist_purchase_date_max', 'new_hist_weekofyear_mean', 'hist_authorized_flag_mean_x', 'new_hist_purchase_date_max', 'new_hist_purchase_amount_var', 'new_hist_purchase_date_diff', 'new_hist_purchase_amount_median', 'new_hist_month_lag_mean', 'hist_month_nunique', 'authorized_flag_N', 'new_hist_month_mean', 'new_hist_weekofyear_max', 'month_lag_0', 'subsector_id_x_8', 'hist_purchase_date_average', 'merchant_category_id_x_755', 'new_hist_purchase_date_average', 'hist_purchase_amount_mean', 'new_hist_purchase_date_uptonow', 'hist_purchase_amount_median', 'new_hist_category_1_mean', 'hist_month_lag_mean', 'hist_purchase_date_min', 'category_1_x_Y', 'hist_first_buy', 'new_hist_weekofyear_min', 'hist_last_buy', 'month_lag_1', 'month_lag_-5', 'hist_purchase_amount_var', 'hist_month_lag_var', 'new_hist_purchase_amount_min', 'hist_month_diff_var', 'month_lag_-6', 'hist_category_1_mean', 'hist_month_lag_skew', 'purchase_amount_skew', 'new_hist_weekofyear_median', 'hist_hour_mean', 'hist_dayofweek_mean', 'category_1_y_Y', 'month_lag_-1', 'avg_purchases_lag3_min', 'new_hist_purchase_date_uptomin', 'hist_purchase_date_diff', 'merchant_category_id_x_661', 'hist_installments_mean', 'subsector_id_x_37', 'new_hist_hour_median', 'month_lag_-3', 'hist_purchase_amount_skew', 'hist_installments_var', 'category_3_C', 'hist_year_mean', 'hist_category_1_sum', 'category_4_Y', 'subsector_id_x_7', 'hist_installments_sum', 'hist_merchant_id_nunique', 'new_hist_category_1_sum', 'month_lag_-2', 'new_hist_last_buy', 'hist_category_3_sum', 'purchase_amount_median', 'month_lag_-8', 'new_hist_first_buy', 'hist_weekend_mean', 'purchase_amount_min', 'avg_sales_lag12_min', 'most_recent_sales_range_C', 'month_lag_-7', 'purchase_amount_std', 'numerical_2_skew', 'installments_3', 'subsector_id_x_33', 'most_recent_purchases_range_B', 'merchant_category_id_x_511', 'installments_0', 'hist_weekofyear_nunique', 'installments_2', 'subsector_id_x_29', 'subsector_id_x_34', 'avg_purchases_lag6_min', 'new_hist_purchase_amount_skew', 'merchant_category_id_x_278', 'merchant_category_id_x_451', 'most_recent_purchases_range_D', 'numerical_1_skew', 'avg_sales_lag12_skew', 'merchant_category_id_x_879', 'new_hist_month_diff_mean', 'avg_purchases_lag12_median', 'new_hist_purchase_date_min', 'avg_purchases_lag6_median', 'avg_sales_lag3_min', 'hist_installments_skew', 'city_id_x_69', 'new_hist_month_lag_var', 'avg_purchases_lag3_median', 'month_lag_-9', 'hist_weekofyear_min', 'purchase_amount_total', 'category_2_x_1.0', 'city_id_x_-1', 'hist_category_2_mean_mean', 'subsector_id_x_22', 'category_2_y_1.0', 'avg_purchases_lag3_skew', 'most_recent_sales_range_B', 'most_recent_purchases_range_A', 'most_recent_sales_range_A', 'hist_weekofyear_mean', 'avg_sales_lag3_skew', 'hist_purchase_amount_min', 'most_recent_purchases_range_C', 'subsector_id_x_27', 'new_hist_dayofweek_mean', 'state_id_x_9', 'state_id_x_-1', 'hist_purchase_amount_sum', 'avg_sales_lag6_min', 'most_recent_sales_range_D', 'new_hist_installments_var', 'avg_sales_lag12_median', 'new_hist_category_3_mean_mean', 'category_1_y_N', 'merchant_category_id_x_574', 'avg_sales_lag3_mean', 'hist_merchant_category_id_nunique', 'category_1_x_N', 'hist_month_mean', 'avg_purchases_lag3_mean', 'numerical_2_mean', 'avg_sales_lag6_median', 'most_recent_purchases_range_E', 'hist_month_diff_max', 'hist_weekofyear_max', 'new_hist_month_max', 'subsector_id_x_19', 'avg_sales_lag3_std', 'avg_purchases_lag6_skew', 'avg_sales_lag6_skew', 'avg_sales_lag12_mean', 'weekofyear', 'avg_purchases_lag12_skew', 'feature_1', 'new_hist_hour_max', 'merchant_category_id_x_705', 'avg_purchases_lag12_min', 'avg_purchases_lag3_std', 'merchant_category_id_x_839', 'hist_purchase_date_uptonow', 'elapsed_time', 'merchant_category_id_x_80', 'merchant_category_id_x_683', 'active_months_lag12_7.0', 'avg_purchases_lag12_mean', 'merchant_category_id_x_307', 'new_hist_installments_skew', 'numerical_2_median', 'most_recent_sales_range_E', 'new_hist_month_lag_skew', 'city_id_x_158', 'hist_category_2_sum', 'hist_purchase_date_uptomin', 'numerical_1_median', 'numerical_2_std', 'subsector_id_x_1', 'month_lag_-10', 'month_lag_-11', 'new_hist_installments_mean', 'avg_sales_lag6_mean', 'new_hist_category_2_sum', 'city_id_x_283', 'hist_subsector_id_nunique', 'month_lag_2', 'avg_sales_lag3_median', 'numerical_1_max', 'avg_sales_lag12_std', 'merchant_category_id_x_108', 'numerical_1_mean', 'merchant_category_id_x_560', 'merchant_category_id_x_367', 'avg_purchases_lag6_std', 'subsector_id_x_16', 'subsector_id_x_21', 'hist_category_2_mean', 'merchant_category_id_x_302', 'installments_4', 'merchant_category_id_x_690', 'new_hist_merchant_category_id_nunique', 'subsector_id_x_15', 'hist_hour_median', 'hist_weekend_sum', 'merchant_category_id_x_90', 'avg_sales_lag6_std', 'state_id_x_15', 'installments_12', 'city_id_x_330', 'new_hist_month_min', 'category_2_y_4.0', 'merchant_category_id_x_884', 'numerical_1_std', 'city_id_x_79', 'merchant_category_id_x_68', 'hist_weekofyear_median', 'installments_5', 'merchant_category_id_x_665', 'merchant_category_id_x_210', 'merchant_category_id_x_178', 'hist_authorized_flag_mean_y', 'state_id_x_12', 'dayofyear', 'merchant_category_id_x_414', 'subsector_id_x_25', 'merchant_category_id_x_422', 'state_id_x_16', 'merchant_category_id_x_836', 'feature_2_y', 'city_id_x_195', 'hist_hour_min', 'merchant_category_id_x_217', 'category_2_x_4.0', 'new_hist_category_2_mean_mean', 'avg_purchases_lag12_std', 'hist_hour_nunique', 'authorized_flag_Y', 'merchant_category_id_x_111', 'merchant_category_id_x_360', 'installments_6', 'subsector_id_x_20', 'card_id_total', 'avg_sales_lag3_max', 'hist_month_lag_median', 'merchant_category_id_x_734', 'installments_10', 'city_id_x_138', 'merchant_category_id_x_792', 'subsector_id_x_36', 'new_hist_installments_sum', 'category_2_y_2.0', 'merchant_category_id_x_87', 'city_id_x_308', 'subsector_id_x_30', 'new_hist_weekend_mean', 'city_id_x_116', 'merchant_category_id_x_842', 'subsector_id_x_3', 'city_id_x_337', 'avg_sales_lag12_max', 'state_id_x_22', 'city_id_x_266', 'dayofweek', 'new_hist_month_median', 'subsector_id_x_18', 'subsector_id_x_17', 'category_2_x_5.0', 'month', 'merchant_category_id_x_398', 'merchant_category_id_x_656', 'new_hist_category_3_mean', 'city_id_x_19', 'new_hist_card_id_count', 'city_id_x_149', 'city_id_x_53', 'state_id_x_24', 'merchant_category_id_x_222', 'hist_authorized_flag_sum_x', 'new_hist_dayofweek_median', 'new_hist_subsector_id_nunique', 'new_hist_weekofyear_nunique', 'avg_purchases_lag6_max', 'subsector_id_x_31', 'city_id_x_233', 'month_lag_-12', 'category_2_x_2.0', 'city_id_x_212', 'merchant_category_id_x_650', 'state_id_x_10', 'city_id_x_87', 'city_id_x_213', 'merchant_category_id_x_195', 'city_id_x_3', 'city_id_x_107', 'merchant_category_id_x_273', 'new_hist_hour_nunique', 'merchant_category_id_x_783', 'merchant_category_id_x_598', 'new_hist_dayofweek_max', 'merchant_category_id_x_497', 'state_id_x_19', 'city_id_x_91', 'new_hist_month_lag_max', 'new_hist_dayofweek_min', 'merchant_category_id_x_454', 'avg_purchases_lag3_max', 'avg_purchases_lag12_max', 'city_id_x_267', 'merchant_category_id_x_771', 'city_id_x_88', 'city_id_x_286', 'hist_installments_max', 'merchant_category_id_x_557', 'category_2_y_5.0', 'merchant_category_id_x_19', 'merchant_category_id_x_779', 'avg_sales_lag6_max', 'merchant_category_id_x_373', 'city_id_x_8', 'city_id_x_333', 'state_id_x_4', 'state_id_x_5', 'merchant_category_id_x_184', 'state_id_x_20', 'new_hist_merchant_id_nunique', 'merchant_category_id_x_434', 'merchant_category_id_x_317', 'new_hist_month_diff_median', 'city_id_x_168', 'city_id_x_96', 'new_hist_category_3_min', 'hist_month_diff_min', 'active_months_lag6_6.0', 'city_id_x_137', 'hist_month_diff_median', 'state_id_x_2', 'merchant_category_id_x_45', 'city_id_x_274', 'merchant_category_id_x_834', 'city_id_x_110', 'merchant_category_id_x_550', 'state_id_x_11', 'city_id_x_244', 'subsector_id_x_32', 'state_id_x_3', 'city_id_x_331', 'merchant_category_id_x_427', 'active_months_lag12_12.0', 'hist_card_id_count', 'city_id_x_253', 'merchant_category_id_x_332', 'merchant_category_id_x_206', 'merchant_category_id_x_309', 'city_id_x_322', 'new_hist_installments_max', 'city_id_x_126', 'subsector_id_x_2', 'hist_month_lag_max', 'hist_hour_max', 'city_id_x_277', 'city_id_x_347', 'subsector_id_x_-1', 'city_id_x_296', 'city_id_x_329', 'new_hist_installments_median', 'numerical_2_max', 'state_id_x_21', 'city_id_x_124', 'subsector_id_x_10', 'merchant_category_id_x_556', 'merchant_category_id_x_299', 'hist_dayofweek_median', 'city_id_x_299', 'merchant_category_id_x_38', 'new_hist_category_3_sum', 'city_id_x_179', 'city_id_x_7', 'state_id_x_7', 'subsector_id_x_5', 'city_id_x_117', 'new_hist_year_nunique', 'merchant_category_id_x_818', 'subsector_id_x_38', 'new_hist_installments_min', 'quarter', 'state_id_x_1', 'subsector_id_x_41', 'installments_-1', 'merchant_category_id_x_607', 'hist_month_min', 'hist_month_lag_min', 'merchant_category_id_x_518', 'city_id_x_325', 'subsector_id_x_4', 'hist_month_median', 'city_id_x_20', 'hist_category_2_max', 'city_id_x_1', 'merchant_category_id_x_544', 'city_id_x_291', 'feature_3', 'merchant_category_id_x_819', 'merchant_category_id_x_561', 'merchant_category_id_x_298', 'city_id_x_280', 'city_id_x_182', 'subsector_id_x_35', 'city_id_x_106', 'city_id_x_60', 'state_id_x_14', 'installments_7', 'new_hist_dayofweek_nunique', 'city_id_x_102', 'merchant_category_id_x_130', 'hist_category_3_min', 'merchant_category_id_x_519', 'city_id_x_223', 'merchant_category_id_x_34', 'hist_installments_min', 'merchant_category_id_x_419', 'merchant_category_id_x_290', 'city_id_x_171', 'city_id_x_340', 'city_id_x_38', 'merchant_category_id_x_840', 'hist_month_max', 'state_id_x_13', 'city_id_x_334', 'merchant_category_id_x_387', 'hist_installments_median', 'feature_1_y', 'city_id_x_163', 'city_id_x_125', 'city_id_x_25', 'merchant_category_id_x_369', 'merchant_category_id_x_356', 'merchant_category_id_x_2', 'merchant_category_id_x_706', 'city_id_x_208', 'category_3_A', 'city_id_x_318', 'city_id_x_143', 'city_id_x_216', 'city_id_x_236', 'feature_2_x', 'city_id_x_62', 'city_id_x_250', 'merchant_category_id_x_489', 'city_id_x_14', 'city_id_x_64', 'city_id_x_159', 'city_id_x_100', 'city_id_x_289', 'new_hist_weekend_sum', 'city_id_x_188', 'subsector_id_x_9', 'merchant_category_id_x_384', 'merchant_category_id_x_813', 'city_id_x_4', 'merchant_category_id_x_793', 'city_id_x_12', 'merchant_category_id_x_63', 'city_id_x_21', 'city_id_x_278', 'merchant_category_id_x_554', 'merchant_category_id_x_645', 'city_id_x_199', 'city_id_x_57', 'city_id_x_231', 'merchant_category_id_x_630', 'city_id_x_56', 'merchant_category_id_x_9', 'merchant_category_id_x_781', 'new_hist_category_2_max', 'city_id_x_344', 'city_id_x_242', 'city_id_x_97', 'merchant_category_id_x_411', 'merchant_category_id_x_415', 'city_id_x_200', 'merchant_category_id_x_14', 'merchant_category_id_x_491', 'city_id_x_198', 'hist_dayofweek_nunique', 'city_id_x_80', 'merchant_category_id_x_110', 'city_id_x_52', 'merchant_category_id_x_412', 'merchant_category_id_x_769', 'merchant_category_id_x_527', 'month_lag_-13', 'state_id_x_18', 'subsector_id_x_12', 'city_id_x_51', 'state_id_x_8', 'numerical_1_min', 'merchant_category_id_x_241', 'city_id_x_262', 'city_id_x_36', 'city_id_x_42', 'merchant_category_id_x_246', 'new_hist_month_diff_max', 'city_id_x_281', 'subsector_id_x_26', 'merchant_category_id_x_330', 'merchant_category_id_x_385', 'city_id_x_94', 'city_id_x_75', 'active_months_lag12_9.0', 'merchant_category_id_x_198', 'city_id_x_218', 'city_id_x_147', 'merchant_category_id_x_105', 'state_id_x_17', 'merchant_category_id_x_763', 'installments_8', 'city_id_x_90', 'merchant_category_id_x_171', 'city_id_x_209', 'city_id_x_140', 'city_id_x_160', 'merchant_category_id_x_774', 'city_id_x_341', 'merchant_category_id_x_259', 'city_id_x_271', 'city_id_x_304', 'active_months_lag3_3.0', 'merchant_category_id_x_667', 'merchant_category_id_x_248', 'merchant_category_id_x_181', 'new_hist_category_1_median', 'city_id_x_339', 'merchant_category_id_x_333', 'merchant_category_id_x_56', 'city_id_x_270', 'city_id_x_260', 'merchant_category_id_x_692', 'state_id_x_23', 'merchant_category_id_x_363', 'city_id_x_328', 'city_id_x_66', 'merchant_category_id_x_33', 'merchant_category_id_x_478', 'new_hist_month_diff_min', 'city_id_x_34', 'active_months_lag12_5.0', 'city_id_x_47', 'city_id_x_323', 'city_id_x_10', 'city_id_x_2', 'city_id_x_161', 'merchant_category_id_x_528', 'merchant_category_id_x_40', 'city_id_x_272', 'city_id_x_170', 'city_id_x_279', 'city_id_x_248', 'merchant_category_id_x_795', 'merchant_category_id_x_637', 'merchant_category_id_x_319', 'subsector_id_x_23', 'city_id_x_155', 'new_hist_category_2_min', 'merchant_category_id_x_209', 'city_id_x_78', 'merchant_category_id_x_531', 'city_id_x_239', 'merchant_category_id_x_748', 'merchant_category_id_x_546', 'city_id_x_251', 'city_id_x_206', 'city_id_x_151', 'merchant_category_id_x_409', 'merchant_category_id_x_703', 'merchant_category_id_x_383', 'city_id_x_180', 'city_id_x_76', 'city_id_x_101', 'city_id_x_238', 'city_id_x_26', 'city_id_x_288', 'active_months_lag12_3.0', 'active_months_lag12_6.0', 'city_id_x_40', 'city_id_x_46', 'merchant_category_id_x_568', 'merchant_category_id_x_529', 'city_id_x_85', 'merchant_category_id_x_391', 'city_id_x_258', 'merchant_category_id_x_438', 'city_id_x_302', 'city_id_x_292', 'city_id_x_30', 'merchant_category_id_x_166', 'merchant_category_id_x_695', 'city_id_x_230', 'merchant_category_id_x_631', 'merchant_category_id_x_480', 'city_id_x_35', 'merchant_category_id_x_60', 'city_id_x_190', 'active_months_lag12_11.0', 'merchant_category_id_x_605', 'merchant_category_id_x_443', 'merchant_category_id_x_670', 'city_id_x_326', 'hist_category_2_min', 'city_id_x_48', 'city_id_x_303', 'new_hist_month_lag_median', 'merchant_category_id_x_416', 'active_months_lag6_4.0', 'city_id_x_247', 'merchant_category_id_x_651', 'city_id_x_11', 'city_id_x_135', 'merchant_category_id_x_462', 'city_id_x_123', 'merchant_category_id_x_320', 'city_id_x_24', 'merchant_category_id_x_437', 'city_id_x_285', 'merchant_category_id_x_289', 'city_id_x_345', 'city_id_x_214', 'merchant_category_id_x_623', 'merchant_category_id_x_668', 'city_id_x_113', 'merchant_category_id_x_881', 'merchant_category_id_x_126', 'merchant_category_id_x_81', 'city_id_x_184', 'city_id_x_194', 'city_id_x_221', 'city_id_x_224', 'city_id_x_227', 'city_id_x_17', 'merchant_category_id_x_267', 'city_id_x_82', 'city_id_x_33', 'merchant_category_id_x_215', 'active_months_lag12_8.0', 'city_id_x_29', 'city_id_x_39', 'city_id_x_311', 'merchant_category_id_x_472', 'city_id_x_327', 'subsector_id_x_39', 'active_months_lag3_2.0', 'merchant_category_id_x_642', 'merchant_category_id_x_761', 'numerical_2_min', 'merchant_category_id_x_357', 'merchant_category_id_x_823', 'merchant_category_id_x_-1', 'merchant_category_id_x_458', 'merchant_category_id_x_396', 'merchant_category_id_x_312', 'installments_9', 'merchant_category_id_x_506', 'new_hist_month_lag_min', 'merchant_category_id_x_69', 'merchant_category_id_x_420', 'city_id_x_13', 'city_id_x_191', 'city_id_x_54', 'city_id_x_9', 'merchant_category_id_x_340', 'city_id_x_268', 'city_id_x_162', 'city_id_x_187', 'merchant_category_id_x_78', 'city_id_x_246', 'merchant_category_id_x_274', 'city_id_x_234', 'installments_11', 'city_id_x_23', 'city_id_x_109', 'hist_authorized_flag_sum_y', 'city_id_x_115', 'city_id_x_130', 'city_id_x_103', 'city_id_x_136', 'merchant_category_id_x_671', 'city_id_x_294', 'merchant_category_id_x_386', 'city_id_x_256', 'merchant_category_id_x_180', 'merchant_category_id_x_57', 'city_id_x_297', 'city_id_x_314', 'merchant_category_id_x_591', 'city_id_x_169', 'city_id_x_150', 'city_id_x_173', 'hist_dayofweek_min', 'city_id_x_245', 'city_id_x_219', 'merchant_category_id_x_342', 'new_hist_month_nunique', 'city_id_x_282', 'subsector_id_x_40', 'merchant_category_id_x_216', 'merchant_category_id_x_154', 'feature_1_x', 'new_hist_card_id_size', 'merchant_category_id_x_432', 'city_id_x_189', 'city_id_x_74', 'merchant_category_id_x_225', 'merchant_category_id_x_614', 'city_id_x_131', 'city_id_x_146', 'hist_year_nunique', 'city_id_x_174', 'city_id_x_71', 'city_id_x_300', 'hist_card_id_size', 'merchant_category_id_x_114', 'merchant_category_id_x_843', 'city_id_x_16', 'merchant_category_id_x_891', 'subsector_id_x_14', 'city_id_x_232', 'merchant_category_id_x_702', 'new_hist_year_mean', 'hist_category_1_median', 'merchant_category_id_x_885', 'hist_dayofweek_max', 'city_id_x_298', 'city_id_x_22', 'merchant_category_id_x_119', 'merchant_category_id_x_224', 'city_id_x_32', 'city_id_x_63', 'feature_2', 'merchant_category_id_x_53', 'merchant_category_id_x_737', 'city_id_x_275', 'feature_3_y', 'city_id_x_193', 'city_id_x_295', 'city_id_x_335', 'city_id_x_156', 'city_id_x_235', 'merchant_category_id_x_179', 'city_id_x_157', 'city_id_x_269', 'merchant_category_id_x_400', 'merchant_category_id_x_292', 'city_id_x_142', 'city_id_x_120', 'city_id_x_264', 'city_id_x_205', 'city_id_x_144', 'merchant_category_id_x_499', 'city_id_x_259', 'new_hist_category_1_min', 'city_id_x_18', 'city_id_x_342', 'city_id_x_61', 'active_months_lag12_4.0', 'city_id_x_166', 'city_id_x_276', 'merchant_category_id_x_829', 'city_id_x_201', 'merchant_category_id_x_534', 'merchant_category_id_x_514', 'city_id_x_252', 'merchant_category_id_x_474', 'merchant_category_id_x_374', 'city_id_x_226', 'state_id_x_6', 'merchant_category_id_x_315', 'merchant_category_id_x_593', 'city_id_x_204', 'city_id_x_98', 'merchant_category_id_x_713', 'new_hist_weekend_median', 'merchant_category_id_x_71', 'city_id_x_119', 'merchant_category_id_x_827', 'merchant_category_id_x_21', 'city_id_x_139', 'merchant_category_id_x_172', 'city_id_x_108', 'city_id_x_73', 'hist_category_1_max', 'merchant_category_id_x_117', 'city_id_x_336', 'merchant_category_id_x_16', 'city_id_x_301', 'merchant_category_id_x_806', 'merchant_category_id_x_796', 'merchant_category_id_x_751', 'merchant_category_id_x_247', 'city_id_x_41', 'subsector_id_x_13', 'merchant_category_id_x_417', 'merchant_category_id_x_265', 'city_id_x_172', 'city_id_x_133', 'merchant_category_id_x_669', 'city_id_x_210', 'city_id_x_263', 'city_id_x_312', 'city_id_x_320', 'active_months_lag6_5.0', 'active_months_lag6_3.0', 'city_id_x_254', 'city_id_x_167', 'merchant_category_id_x_696', 'merchant_category_id_x_157', 'merchant_category_id_x_717', 'merchant_category_id_x_507', 'new_hist_category_1_max', 'active_months_lag6_2.0', 'new_hist_year_median', 'merchant_category_id_x_430', 'city_id_x_153', 'city_id_x_148', 'merchant_category_id_x_573', 'city_id_x_181', 'city_id_x_118', 'merchant_category_id_x_854', 'city_id_x_70', 'city_id_x_261', 'city_id_x_321', 'city_id_x_307', 'city_id_x_293', 'city_id_x_111', 'subsector_id_x_24', 'city_id_x_290', 'hist_weekend_median', 'merchant_category_id_x_348', 'merchant_category_id_x_36', 'hist_category_1_min', 'city_id_x_338', 'city_id_x_240', 'merchant_category_id_x_873', 'merchant_category_id_x_276', 'city_id_x_6', 'city_id_x_211', 'city_id_x_81', 'feature_3_x', 'subsector_id_x_11', 'city_id_x_68', 'city_id_x_44', 'merchant_category_id_x_504', 'city_id_x_310', 'merchant_category_id_x_613', 'city_id_x_86', 'city_id_x_287', 'city_id_x_229', 'merchant_category_id_x_182', 'merchant_category_id_x_456', 'city_id_x_265', 'merchant_category_id_x_808', 'city_id_x_183', 'city_id_x_228', 'new_hist_year_max', 'city_id_x_255', 'city_id_x_343', 'merchant_category_id_x_471', 'merchant_category_id_x_469', 'city_id_x_104', 'merchant_category_id_x_162', 'merchant_category_id_x_889', 'merchant_category_id_x_687', 'merchant_category_id_x_686', 'city_id_x_105', 'merchant_category_id_x_685', 'merchant_category_id_x_131', 'city_id_x_114', 'city_id_x_89', 'merchant_category_id_x_676', 'active_months_lag12_2.0', 'merchant_category_id_x_183', 'merchant_category_id_x_140', 'new_hist_category_3_max', 'merchant_category_id_x_882', 'city_id_x_65', 'subsector_id_x_28', 'city_id_x_112', 'merchant_category_id_x_67', 'merchant_category_id_x_145', 'merchant_category_id_x_18', 'merchant_category_id_x_141', 'city_id_x_84', 'new_hist_weekend_min', 'merchant_category_id_x_817', 'merchant_category_id_x_814', 'merchant_category_id_x_83', 'new_hist_year_min', 'merchant_category_id_x_805', 'merchant_category_id_x_803', 'city_id_x_77', 'new_hist_weekend_max', 'merchant_category_id_x_847', 'city_id_x_83', 'merchant_category_id_x_153', 'merchant_category_id_x_741', 'merchant_category_id_x_86', 'merchant_category_id_x_725', 'merchant_category_id_x_718', 'merchant_category_id_x_714', 'merchant_category_id_x_875', 'active_months_lag6_1.0', 'merchant_category_id_x_712', 'merchant_category_id_x_164', 'active_months_lag3_1.0', 'merchant_category_id_x_878', 'hist_category_3_max', 'merchant_category_id_x_187', 'city_id_x_165', 'merchant_category_id_x_664', 'merchant_category_id_x_27', 'hist_year_median', 'merchant_category_id_x_311', 'merchant_category_id_x_31', 'hist_year_max', 'hist_weekend_min', 'merchant_category_id_x_464', 'city_id_x_237', 'merchant_category_id_x_281', 'merchant_category_id_x_482', 'merchant_category_id_x_49', 'merchant_category_id_x_662', 'city_id_x_222', 'city_id_x_220', 'merchant_category_id_x_268', 'merchant_category_id_x_498', 'city_id_x_92', 'merchant_category_id_x_266', 'merchant_category_id_x_509', 'merchant_category_id_x_513', 'city_id_x_207', 'merchant_category_id_x_457', 'merchant_category_id_x_448', 'hist_year_min', 'merchant_category_id_x_436', 'merchant_category_id_x_343', 'merchant_category_id_x_322', 'city_id_x_306', 'merchant_category_id_x_345', 'merchant_category_id_x_351', 'city_id_x_309', 'merchant_category_id_x_355', 'merchant_category_id_x_358', 'city_id_x_313', 'merchant_category_id_x_37', 'city_id_x_28', 'merchant_category_id_x_381', 'city_id_x_315', 'merchant_category_id_x_393', 'city_id_x_316', 'city_id_x_273', 'merchant_category_id_x_401', 'city_id_x_319', 'merchant_category_id_x_421', 'city_id_x_203', 'merchant_category_id_x_52', 'merchant_category_id_x_523', 'merchant_category_id_x_599', 'merchant_category_id_x_603', 'merchant_category_id_x_220', 'city_id_x_49', 'city_id_x_145', 'hist_authorized_flag_max', 'merchant_category_id_x_628', 'merchant_category_id_x_634', 'merchant_category_id_x_648', 'merchant_category_id_x_201', 'merchant_category_id_x_192', 'merchant_category_id_x_190', 'city_id_x_58', 'city_id_x_129', 'city_id_x_128', 'hist_weekend_max', 'merchant_category_id_x_652', 'merchant_category_id_x_653', 'hist_authorized_flag_min', 'city_id_x_122', 'merchant_category_id_x_601', 'merchant_category_id_x_223', 'merchant_category_id_x_526', 'merchant_category_id_x_59', 'merchant_category_id_x_530', 'city_id_x_197', 'merchant_category_id_x_261', 'merchant_category_id_x_536', 'merchant_category_id_x_542', 'merchant_category_id_x_551', 'city_id_x_186', 'city_id_x_185', 'merchant_category_id_x_260', 'merchant_category_id_x_249', 'merchant_category_id_x_579', 'city_id_x_178', 'city_id_x_175', 'merchant_category_id_x_245', 'merchant_category_id_x_580', 'merchant_category_id_x_583', 'merchant_category_id_x_226', 'merchant_category_id_x_587', 'merchant_category_id_x_334', 'city_id_x_215'] 
<define_variables>
subm[["Patient_Week","FVC","Confidence"]].to_csv("submission_regression.csv", index=False )
features_current_model = ['old_duration_min', 'new_purchase_amount_max', 'new_duration_max', 'hist_month_diff_mean', 'new_hist_month_lag_mean', 'hist_month_nunique', 'new_hist_weekofyear_max', 'new_hist_weekofyear_mean', 'new_Christmas_Day_2017_mean', 'new_day_mean', 'new_purchase_date_uptonow', 'new_hist_purchase_date_diff', 'old_authorized_flag__0_fraction', 'merchant_category_id_x_755', 'new_Black_Friday_2017_mean', 'new_amount_month_ratio_max', 'new_hist_category_1_mean', 'days_feature2', 'subsector_id_x_8', 'new_weekofyear_min', 'hist_purchase_date_uptonow', 'month_lag_0', 'old_amount_month_ratio_min', 'new_month_mean', 'month_lag_1', 'old_merchant_category_id_bins__(9.368, 10.692]_fraction', 'new_hist_purchase_date_average', 'category_1_x_Y', 'new_Children_day_2017_mean', 'new_hist_weekofyear_median', 'old_price_var', 'old_purchase_amount_median', 'new_day_max', 'hist_purchase_date_max', 'old_subsector_id_bins__(11.614, 12.465]_fraction', 'merchant_category_id_x_661', 'old_Children_day_2017_mean', 'old_merchant_id_bins__(3.091, 4.111]_fraction', 'new_hist_category_1_sum', 'new_amount_month_ratio_mean', 'authorized_flag_N', 'old_purchase_date_month_diff_std', 'days_feature1', 'new_duration_min', 'new_duration_var', 'new_purchase_amount_median', 'hist_purchase_amount_mean', 'old_category_1__0_fraction', 'old_purchase_date_month_diff_max', 'hist_month_lag_mean', 'old_category_3__C_fraction', 'month_lag_-5', 'old_purchase_date_month_diff_median', 'month_lag_-6', 'old_authorized_flag__0_count', 'merchant_category_id_x_451', 'hist_category_1_sum', 'hist_merchant_id_nunique', 'new_Mothers_Day_2018_mean', 'new_hist_hour_median', 'month_lag_-8', 'category_1_y_Y', 'merchant_category_id_x_511', 'subsector_id_x_37', 'hist_purchase_date_min', 'month_lag_-3', 'hist_first_buy', 'old_day_mean', 'month_lag_-1', 'hist_authorized_flag_mean_y', 'old_category_3__B_fraction', 'old_subsector_id_bins__(10.06, 11.614]_fraction', 'new_hist_purchase_amount_var', 'days_feature3', 'hist_last_buy', 'subsector_id_x_7', 'days_feature1_ratio', 'old_subsector_id_bins__(13.476, 15.537]_fraction', 'old_subsector_id_bins__(12.465, 13.476]_fraction', 'avg_purchases_lag3_min', 'avg_sales_lag12_min', 'new_amount_month_ratio_var', 'old_hour_mean', 'new_price_var', 'hist_month_lag_skew', 'hist_dayofweek_mean', 'old_subsector_id_bins__(12.465, 13.476]_count', 'old_amount_month_ratio_var', 'merchant_category_id_x_879', 'month_lag_-2', 'new_day_min', 'old_month_lag_mad', 'days_feature2_ratio', 'old_Black_Friday_2017_mean', 'new_category_3__A_count', 'hist_month_diff_var', 'hist_category_3_sum', 'old_weekofyear_min', 'old_amount_month_ratio_mean', 'new_hist_last_buy', 'category_4_Y', 'merchant_category_id_x_278', 'hist_purchase_date_average', 'new_amount_month_ratio_min', 'purchase_amount_skew', 'new_hist_purchase_amount_min', 'installments_3', 'month_lag_-9', 'installments_2', 'merchant_category_id_x_705', 'hist_installments_mean', 'hist_year_mean', 'old_duration_var', 'subsector_id_x_22', 'hist_installments_sum', 'old_purchase_date_month_diff_sum', 'purchase_amount_median', 'merchant_category_id_x_574', 'old_weekend_mean', 'old_merchant_id_bins__(1.099, 2.197]_fraction', 'hist_weekofyear_nunique', 'new_hist_purchase_date_uptomin', 'avg_sales_lag3_min', 'hist_category_1_mean', 'old_category_3__C_count', 'most_recent_sales_range_C', 'city_id_x_69', 'new_price_min', 'month_lag_-7', 'old_month_lag_std', 'subsector_id_x_29', 'old_merchant_category_id_bins__(7.849, 9.368]_fraction', 'old_purchase_date_uptomin', 'hist_merchant_category_id_nunique', 'purchase_amount_min', 'city_id_x_283', 'avg_sales_lag6_min', 'old_purchase_amount_mad', 'new_hist_month_diff_mean', 'state_id_x_-1', 'new_hist_purchase_date_max', 'new_hour_max', 'old_month_lag_sum', 'merchant_category_id_x_839', 'numerical_2_skew', 'numerical_1_skew', 'merchant_category_id_x_217', 'subsector_id_x_34', 'old_merchant_category_id_bins__(9.368, 10.692]_count', 'old_purchase_date_month_diff_min', 'old_merchant_id_bins__(4.111, 14.042]_fraction', 'purchase_amount_total', 'state_id_x_9', 'avg_purchases_lag6_min', 'old_subsector_id_bins__(4.819, 10.06]_fraction', 'old_Christmas_Day_2017_mean', 'hist_purchase_amount_skew', 'old_city_id_bins__(10.474, 11.183]_fraction', 'hist_month_diff_max', 'most_recent_sales_range_B', 'subsector_id_x_27', 'category_2_y_1.0', 'old_city_id_bins__(9.928, 10.474]_fraction', 'merchant_category_id_x_90', 'city_id_x_158', 'most_recent_purchases_range_B', 'new_hist_dayofweek_mean', 'avg_sales_lag12_median', 'old_city_id_bins__(11.183, 15.391]_fraction', 'category_3_C', 'old_purchase_date_month_diff_mean', 'subsector_id_x_33', 'avg_sales_lag6_median', 'active_months_lag12_7.0', 'merchant_category_id_x_302', 'merchant_category_id_x_665', 'new_hist_month_lag_skew', 'new_hist_month_lag_var', 'old_merchant_id_bins__(-0.001, 1.099]_fraction', 'old_amount_month_ratio_skew', 'most_recent_sales_range_A', 'avg_purchases_lag3_median', 'old_duration_skew', 'most_recent_purchases_range_D', 'new_subsector_id_bins__(11.111, 12.737]_fraction', 'city_id_x_330', 'hist_weekofyear_max', 'old_purchase_amount_std', 'numerical_2_median', 'merchant_category_id_x_836', 'most_recent_purchases_range_C', 'hist_purchase_date_diff', 'old_merchant_category_id_bins__(5.533, 7.849]_fraction', 'old_merchant_category_id_bins__(-0.001, 5.533]_fraction', 'old_category_1__1_fraction', 'most_recent_sales_range_D', 'old_purchase_amount_sum', 'dayofyear', 'numerical_1_mean', 'avg_purchases_lag3_skew', 'most_recent_purchases_range_A', 'purchase_amount_std', 'avg_purchases_lag6_median', 'merchant_category_id_x_683', 'old_category_2__4.0_fraction', 'installments_4', 'hist_installments_var', 'new_price_max', 'hist_purchase_amount_min', 'category_2_x_1.0', 'old_subsector_id_bins__(11.614, 12.465]_count', 'avg_purchases_lag12_median', 'city_id_x_79', 'avg_sales_lag12_skew', 'city_id_x_-1', 'category_1_y_N', 'avg_purchases_lag3_mean', 'avg_sales_lag3_skew', 'city_id_x_337', 'city_id_x_195', 'new_hist_month_max', 'weekofyear', 'old_merchant_id_bins__(3.091, 4.111]_count', 'state_id_x_12', 'old_city_id_bins__(9.441, 9.928]_fraction', 'avg_sales_lag3_mean', 'merchant_category_id_x_734', 'old_subsector_id_bins__(10.06, 11.614]_count', 'installments_0', 'avg_purchases_lag3_std', 'old_category_3__A_count', 'old_category_2__1.0_fraction', 'category_1_x_N', 'new_hist_installments_var', 'month_lag_-10', 'old_installments_mad', 'old_weekofyear_mean', 'new_purchase_amount_skew', 'old_state_id_bins__(13.479, 14.065]_fraction', 'new_hist_first_buy', 'avg_sales_lag3_median', 'avg_purchases_lag12_min', 'old_month_mean', 'installments_12', 'merchant_category_id_x_307', 'new_hist_category_3_mean_mean', 'city_id_x_53', 'merchant_category_id_x_414', 'merchant_category_id_x_80', 'avg_sales_lag6_skew', 'city_id_x_266', 'numerical_2_std', 'merchant_category_id_x_398', 'avg_purchases_lag12_mean', 'new_category_3__B_fraction', 'avg_purchases_lag12_skew', 'new_hist_purchase_amount_max', 'old_Mothers_Day_2018_mean', 'numerical_1_max', 'city_id_x_308', 'city_id_x_116', 'old_state_id_bins__(12.862, 13.479]_fraction', 'state_id_x_24', 'most_recent_sales_range_E', 'old_city_id_bins__(11.183, 15.391]_count', 'hist_category_2_mean_mean', 'most_recent_purchases_range_E', 'numerical_1_median', 'new_hist_installments_mean', 'old_category_2__1.0_count', 'merchant_category_id_x_178', 'city_id_x_87', 'city_id_x_267', 'month_lag_-11', 'merchant_category_id_x_560', 'merchant_category_id_x_108', 'new_merchant_category_id_bins__(8.485, 12.163]_fraction', 'hist_month_diff_median', 'subsector_id_x_19', 'avg_sales_lag3_std', 'merchant_category_id_x_210', 'avg_sales_lag12_mean', 'city_id_x_91', 'old_city_id_bins__(9.928, 10.474]_count', 'new_subsector_id_bins__(10.053, 11.111]_fraction', 'new_purchase_date_uptomin', 'old_state_id_bins__(12.236, 12.862]_fraction', 'old_state_id_bins__(8.885, 12.236]_fraction', 'avg_sales_lag12_std', 'avg_purchases_lag6_skew', 'old_city_id_bins__(10.474, 11.183]_count', 'old_state_id_bins__(14.065, 16.173]_count', 'hist_subsector_id_nunique', 'new_merchant_id_bins__(2.079, 10.804]_fraction', 'hist_category_2_sum', 'city_id_x_149', 'hist_hour_median', 'merchant_category_id_x_792', 'old_state_id_bins__(8.885, 12.236]_count', 'old_category_2__5.0_fraction', 'old_state_id_bins__(12.862, 13.479]_count', 'subsector_id_x_21', 'state_id_x_15', 'month_lag_2', 'new_month_lag_max', 'subsector_id_x_16', 'merchant_category_id_x_650', 'avg_sales_lag6_mean', 'merchant_category_id_x_184', 'old_category_2__2.0_fraction', 'subsector_id_x_1', 'city_id_x_138', 'old_city_id_bins__(3.806, 9.441]_fraction', 'new_hist_category_2_sum', 'new_category_3__B_count', 'merchant_category_id_x_68', 'merchant_category_id_x_656', 'old_purchase_date_uptonow', 'merchant_category_id_x_111', 'installments_5', 'city_id_x_96', 'old_price_min', 'new_purchase_date_diff', 'avg_sales_lag6_std', 'city_id_x_286', 'state_id_x_22', 'new_merchant_id_bins__(0.693, 1.386]_fraction', 'old_month_lag_median', 'subsector_id_x_15', 'new_amount_month_ratio_skew', 'hist_installments_skew', 'old_installments_std', 'city_id_x_233', 'old_installments_sum', 'state_id_x_10', 'merchant_category_id_x_422', 'new_subsector_id_bins__(11.111, 12.737]_count', 'city_id_x_253', 'category_2_y_4.0', 'new_duration_skew', 'new_subsector_id_bins__(9.477, 10.053]_fraction', 'new_hist_month_median', 'city_id_x_88', 'merchant_category_id_x_690', 'new_merchant_id_bins__(-0.001, 0.693]_fraction', 'new_hist_merchant_category_id_nunique', 'old_subsector_id_bins__(13.476, 15.537]_count', 'city_id_x_110', 'new_month_lag_sum', 'state_id_x_16', 'old_merchant_category_id_bins__(5.533, 7.849]_count', 'hist_weekend_sum', 'new_weekofyear_mean', 'merchant_category_id_x_497', 'avg_purchases_lag12_std', 'merchant_category_id_x_598', 'installments_6', 'city_id_x_3', 'city_id_x_274', 'subsector_id_x_3', 'city_id_x_19', 'subsector_id_x_30', 'merchant_category_id_x_367', 'old_installments_skew', 'old_category_1__0_count', 'hist_weekofyear_median', 'city_id_x_107', 'merchant_category_id_x_454', 'new_installments_median', 'city_id_x_212', 'merchant_category_id_x_273', 'city_id_x_8', 'merchant_category_id_x_771', 'old_state_id_bins__(14.065, 16.173]_fraction', 'hist_hour_min', 'new_hist_purchase_date_uptonow', 'merchant_category_id_x_360', 'merchant_category_id_x_222', 'subsector_id_x_25', 'month_lag_-12', 'merchant_category_id_x_87', 'subsector_id_x_17', 'subsector_id_x_36', 'category_2_y_2.0', 'city_id_x_213', 'merchant_category_id_x_842', 'new_hist_installments_skew', 'old_category_1__1_count', 'merchant_category_id_x_884', 'installments_10', 'avg_sales_lag12_max', 'numerical_2_mean', 'avg_purchases_lag6_max', 'days_feature3_ratio', 'new_weekofyear_max', 'subsector_id_x_31', 'old_hour_nunique', 'old_category_2__4.0_count', 'subsector_id_x_20', 'new_installments_mad', 'new_installments_skew', 'old_day_max', 'old_day_min', 'merchant_category_id_x_779', 'city_id_x_126', 'old_merchant_category_id_bins__(10.692, 15.53]_count', 'new_hist_month_min', 'merchant_category_id_x_206', 'city_id_x_137', 'new_merchant_id_bins__(1.386, 2.079]_fraction', 'merchant_category_id_x_427', 'numerical_1_std', 'city_id_x_168', 'new_hist_dayofweek_median', 'city_id_x_331', 'avg_sales_lag3_max', 'authorized_flag_Y', 'old_merchant_category_id_bins__(7.849, 9.368]_count', 'new_installments_std', 'new_merchant_id_bins__(2.079, 10.804]_count', 'new_month_lag_mad', 'state_id_x_20', 'old_day_nunique', 'feature1_3', 'hist_month_diff_min', 'city_id_x_333', 'state_id_x_4', 'new_hist_purchase_date_min', 'dayofweek', 'new_merchant_category_id_bins__(3.434, 5.822]_fraction', 'subsector_id_x_18', 'old_state_id_bins__(13.479, 14.065]_count', 'old_city_id_bins__(9.441, 9.928]_count', 'merchant_category_id_x_550', 'feature_var', 'new_merchant_category_id_bins__(7.156, 8.485]_fraction', 'old_merchant_id_bins__(1.099, 2.197]_count', 'elapsed_time', 'state_id_x_19', 'avg_purchases_lag6_std', 'new_weekday_min', 'old_state_id_bins__(12.236, 12.862]_count', 'new_category_3__A_fraction', 'hist_purchase_amount_median', 'new_hist_category_2_mean_mean', 'state_id_x_2', 'new_category_2__4.0_count', 'new_installments_mean', 'new_category_2__1.0_count', 'new_merchant_category_id_bins__(8.485, 12.163]_count', 'card_id_total', 'new_hist_month_mean', 'new_city_id_bins__(8.641, 12.704]_fraction', 'feature1_1', 'merchant_category_id_x_309', 'new_hist_purchase_amount_median', 'avg_purchases_lag3_max', 'merchant_category_id_x_834', 'city_id_x_322', 'city_id_x_244', 'merchant_category_id_x_434', 'merchant_category_id_x_557', 'merchant_category_id_x_19', 'merchant_category_id_x_373', 'old_month_lag_max', 'feature_sum', 'merchant_category_id_x_195', 'old_city_id_bins__(3.806, 9.441]_count', 'merchant_category_id_x_783', 'avg_sales_lag6_max', 'merchant_category_id_x_45', 'new_city_id_bins__(8.641, 12.704]_count', 'new_hist_dayofweek_max', 'category_2_x_4.0', 'old_month_lag_skew', 'avg_purchases_lag12_max', 'old_merchant_id_bins__(4.111, 14.042]_count', 'state_id_x_5', 'new_state_id_bins__(11.433, 13.505]_fraction', 'merchant_category_id_x_317', 'new_hist_weekofyear_nunique', 'new_hist_weekofyear_min', 'old_category_2__2.0_count', 'new_category_3__C_fraction', 'merchant_category_id_x_332', 'new_weekend_mean', 'new_category_2__5.0_fraction', 'hist_category_2_mean', 'new_hist_hour_nunique', 'state_id_x_3', 'new_category_2__2.0_fraction', 'state_id_x_11', 'hist_purchase_date_uptomin', 'new_city_id_bins__(7.814, 8.641]_fraction', 'new_merchant_category_id_bins__(5.822, 7.156]_fraction', 'new_city_id_bins__(7.249, 7.814]_fraction', 'new_hist_installments_max', 'hist_installments_max', 'new_state_id_bins__(11.433, 13.505]_count', 'new_subsector_id_bins__(7.706, 9.477]_fraction', 'old_category_2__5.0_count', 'new_state_id_bins__(9.474, 10.222]_fraction', 'new_hist_card_id_count', 'subsector_id_x_2', 'category_2_y_5.0', 'new_category_2__4.0_fraction', 'new_hist_subsector_id_nunique', 'new_hist_category_3_mean', 'new_state_id_bins__(10.886, 11.433]_fraction', 'old_authorized_flag__1_count', 'new_installments_sum', 'old_subsector_id_bins__(4.819, 10.06]_count', 'hist_authorized_flag_mean_x', 'new_category_2__1.0_fraction', 'old_hour_max', 'category_2_x_2.0', 'new_day_nunique', 'subsector_id_x_32', 'old_merchant_id_bins__(-0.001, 1.099]_count', 'hist_month_lag_var', 'new_hist_merchant_id_nunique', 'new_hist_installments_sum', 'old_weekday_mean', 'new_month_lag_skew', 'new_state_id_bins__(9.474, 10.222]_count', 'hist_hour_mean', 'category_2_x_5.0', 'new_city_id_bins__(6.778, 7.249]_fraction', 'new_purchase_amount_std', 'new_subsector_id_bins__(10.053, 11.111]_count', 'new_month_lag_std', 'old_month_lag_mean', 'new_merchant_id_bins__(0.693, 1.386]_count', 'hist_weekend_mean', 'active_months_lag6_6.0', 'active_months_lag12_12.0', 'new_purchase_amount_mean', 'hist_weekofyear_min', 'old_month_min', 'feature_1', 'old_weekofyear_nunique', 'old_purchase_amount_skew', 'new_month_lag_median', 'new_weekday_mean', 'new_installments_max', 'old_weekofyear_max', 'new_state_id_bins__(10.886, 11.433]_count', 'old_month_max', 'old_hist_count', 'hist_purchase_amount_var', 'hist_purchase_amount_sum', 'hist_month_mean', 'old_purchase_amount_mean', 'new_hist_purchase_amount_skew', 'feature_2_y', 'old_purchase_date_diff', 'new_hist_hour_max', 'new_hist_category_3_min', 'new_month_max', 'old_installments_max', 'month', 'old_hour_min', 'hist_weekofyear_mean', 'new_month_min', 'hist_month_lag_median', 'new_hist_month_diff_median', 'hist_hour_nunique', 'new_month_lag_mean', 'new_weekday_max', 'hist_month_lag_max', 'new_hist_count', 'new_hist_weekend_mean', 'new_weekofyear_nunique', 'new_hist_dayofweek_min', 'new_hist_month_lag_max', 'new_hour_nunique', 'hist_authorized_flag_sum_x', 'old_authorized_flag__1_fraction', 'hist_card_id_count', 'quarter']<load_pretrained>
reg_sub = subm[["Patient_Week","FVC","Confidence"]].copy()
df_train_old = pd.read_pickle(".. /input/features-from-old-model/train_old_features.pkl")
 df_test_old = pd.read_pickle(".. /input/features-from-old-model/test_old_features.pkl" )<load_pretrained>
df1 = img_sub.sort_values(by=['Patient_Week'], ascending=True ).reset_index(drop=True)
 df2 = reg_sub.sort_values(by=['Patient_Week'], ascending=True ).reset_index(drop=True )
df_train = pd.read_pickle(".. /input/elo-features-data-7-feb/train_df.pkl")
 df_test = pd.read_pickle(".. /input/elo-features-data-7-feb/test_df.pkl" )<define_variables>
df = df1[['Patient_Week']].copy()
df['FVC'] = 0.25*df1['FVC'] + 0.75*df2['FVC']
df['Confidence'] = 0.25*df1['Confidence'] + 0.75*df2['Confidence']
df.head()
<drop_column><EOS> 
df.to_csv('submission.csv', index=False )