Kaggle competition: 2018 Data Science Bowl
X_train = pd.DataFrame()
y_train = pd.Series()
for df in train:
ch = gen_features(df['acoustic_data'])
 X_train = X_train.append(ch, ignore_index=True)
 y_train = y_train.append(pd.Series(df['time_to_failure'].values[-1]))<define_variables>
import cv2
import pandas as pd
import numpy as np
from skimage.morphology import closing, square
from skimage.segmentation import clear_border
from skimage.measure import label, regionprops
from skimage.filters import threshold_otsu
from skimage import data
from skimage.color import label2rgb
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
train_pool = Pool(X_train, y_train )<train_model>
image_path = ".. /input/stage2_test_final/0a8dfb6763ec049b57454e6b5605f872cdf41cd13951fb2a2f31a6e3c8667712/images/0a8dfb6763ec049b57454e6b5605f872cdf41cd13951fb2a2f31a6e3c8667712.png"
m = CatBoostRegressor(iterations=10000, loss_function='MAE', boosting_type='Ordered')
 m.fit(X_train, y_train, silent=True)
 m.best_score_<load_from_csv>
image = cv2.imread(image_path)
 image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY )
submission = pd.read_csv('.. /input/sample_submission.csv', index_col='seg_id' )<create_dataframe>
thresh = threshold_otsu(image)
 if thresh:
bw = closing(image > thresh, square(3))
else:
ret, bw = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY )
X_test = pd.DataFrame()<load_from_csv>
def rle_encoding(x):

 dots = np.where(x.T.flatten() ==1)[0]
run_lengths = []
prev = -2
for b in dots:
if(b>prev+1): run_lengths.extend(( b+1, 0))
run_lengths[-1] += 1
prev = b
return run_lengths
for seg_id in submission.index:
seg = pd.read_csv('.. /input/test/' + seg_id + '.csv')
 ch = gen_features(seg['acoustic_data'])
 X_test = X_test.append(ch, ignore_index=True )<save_to_csv>
import glob
<set_options><EOS> 
df.to_csv("submission.csv", index=False )