Kaggle competition: New York City Taxi Trip Duration
<SOS> metric: RMSLE Kaggle data source: new-york-city-taxi-trip-duration<load_from_csv>
%matplotlib inline
warnings.filterwarnings("ignore" )
submission = pd.read_csv('.. /input/sample_submission.csv', index_col='seg_id')
 X_test = pd.DataFrame(columns=X_train.columns, dtype=np.float64, index=submission.index )<feature_engineering>
train = pd.read_csv('/kaggle/input/nyc-taxi-trip-duration/train.zip')
 test = pd.read_csv('/kaggle/input/nyc-taxi-trip-duration/test.zip')
 sample_submission = pd.read_csv('/kaggle/input/nyc-taxi-trip-duration/sample_submission.zip' )
for seg_id in tqdm(X_test.index):
seg = pd.read_csv('.. /input/test/' + seg_id + '.csv')
 x = seg['acoustic_data'].values
X_test.loc[seg_id, 'ave'] = x.mean()
X_test.loc[seg_id, 'std'] = x.std()
X_test.loc[seg_id, 'max'] = x.max()
X_test.loc[seg_id, 'min'] = x.min()
X_test.loc[seg_id, 'q95'] = np.quantile(x,0.95)
 X_test.loc[seg_id, 'q99'] = np.quantile(x,0.99)
 X_test.loc[seg_id, 'q05'] = np.quantile(x,0.05)
 X_test.loc[seg_id, 'q01'] = np.quantile(x,0.01)
 X_test.loc[seg_id, 'abs_max'] = np.abs(x ).max()
X_test.loc[seg_id, 'abs_mean'] = np.abs(x ).mean()
X_test.loc[seg_id, 'abs_std'] = np.abs(x ).std()
X_test.loc[seg_id, 'trend'] = add_trend_feature(x)
 X_test.loc[seg_id, 'abs_trend'] = add_trend_feature(x, abs_values=True )<define_variables>
train.isnull().sum()
f = [y_pred_nusvr,y_pred_SVR,y_pred_cat,y_pred_lgb,y_pred_Bayesian]<concatenate>
train.isnull().sum()
f = np.transpose(f )<create_dataframe>
from scipy import stats
from scipy.stats import norm
d = {'Model': ['nuSVR', 'SVR','Kernel Ridge','Lightgbm','Catboost','Stacking'], 'RMSE': [2.647,2.635,2.653,2.029,2.491,1.20],'F1_Score': [0.48,0.485,0.478,0.695,0.54,0.695]}
analysis_df = pd.DataFrame(d)
 analysis_df.index = analysis_df.Model
del analysis_df['Model']
display(analysis_df )<train_model>
train['trip_duration'] = np.log(train['trip_duration'].values )
sclf = StackingRegressor(regressors=[svm1,svm2,svm3,svm4,svm5,svm6],
meta_regressor=SVR())
 sclf.fit(X_train_scaled, y_train.values.flatten() )<predict_on_test>
feature_names=list(test)
 df_train=train[feature_names]
df=pd.concat(( df_train, test))
X_test_scaled = scaler.transform(X_test)
 submission['time_to_failure'] = sclf.predict(X_test_scaled)
<save_to_csv>
df['pickup_datetime'] = pd.to_datetime(df['pickup_datetime'] )
submission.to_csv("Advance_stack.csv" )<save_to_csv>
df['month'] = df['pickup_datetime'].dt.month
df['day'] = df['pickup_datetime'].dt.day
df['weekday'] = df['pickup_datetime'].dt.weekday
df['hour'] = df['pickup_datetime'].dt.hour
df['dayofweek'] = df['pickup_datetime'].dt.dayofweek
submission1 = pd.read_csv('.. /input/sample_submission.csv', index_col='seg_id')
 submission1['time_to_failure'] = svm5.predict(X_test_scaled)
 submission1.to_csv("submission_lgbbestmodel.csv" )<save_to_csv>
df.drop(['pickup_datetime'], axis=1, inplace=True )
submission1 = pd.read_csv('.. /input/sample_submission.csv', index_col='seg_id')
 submission1['time_to_failure'] = svm3.predict(X_test_scaled)
 submission1.to_csv("submission_svrbestmodel.csv" )<save_to_csv>
df['dist_long'] = df['pickup_longitude'] - df['dropoff_longitude']
df['dist_lat'] = df['pickup_latitude'] - df['dropoff_latitude']
submission1 = pd.read_csv('.. /input/sample_submission.csv', index_col='seg_id')
 submission1['time_to_failure'] = svm1.predict(X_test_scaled)
 submission1.to_csv("submission_nusvrbestmodel.csv" )<load_from_csv>
df['dist'] = np.sqrt(np.square(df['dist_long'])+ np.square(df['dist_lat']))
seed(639)
 set_random_seed(5944)
 float_data = pd.read_csv(".. /input/train.csv", nrows=300000, dtype={"acoustic_data": np.float32, "time_to_failure": np.float32} ).values
def extract_features(z):
return np.c_[z.mean(axis=1),
z.min(axis=1),
z.max(axis=1),
z.std(axis=1)]
def create_X_Y(x, last_index=None, n_steps=150, step_length=1000):
if last_index == None:
last_index=len(x)
 assert last_index - n_steps * step_length >= 0
chunk = x[(last_index - n_steps * step_length):last_index]
X =(chunk.T[0].reshape(n_steps, step_length)- 4.5)/ 10.7
Y = chunk.T[1].min()
return np.c_[extract_features(X),
extract_features(X[:, -step_length // 10:]),
extract_features(X[:, -step_length // 100:])],Y
def create_X(x, last_index=None, n_steps=150, step_length=1000):
if last_index == None:
last_index=len(x)
 assert last_index - n_steps * step_length >= 0
chunk = x[(last_index - n_steps * step_length):last_index]
X =(chunk.reshape(n_steps, step_length)- 4.5)/ 10.7
return np.c_[extract_features(X),
extract_features(X[:, -step_length // 10:]),
extract_features(X[:, -step_length // 100:])]<prepare_x_and_y>
def ft_haversine_distance(lat1, lng1, lat2, lng2):
lat1, lng1, lat2, lng2 = map(np.radians,(lat1, lng1, lat2, lng2))
AVG_EARTH_RADIUS = 6371
lat = lat2 - lat1
lng = lng2 - lng1
d = np.sin(lat * 0.5)** 2 + np.cos(lat1)* np.cos(lat2)* np.sin(lng * 0.5)** 2
h = 2 * AVG_EARTH_RADIUS * np.arcsin(np.sqrt(d))
return h
df['distance'] = ft_haversine_distance(df['pickup_latitude'].values,
df['pickup_longitude'].values,
df['dropoff_latitude'].values,
df['dropoff_longitude'].values )
features,targets = create_X_Y(float_data[0:150000])
 n_features = features.shape[1]
print("Our RNN is based on %i features"% n_features )<load_from_csv>
df = pd.concat([df, pd.get_dummies(df['store_and_fwd_flag'],prefix = 'store')], axis=1)
 df.drop(['store_and_fwd_flag'], axis=1, inplace=True)
 df = pd.concat([df, pd.get_dummies(df['vendor_id'],prefix = 'vendor')], axis=1)
 df.drop(['vendor_id'], axis=1, inplace=True )
n_train = 5000
float_data = pd.read_csv(".. /input/train.csv", nrows=n_train*150000, dtype={"acoustic_data": np.float32, "time_to_failure": np.float32} ).values 
<define_variables>
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.metrics import mean_squared_log_error
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor
from sklearn.linear_model import LinearRegression
def generator(data, min_index=0, max_index=None, batch_size=16, n_steps=150, step_length=1000):
if max_index is None:
max_index = len(data)- 1
while True:
rows = np.random.randint(min_index + n_steps * step_length, max_index, size=batch_size)
 samples = np.zeros(( batch_size, n_steps, n_features))
targets = np.zeros(batch_size,)
 for j, row in enumerate(rows):
samples[j],targets[j] = create_X_Y(data, last_index=row, n_steps=n_steps, step_length=step_length)
 yield samples, targets
batch_size = 64
second_earthquake = 50085877
tv_bd = 3800 * 150000
train_gen = generator(float_data, max_index = 4000 * 150000, batch_size=batch_size,n_steps=300,step_length=500)
 valid_gen = generator(float_data, min_index= 3800 * 150000,batch_size=batch_size,n_steps=300, step_length=500 )<choose_model_class>
df.drop(["id"], axis=1, inplace=True )
cb = [ModelCheckpoint("model.hdf5", save_best_only=True, period=3)]
model = Sequential()
model.add(CuDNNLSTM(64,return_sequences=True,input_shape=(None, n_features)))
 model.add(CuDNNGRU(48))
model.add(Dense(16,activation="relu"))
model.add(Dense(1))
model.summary()
model.compile(optimizer=RMSprop(lr=0.0005), loss="mae")
 history = model.fit_generator(train_gen,
steps_per_epoch=1000,
epochs=100,
verbose=2,
callbacks=cb,
validation_data=valid_gen,
validation_steps=200)
<install_modules>
new_train = df[:train.shape[0]]
new_test = df[train.shape[0]:]
!pip install -U pip
!pip install -q efficientnet<import_modules>
target = train['trip_duration']
import pandas as pd
import os, math
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
import efficientnet.tfkeras as efn
from kaggle_datasets import KaggleDatasets
import tensorflow.keras.backend as K
from tensorflow.keras.callbacks import LearningRateScheduler
from tensorflow.keras.models import load_model
from sklearn.model_selection import train_test_split<train_on_grid>
X_train, X_val, y_train, y_val = train_test_split(new_train, target, test_size=0.2, shuffle=True )
try:
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
print('Running on TPU ', tpu.master())
 except ValueError:
tpu = None
if tpu:
tf.config.experimental_connect_to_cluster(tpu)
 tf.tpu.experimental.initialize_tpu_system(tpu)
 strategy = tf.distribute.experimental.TPUStrategy(tpu)
 else:
strategy = tf.distribute.get_strategy()
print("REPLICAS: ", strategy.num_replicas_in_sync)
 GCS_DS_PATH = KaggleDatasets().get_gcs_path()
EPOCHS = 100
BATCH_SIZE = 16 * strategy.num_replicas_in_sync
AUG_BATCH = BATCH_SIZE
IMG_SIZE = 512
AUTO = tf.data.experimental.AUTOTUNE<define_variables>
def rmsle_score(preds, true):
rmsle_score =(np.sum(( np.log1p(preds)-np.log1p(true)) **2)/len(true)) **0.5
return rmsle_score
def seed_everything(seed=0):
np.random.seed(seed)
 tf.random.set_seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 os.environ['TF_DETERMINISTIC_OPS'] = '1'
def format_path(s):
return GCS_DS_PATH + "/images/" +s+ ".jpg"
seed_everything(2048 )<load_from_csv>
RMSLE = make_scorer(rmsle_score )
train_csv = pd.read_csv('.. /input/plant-pathology-2020-fgvc7/train.csv')
 test_csv = pd.read_csv('.. /input/plant-pathology-2020-fgvc7/test.csv')
 submission_csv = pd.read_csv('.. /input/plant-pathology-2020-fgvc7/sample_submission.csv')
 train_paths = train_csv.image_id.apply(format_path ).values
test_paths = test_csv.image_id.apply(format_path ).values
train_labels = train_csv.loc[:, 'healthy':].values
train_paths, valid_paths, train_labels, valid_labels = train_test_split(
 train_paths, train_labels, test_size=0.15, random_state=2048 )<normalization>
import statsmodels.api as sm
def get_mat(rotation, shear, height_zoom, width_zoom, height_shift, width_shift):
rotation = math.pi * rotation / 180.
 shear = math.pi * shear / 180.
 c1 = tf.math.cos(rotation)
 s1 = tf.math.sin(rotation)
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 rotation_matrix = tf.reshape(tf.concat([c1,s1,zero, -s1,c1,zero, zero,zero,one],axis=0),[3,3])
 c2 = tf.math.cos(shear)
 s2 = tf.math.sin(shear)
 shear_matrix = tf.reshape(tf.concat([one,s2,zero, zero,c2,zero, zero,zero,one],axis=0),[3,3])
 zoom_matrix = tf.reshape(tf.concat([one/height_zoom,zero,zero, zero,one/width_zoom,zero, zero,zero,one],axis=0),[3,3])
 shift_matrix = tf.reshape(tf.concat([one,zero,height_shift, zero,one,width_shift, zero,zero,one],axis=0),[3,3])
 return K.dot(K.dot(rotation_matrix, shear_matrix), K.dot(zoom_matrix, shift_matrix))
def transform2(image, label, DIM = 512):
XDIM = DIM % 2
rot = 15.* tf.random.normal([1],dtype='float32')
 shr = 5.* tf.random.normal([1],dtype='float32')
 h_zoom = 1.0 + tf.random.normal([1],dtype='float32')/10.
 w_zoom = 1.0 + tf.random.normal([1],dtype='float32')/10.
 h_shift = 16.* tf.random.normal([1],dtype='float32')
 w_shift = 16.* tf.random.normal([1],dtype='float32')
 m = get_mat(rot,shr,h_zoom,w_zoom,h_shift,w_shift)
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(m,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image,tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3]),label
def cutmix(image, label, PROBABILITY = 1.0, DIM = None):
CLASSES = 4
imgs = []; labs = []
for j in range(AUG_BATCH):
P = tf.cast(tf.random.uniform([],0,1)<=PROBABILITY, tf.int32)
 k = tf.cast(tf.random.uniform([],0,AUG_BATCH),tf.int32)
 x = tf.cast(tf.random.uniform([],0,DIM),tf.int32)
 y = tf.cast(tf.random.uniform([],0,DIM),tf.int32)
 b = tf.random.uniform([],0,1)
 WIDTH = tf.cast(DIM * tf.math.sqrt(1-b),tf.int32)* P
ya = tf.math.maximum(0,y-WIDTH//2)
 yb = tf.math.minimum(DIM,y+WIDTH//2)
 xa = tf.math.maximum(0,x-WIDTH//2)
 xb = tf.math.minimum(DIM,x+WIDTH//2)
 one = image[j,ya:yb,0:xa,:]
two = image[k,ya:yb,xa:xb,:]
three = image[j,ya:yb,xb:DIM,:]
middle = tf.concat([one,two,three],axis=1)
 img = tf.concat([image[j,0:ya,:,:],middle,image[j,yb:DIM,:,:]],axis=0)
 imgs.append(img)
 a = tf.cast(WIDTH*WIDTH/DIM/DIM,tf.float32)
 if len(label.shape)==1:
lab1 = tf.one_hot(label[j],CLASSES)
 lab2 = tf.one_hot(label[k],CLASSES)
 else:
lab1 = label[j,]
lab2 = label[k,]
labs.append(( 1-a)*lab1 + a*lab2)
 image2 = tf.reshape(tf.stack(imgs),(AUG_BATCH,DIM,DIM,3))
label2 = tf.reshape(tf.stack(labs),(AUG_BATCH,CLASSES))
return image2,label2
def mixup(image, label, PROBABILITY = 1.0, DIM=None):
CLASSES = 4
imgs = []; labs = []
for j in range(AUG_BATCH):
P = tf.cast(tf.random.uniform([],0,1)<=PROBABILITY, tf.float32)
 k = tf.cast(tf.random.uniform([],0,AUG_BATCH),tf.int32)
 a = tf.random.uniform([],0,1)*P
img1 = image[j,]
img2 = image[k,]
imgs.append(( 1-a)*img1 + a*img2)
 if len(label.shape)==1:
lab1 = tf.one_hot(label[j],CLASSES)
 lab2 = tf.one_hot(label[k],CLASSES)
 else:
lab1 = label[j,]
lab2 = label[k,]
labs.append(( 1-a)*lab1 + a*lab2)
 image2 = tf.reshape(tf.stack(imgs),(AUG_BATCH,DIM,DIM,3))
label2 = tf.reshape(tf.stack(labs),(AUG_BATCH,CLASSES))
return image2,label2
def transform(image,label, DIM=None):
CLASSES = 4
SWITCH = 0.5
CUTMIX_PROB = 0.666
MIXUP_PROB = 0.666
image2, label2 = cutmix(image, label, CUTMIX_PROB, DIM)
 image3, label3 = mixup(image, label, MIXUP_PROB, DIM)
 imgs = []; labs = []
for j in range(AUG_BATCH):
P = tf.cast(tf.random.uniform([],0,1)<=SWITCH, tf.float32)
 imgs.append(P*image2[j,]+(1-P)*image3[j,])
 labs.append(P*label2[j,]+(1-P)*label3[j,])
 image4 = tf.reshape(tf.stack(imgs),(AUG_BATCH,DIM,DIM,3))
label4 = tf.reshape(tf.stack(labs),(AUG_BATCH,CLASSES))
return image4,label4<normalization>
model = sm.OLS(target.values, new_train.astype(float))
def decode_image(filename, label=None, image_size=(512, 512)) :
bits = tf.io.read_file(filename)
 image = tf.image.decode_jpeg(bits, channels=3)
 image = tf.cast(image, tf.float32)/ 255.0
image = tf.image.resize(image, image_size)
 if label is None:
return image
else:
return image, label
def data_augment(image, label=None, image_size=(512, 512), seed=2048):
image = tf.image.random_flip_left_right(image,seed=seed)
 image = tf.image.random_flip_up_down(image,seed=seed)
 image = tf.image.random_brightness(image, 0.1, seed=seed)
 image = tf.image.random_hue(image, 0.01)
 image = tf.image.random_saturation(image, 0.7, 1.3)
 image = tf.image.random_contrast(image, 0.8, 1.2)
 image = tf.image.random_brightness(image, 0.1)
 image = tf.image.random_saturation(image, 0, 2)
 if label is None:
return image
else:
return image, label
def load_dataset(train_paths, ordered=False):
ignore_order = tf.data.Options()
if not ordered:
ignore_order.experimental_deterministic = False
return(
 tf.data.Dataset 
.from_tensor_slices(( train_paths, train_labels)) 
.map(decode_image, num_parallel_calls=AUTO)
.with_options(ignore_order)
)
 def get_training_dataset(IMG_SIZE=512, do_aug=True, cutmixup=True, mataug=True):
dataset = load_dataset(train_paths)
 if do_aug:
dataset = dataset.map(data_augment, num_parallel_calls=AUTO)
 if mataug:
dataset = dataset.map(transform2, num_parallel_calls=AUTO)
 dataset = dataset.repeat()
if cutmixup:
dataset = dataset.batch(AUG_BATCH)
 dataset = dataset.map(lambda image, label: transform(image, tf.cast(label, tf.float32), DIM=IMG_SIZE), num_parallel_calls=AUTO)
 dataset = dataset.unbatch()
dataset = dataset.shuffle(2048)
 dataset = dataset.batch(BATCH_SIZE)
 dataset = dataset.prefetch(AUTO)
 return dataset<categorify>
re = model.fit()
re.summary()
valid_dataset =(
 tf.data.Dataset 
.from_tensor_slices(( valid_paths, valid_labels)) 
.map(decode_image, num_parallel_calls=AUTO)
.cache() 
.shuffle(2048)
.batch(BATCH_SIZE)
.prefetch(AUTO)
)
 test_dataset =(
 tf.data.Dataset 
.from_tensor_slices(test_paths)
.map(decode_image, num_parallel_calls=AUTO)
.batch(BATCH_SIZE)
 )<choose_model_class>
import lightgbm as lgbm
with strategy.scope() :
model = tf.keras.Sequential([
efn.EfficientNetB5(include_top=False, weights='noisy-student', input_shape=[512, 512, 3]),
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(1000, use_bias=True, activation='relu'),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Dense(train_labels.shape[1], activation='softmax')
 ])
 def custom_loss(x, y):
return tf.keras.losses.categorical_crossentropy(x, y, from_logits=False, label_smoothing=0.1)
 model.compile(optimizer='Adam',
loss=custom_loss,
metrics=['categorical_accuracy']
)<init_hyperparams>
lgb_params = {
'metric' : 'rmse',
'learning_rate': 0.1,
'max_depth': 25,
'num_leaves': 1000,
'objective': 'regression',
'feature_fraction': 0.9,
'bagging_fraction': 0.5,
'max_bin': 1000 }
LR_START = 0.00001
LR_MAX = 0.00005 * strategy.num_replicas_in_sync
LR_MIN = 0.00001
LR_RAMPUP_EPOCHS = 5
LR_SUSTAIN_EPOCHS = 0
LR_EXP_DECAY =.7
def lrfn(epoch):
if epoch < LR_RAMPUP_EPOCHS:
lr =(LR_MAX - LR_START)/ LR_RAMPUP_EPOCHS * epoch + LR_START
elif epoch < LR_RAMPUP_EPOCHS + LR_SUSTAIN_EPOCHS:
lr = LR_MAX
else:
lr =(LR_MAX - LR_MIN)* LR_EXP_DECAY**(epoch - LR_RAMPUP_EPOCHS - LR_SUSTAIN_EPOCHS)+ LR_MIN
return lr
lr_callback = tf.keras.callbacks.LearningRateScheduler(lrfn, verbose=True)
 rng = [i for i in range(EPOCHS)]
y = [lrfn(x)for x in rng]
plt.plot(rng, y)
 print("Learning rate schedule: {:.3g} to {:.3g} to {:.3g}".format(y[0], max(y), y[-1]))<train_model>
lgb_df = lgbm.Dataset(new_train,target )
STEPS_PER_EPOCH = train_labels.shape[0] // BATCH_SIZE
Checkpoint=tf.keras.callbacks.ModelCheckpoint(f"Effnet_best.h5", verbose=1, mode='min', save_best_only=True, monitor='val_loss', save_weights_only=True)
 history = model.fit(get_training_dataset(IMG_SIZE),
epochs=EPOCHS,
validation_data=valid_dataset,
steps_per_epoch = STEPS_PER_EPOCH,
callbacks=[Checkpoint] )<save_to_csv>
lgb_model = lgbm.train(lgb_params, lgb_df, num_boost_round=1500 )
probs = model.predict(test_dataset, verbose=1)
 submission_csv.loc[:, 'healthy':] = probs
submission_csv.to_csv('submission.csv', index=False)
 submission_csv.head()<save_to_csv>
pred = lgb_model.predict(new_test )
model.load_weights(f"./Effnet_best.h5")
 probs = model.predict(test_dataset, verbose=1)
 submission_csv.loc[:, 'healthy':] = probs
submission_csv.to_csv('submission1.csv', index=False)
 submission_csv.head()<import_modules>
pred_lgb = np.exp(pred )
import pandas as pd<import_modules>
import xgboost as xgb
import pandas as pd<load_from_csv>
params = {
'booster': 'gbtree',
'objective': 'reg:linear',
'learning_rate': 0.1,
'max_depth': 14,
'subsample': 0.8,
'colsample_bytree': 0.7,
'colsample_bylevel': 0.7,
'silent': 1
}
sub1 = pd.read_csv(
 '.. /input\
/classification-densenet201-efficientnetb7\
/submission.csv' 
)
 sub2 = pd.read_csv(
 '.. /input\
/tf-zoo-models-on-tpu\
/submission.csv' 
)
 sub3 = pd.read_csv(
 '.. /input\
/fork-of-plant-2020-tpu-915e9c\
/submission.csv' 
)
 sub4 = pd.read_csv('.. /input/previous-sub/submission.csv')
<load_from_csv>
dtrain = xgb.DMatrix(new_train, target )
sub = pd.read_csv(
 '.. /input\
/plant-pathology-2020-fgvc7\
/sample_submission.csv'
)<feature_engineering>
gbm = xgb.train(params,
dtrain,
num_boost_round = 200 )
sub.healthy = sub1.healthy*0.10 \
+ sub2.healthy*0.30 \
+ sub3.healthy*0.60<feature_engineering>
pred_test = np.exp(gbm.predict(xgb.DMatrix(new_test)) )
sub.multiple_diseases = sub1.multiple_diseases * 0.10 \
+ sub2.multiple_diseases * 0.30 \
+ sub3.multiple_diseases * 0.60<feature_engineering>
sub = pd.DataFrame()
sub['id'] = test.id
sub['trip_duration'] = ensemble
sub.head(3 )
sub.rust = sub1.rust*0.10 \
+ sub2.rust*0.30 \
+ sub3.rust*0.60<save_to_csv>
sub = pd.DataFrame()
sub['id'] = test.id
sub['trip_duration'] = ensemble
sub.head(3 )
sub.to_csv('submission.csv', index=False )<save_to_csv>
sub.to_csv('submission.csv', index=False )
<import_modules><EOS> 
sub.to_csv('submission.csv', index=False )