Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<predict_on_test>
warnings.filterwarnings('ignore' )
def predict_on_video(video_path, batch_size):
try:
faces = face_extractor.process_video(video_path)
 face_extractor.keep_only_best_face(faces)
 if len(faces)> 0:
x = np.zeros(( batch_size, input_size, input_size, 3), dtype=np.uint8)
 n = 0
for frame_data in faces:
for face in frame_data["faces"]:
resized_face = isotropically_resize_image(face, input_size)
 resized_face = make_square_image(resized_face)
 if n < batch_size:
x[n] = resized_face
n += 1
else:
print("WARNING: have %d faces but batch size is %d" %(n, batch_size))
if n > 0:
x = torch.tensor(x, device=gpu ).float()
x = x.permute(( 0, 3, 1, 2))
for i in range(len(x)) :
x[i] = normalize_transform(x[i] / 255.)
with torch.no_grad() :
y_pred = model(x)
 y_pred = torch.sigmoid(y_pred.squeeze())
 return y_pred[:n].mean().item()
except Exception as e:
print("Prediction error on video %s: %s" %(video_path, str(e)))
 return 0.5<predict_on_test>
def seed_everything(seed=0):
random.seed(seed)
 np.random.seed(seed )
def predict_on_video_set(videos, num_workers):
def process_file(i):
filename = videos[i]
y_pred = predict_on_video(os.path.join(test_dir, filename), batch_size=frames_per_video)
 return y_pred
with ThreadPoolExecutor(max_workers=num_workers)as ex:
predictions = ex.map(process_file, range(len(videos)))
 return list(predictions )<define_variables>
SEED = 42
seed_everything(SEED)
 TARGET = 'isFraud'
START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d' )
speed_test = False<predict_on_test>
lgb_params = {
'objective':'binary',
'boosting_type':'gbdt',
'metric':'auc',
'n_jobs':-1,
'learning_rate':0.01,
'num_leaves': 2**8,
'max_depth':-1,
'tree_learner':'serial',
'colsample_bytree': 0.8,
'subsample_freq':1,
'subsample':0.7,
'n_estimators':22000,
'max_bin':384,
'verbose':-1,
'seed': SEED,
'early_stopping_rounds':110,
}
if speed_test:
start_time = time.time()
speedtest_videos = test_videos[:5]
predictions = predict_on_video_set(speedtest_videos, num_workers=4)
 elapsed = time.time() - start_time
print("Elapsed %f sec.Average per video: %f sec." %(elapsed, elapsed / len(speedtest_videos)) )<predict_on_test>
print('Load Data')
 train_df = pd.read_pickle('.. /input/ieee-data-minification/train_transaction.pkl')
 train_df['DT_M'] = train_df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 train_df['DT_M'] =(train_df['DT_M'].dt.year-2017)*12 + train_df['DT_M'].dt.month
test_df = train_df[train_df['DT_M']==train_df['DT_M'].max() ].reset_index(drop=True)
 train_df = train_df[train_df['DT_M']<(train_df['DT_M'].max())].reset_index(drop=True)
 print('Shape control:', train_df.shape, test_df.shape )
predictions = predict_on_video_set(test_videos, num_workers=4 )<save_to_csv>
for col in list(train_df):
if train_df[col].dtype=='O':
print(col)
 train_df[col] = train_df[col].fillna('unseen_before_label')
 test_df[col] = test_df[col].fillna('unseen_before_label')
 train_df[col] = train_df[col].astype(str)
 test_df[col] = test_df[col].astype(str)
 le = LabelEncoder()
le.fit(list(train_df[col])+list(test_df[col]))
train_df[col] = le.transform(train_df[col])
 test_df[col] = le.transform(test_df[col])
 train_df[col] = train_df[col].astype('category')
 test_df[col] = test_df[col].astype('category' )
submission_df = pd.DataFrame({"filename": test_videos, "label": predictions})
 submission_df.to_csv("submission.csv", index=False )<install_modules>
rm_cols = [
'TransactionID','TransactionDT',
TARGET,
'DT_M'
]
rm_cols += ['V'+str(i)for i in range(1,340)]
features_columns = [col for col in list(train_df)if col not in rm_cols]
!pip install /kaggle/input/dfdcpackages/dlib-19.19.0-cp36-cp36m-linux_x86_64.whl<define_variables>
RESULTS = test_df[['TransactionID',TARGET]]
N_SPLITS = 4
DATA_PREFIX = '/kaggle/input'
SKIP_FRAMES = 75
detector = dlib.cnn_face_detection_model_v1(os.path.join(DATA_PREFIX, 'dfdcpackages', 'mmod_human_face_detector.dat'))
sp = dlib.shape_predictor(os.path.join(DATA_PREFIX, 'dfdcpackages', 'shape_predictor_5_face_landmarks.dat'))
predictor = dlib.deep_fake_detection_model_v1(os.path.join(DATA_PREFIX, 'dfdcpackages', 'deepfake_detector.dnn'))
def align_face(frame, detection_sp):
x_center = int(( detection_sp.part(0 ).x + detection_sp.part(2 ).x + detection_sp.part(4 ).x)/ 3)
 y_center = int(( detection_sp.part(4 ).y + detection_sp.part(0 ).y + detection_sp.part(2 ).y)/ 3)
 w = 2 * abs(detection_sp.part(0 ).x - detection_sp.part(2 ).x)
 h = w
shape = frame.shape
face_crop = frame[
max(int(y_center - h), 0):min(int(y_center + h), shape[0]),
max(int(x_center - w), 0):min(int(x_center + w), shape[1])
 ]
return cv2.resize(face_crop,(150,150))
def align_face_dlib(frame, detection_sp):
detections = dlib.full_object_detections()
detections.append(detection_sp)
 return dlib.get_face_chips(frame, detections, size=150)[0]
def predict_fake(face):

 return predictor.predict(face)[0]
def process_frame(frame):
labels = []
dets = detector(frame, 1)
 batch_faces = dlib.full_object_detections()
for k,d in enumerate(dets):
face = align_face_dlib(frame, sp(frame, d.rect))
labels.append(predict_fake(face))
return labels
def process_video(video_filename):

 frame_labels = []
frames = []
cap = cv2.VideoCapture(video_filename)
 frame_count = 0
while cap.isOpened() :
ret = cap.grab()
frame_count += 1
if not ret:
break
if frame_count % SKIP_FRAMES:
continue
_, frame = cap.retrieve()
frame_labels.extend(process_frame(frame))
cap.release()
fakeness = statistics.mean(frame_labels)
 fakeness = 0.1 + fakeness * 0.8
return fakeness
def single_log_loss(prediction, groundtruth):
return groundtruth * math.log(prediction)+(1-groundtruth)* math.log(1-prediction)
 def estimate_loss(predictions, all_correct=True):
result = 0
for p in predictions:
if all_correct:
result += single_log_loss(p, 1 if p > 0.5 else 0)
 else:
result += single_log_loss(p, 0 if p > 0.5 else 1)
 return -result/len(predictions)
 predictions = []
filenames = glob.glob(os.path.join(DATA_PREFIX, 'deepfake-detection-challenge/test_videos/*.mp4'))
sub = pd.read_csv(os.path.join(DATA_PREFIX, 'deepfake-detection-challenge/sample_submission.csv'))
sub = sub.set_index('filename', drop=False)
 print('Initialize submission')
 for filename in tqdm.tqdm(filenames):
fn = filename.split('/')[-1]
sub.loc[fn, 'label'] = 0.5
print('CUDA usage: {}'.format(dlib.DLIB_USE_CUDA))
for filename in tqdm.tqdm(filenames):
fn = filename.split('/')[-1]
sub.loc[fn, 'label'] = 0.5
try:
start = timer()
prediction = process_video(filename)
 sub.loc[fn, 'label'] = prediction
sub.to_csv('submission.csv', index=False)
 predictions.append(prediction)
 print('Processed video {}, label={}, time={}'.format(filename, prediction, timedelta(seconds=timer() -start)))
 print('Possible lost: best={}, worse={}'.format(estimate_loss(predictions), estimate_loss(predictions, False)))
 except Exception as error:
print('Failed to process {}'.format(filename))
sub.to_csv('submission.csv', index=False )<import_modules>
X,y = train_df[features_columns], train_df[TARGET]
P = test_df[features_columns]
for n_rounds in [1000,2500,5000, 10000]:
print('
print('No Validation training...', n_rounds, 'boosting rounds')
 corrected_lgb_params = lgb_params.copy()
corrected_lgb_params['n_estimators'] = n_rounds
corrected_lgb_params['early_stopping_rounds'] = None
train_data = lgb.Dataset(X, label=y)
 estimator = lgb.train(
 corrected_lgb_params,
train_data 
)
 RESULTS['no_validation_'+str(n_rounds)] = estimator.predict(P)
 print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['no_validation_'+str(n_rounds)]))
print('
import numpy as np
import pandas as pd
import os 
<load_from_csv>
print('
print('KFold training...')
 folds = KFold(n_splits=N_SPLITS, shuffle=True, random_state=SEED)
 X,y = train_df[features_columns], train_df[TARGET]
P = test_df[features_columns]
RESULTS['kfold'] = 0
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y)) :
print('Fold:',fold_+1)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, v_y = X.iloc[val_idx,:], y[val_idx]
train_data = lgb.Dataset(tr_x, label=tr_y)
 valid_data = lgb.Dataset(vl_x, label=v_y)
 estimator = lgb.train(
 lgb_params,
train_data,
valid_sets = [train_data, valid_data],
verbose_eval = 1000, 
)
 RESULTS['kfold'] = estimator.predict(P)
 print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['kfold']))
print('
tourney_cresults = pd.read_csv('.. /input/stage2datafiles/NCAATourneyCompactResults.csv')
 tourney_cresults = tourney_cresults.loc[tourney_cresults['Season'] >= 2003]
training_set = pd.DataFrame()
training_set['Result'] = np.random.randint(0,2,len(tourney_cresults.index))
training_set['Season'] = tourney_cresults['Season'].values
training_set['Team1'] = training_set['Result'].values * tourney_cresults['WTeamID'].values +(1-training_set['Result'].values)* tourney_cresults['LTeamID'].values
training_set['Team2'] =(1-training_set['Result'].values)* tourney_cresults['WTeamID'].values + training_set['Result'].values * tourney_cresults['LTeamID'].values 
<load_from_csv>
print('
print('StratifiedKFold training...')
 folds = StratifiedKFold(n_splits=N_SPLITS, shuffle=True, random_state=SEED)
 X,y = train_df[features_columns], train_df[TARGET]
P = test_df[features_columns]
RESULTS['stratifiedkfold'] = 0
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y, groups=y)) :
print('Fold:',fold_+1)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, v_y = X.iloc[val_idx,:], y[val_idx]
train_data = lgb.Dataset(tr_x, label=tr_y)
 valid_data = lgb.Dataset(vl_x, label=v_y)
 estimator = lgb.train(
 lgb_params,
train_data,
valid_sets = [train_data, valid_data],
verbose_eval = 1000, 
)
 RESULTS['stratifiedkfold'] += estimator.predict(P)/N_SPLITS
print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['stratifiedkfold']))
print('
seeds = pd.read_csv('.. /input/stage2datafiles/NCAATourneySeeds.csv')
 seeds['Seed'] = pd.to_numeric(seeds['Seed'].str[1:3], downcast='integer',errors='coerce')
 def delta_seed(row):
cond =(seeds['Season'] == row['Season'])
 return seeds[cond &(seeds['TeamID'] == row['Team1'])]['Seed'].iloc[0] - seeds[cond &(seeds['TeamID'] == row['Team2'])]['Seed'].iloc[0]
training_set['deltaSeed'] = training_set.apply(delta_seed,axis=1 )<load_from_csv>
print('
print('LBO training...')
 train_df['DT_M'] = train_df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 train_df['DT_M'] =(train_df['DT_M'].dt.year-2017)*12 + train_df['DT_M'].dt.month
main_train_set = train_df[train_df['DT_M']<(train_df['DT_M'].max())].reset_index(drop=True)
 validation_set = train_df[train_df['DT_M']==train_df['DT_M'].max() ].reset_index(drop=True)
 folds = KFold(n_splits=N_SPLITS, shuffle=True, random_state=SEED)
 X,y = main_train_set[features_columns], main_train_set[TARGET]
v_X, v_y = validation_set[features_columns], validation_set[TARGET]
estimators_bestround = []
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y)) :
print('Fold:',fold_+1)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
train_data = lgb.Dataset(tr_x, label=tr_y)
 valid_data = lgb.Dataset(v_X, label=v_y)
 estimator = lgb.train(
 lgb_params,
train_data,
valid_sets = [train_data, valid_data],
verbose_eval = 1000, 
)
 estimators_bestround.append(estimator.current_iteration())
 corrected_lgb_params = lgb_params.copy()
corrected_lgb_params['n_estimators'] = int(np.mean(estimators_bestround))
corrected_lgb_params['early_stopping_rounds'] = None
print('
print('Mean Best round:', corrected_lgb_params['n_estimators'])
 X,y = train_df[features_columns], train_df[TARGET]
P = test_df[features_columns]
RESULTS['lbo'] = 0
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y)) :
print('Fold:',fold_+1)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
train_data = lgb.Dataset(tr_x, label=tr_y)
 estimator = lgb.train(
 corrected_lgb_params,
train_data 
)
 RESULTS['lbo'] += estimator.predict(P)/N_SPLITS
print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['lbo']))
print('
mo = pd.read_csv('.. /input/masseyordinals_thru_2019_day_128/MasseyOrdinals_thru_2019_day_128.csv')
 mo = mo[(mo['RankingDayNum'] == 128)&(mo['Season'] >= 2003)]
def delta_ord(row):
cond =(mo['Season'] == row['Season'])
 cond1 =(mo['TeamID'] == row['Team1'])& cond
cond2 =(mo['TeamID'] == row['Team2'])& cond
t1 = mo[cond1]['OrdinalRank'].mean()
t2 = mo[cond2]['OrdinalRank'].mean()
return t1-t2
training_set['deltaMO'] = training_set.apply(delta_ord,axis=1)
<load_from_csv>
print('
print('GroupKFold timeblocks split training...')
 folds = GroupKFold(n_splits=N_SPLITS)
 train_df['groups'] = train_df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 train_df['groups'] =(train_df['groups'].dt.year-2017)*12 + train_df['groups'].dt.month
X,y = train_df[features_columns], train_df[TARGET]
split_groups = train_df['groups']
P = test_df[features_columns]
RESULTS['groupkfold_timeblocks'] = 0
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y, groups=split_groups)) :
print('Fold:',fold_+1)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, v_y = X.iloc[val_idx,:], y[val_idx]
train_data = lgb.Dataset(tr_x, label=tr_y)
 valid_data = lgb.Dataset(vl_x, label=v_y)
 estimator = lgb.train(
 lgb_params,
train_data,
valid_sets = [train_data, valid_data],
verbose_eval = 1000, 
)
 RESULTS['groupkfold_timeblocks'] += estimator.predict(P)/N_SPLITS
print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['groupkfold_timeblocks']))
print('
season_dresults = pd.read_csv('.. /input/stage2datafiles/RegularSeasonDetailedResults.csv')
 record = pd.DataFrame({'wins': season_dresults.groupby(['Season','WTeamID'] ).size() } ).reset_index() ;
losses = pd.DataFrame({'losses': season_dresults.groupby(['Season','LTeamID'] ).size() } ).reset_index() ;
record = record.merge(losses, how='outer', left_on=['Season','WTeamID'], right_on=['Season','LTeamID'])
 record = record.fillna(0)
 record['games'] = record['wins'] + record['losses']
def delta_winPct(row):
cond1 =(record['Season'] == row['Season'])&(record['WTeamID'] == row['Team1'])
 cond2 =(record['Season'] == row['Season'])&(record['WTeamID'] == row['Team2'])
 return(record[cond1]['wins']/record[cond1]['games'] ).mean() -(record[cond2]['wins']/record[cond2]['games'] ).mean()
training_set['deltaWinPct'] = training_set.apply(delta_winPct,axis=1)
<groupby>
print('
print('GroupKFold uID split training...')
 folds = GroupKFold(n_splits=N_SPLITS)
 train_df['groups'] = ''
for col in ['card1','card2','card3','card5','addr1','addr2',]:
train_df['groups'] = '_' + train_df[col].astype(str)
 X,y = train_df[features_columns], train_df[TARGET]
split_groups = train_df['groups']
P = test_df[features_columns]
RESULTS['groupkfold_uid'] = 0
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y, groups=split_groups)) :
print('Fold:',fold_+1)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, v_y = X.iloc[val_idx,:], y[val_idx]
train_data = lgb.Dataset(tr_x, label=tr_y)
 valid_data = lgb.Dataset(vl_x, label=v_y)
 estimator = lgb.train(
 lgb_params,
train_data,
valid_sets = [train_data, valid_data],
verbose_eval = 1000, 
)
 RESULTS['groupkfold_uid'] += estimator.predict(P)/N_SPLITS
print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['groupkfold_uid']))
print('
dfW = season_dresults.groupby(['Season','WTeamID'] ).sum().reset_index()
dfL = season_dresults.groupby(['Season','LTeamID'] ).sum().reset_index()
def get_points_for(row):
wcond =(dfW['Season'] == row['Season'])&(dfW['WTeamID'] == row['WTeamID'])
 fld1 = 'WScore'
lcond =(dfL['Season'] == row['Season'])&(dfL['LTeamID'] == row['WTeamID'])
 fld2 = 'LScore'
retVal = dfW[wcond][fld1].sum()
if len(dfL[lcond][fld2])> 0:
retVal = retVal + dfL[lcond][fld2].sum()
return retVal
def get_points_against(row):
wcond =(dfW['Season'] == row['Season'])&(dfW['WTeamID'] == row['WTeamID'])
 fld1 = 'LScore'
lcond =(dfL['Season'] == row['Season'])&(dfL['LTeamID'] == row['WTeamID'])
 fld2 = 'WScore'
retVal = dfW[wcond][fld1].sum()
if len(dfL[lcond][fld2])> 0:
retVal = retVal + dfL[lcond][fld2].sum()
return retVal
record['PointsFor'] = record.apply(get_points_for, axis=1)
 record['PointsAgainst'] = record.apply(get_points_against, axis=1 )<feature_engineering>
print('
print('Intermediate results...')
 final_df = []
for current_strategy in list(RESULTS.iloc[:,2:]):
auc_score = metrics.roc_auc_score(RESULTS[TARGET], RESULTS[current_strategy])
 final_df.append([current_strategy, auc_score])
 final_df = pd.DataFrame(final_df, columns=['Stategy', 'Result'])
 final_df.sort_values(by=['Result'], ascending=False, inplace=True)
 print(final_df )
def get_remaining_stats(row, field):
wcond =(dfW['Season'] == row['Season'])&(dfW['WTeamID'] == row['WTeamID'])
 fld1 = 'W' + field
lcond =(dfL['Season'] == row['Season'])&(dfL['LTeamID'] == row['WTeamID'])
 fld2 = 'L'+ field
retVal = dfW[wcond][fld1].sum()
if len(dfL[lcond][fld2])> 0:
retVal = retVal + dfL[lcond][fld2].sum()
return retVal
cols = ['FGM','FGA','FGM3','FGA3','FTM','FTA','OR','DR','Ast','TO','Stl','Blk','PF']
for col in cols:
print("Processing",col)
 record[col] = record.apply(get_remaining_stats, args=(col,), axis=1)
<feature_engineering>
print('
print('LBO full set training...')
 train_df['DT_M'] = train_df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 train_df['DT_M'] =(train_df['DT_M'].dt.year-2017)*12 + train_df['DT_M'].dt.month
main_train_set = train_df[train_df['DT_M']<(train_df['DT_M'].max())].reset_index(drop=True)
 validation_set = train_df[train_df['DT_M']==train_df['DT_M'].max() ].reset_index(drop=True)
 X,y = main_train_set[features_columns], main_train_set[TARGET]
v_X, v_y = validation_set[features_columns], validation_set[TARGET]
estimators_bestround = []
for current_model in range(3):
print('Model:',current_model+1)
 SEED += 1
seed_everything(SEED)
 corrected_lgb_params = lgb_params.copy()
corrected_lgb_params['seed'] = SEED
train_data = lgb.Dataset(X, label=y)
 valid_data = lgb.Dataset(v_X, label=v_y)
 estimator = lgb.train(
 corrected_lgb_params,
train_data,
valid_sets = [train_data, valid_data],
verbose_eval = 1000, 
)
 estimators_bestround.append(estimator.current_iteration())
 corrected_lgb_params = lgb_params.copy()
corrected_lgb_params['n_estimators'] = int(np.mean(estimators_bestround))
corrected_lgb_params['early_stopping_rounds'] = None
print('
print('Mean Best round:', corrected_lgb_params['n_estimators'])
 X,y = train_df[features_columns], train_df[TARGET]
P = test_df[features_columns]
RESULTS['lbo_full'] = 0
NUMBER_OF_MODELS = 3
for current_model in range(NUMBER_OF_MODELS):
print('Model:',current_model+1)
 SEED += 1
seed_everything(SEED)
 train_data = lgb.Dataset(X, label=y)
 estimator = lgb.train(
 corrected_lgb_params,
train_data 
)
 RESULTS['lbo_full'] += estimator.predict(P)/NUMBER_OF_MODELS
print('AUC score', metrics.roc_auc_score(RESULTS[TARGET], RESULTS['lbo_full']))
print('
def delta_stat(row, field):
cond1 =(record['Season'] == row['Season'])&(record['WTeamID'] == row['Team1'])
 cond2 =(record['Season'] == row['Season'])&(record['WTeamID'] == row['Team2'])
 return(record[cond1][field]/record[cond1]['games'] ).mean() -(record[cond2][field]/record[cond2]['games'] ).mean()
cols = ['PointsFor','PointsAgainst','FGM','FGA','FGM3','FGA3','FTM','FTA','OR','DR','Ast','TO','Stl','Blk','PF']
for col in cols:
print("Processing",col)
 training_set['delta' + col] = training_set.apply(delta_stat,args=(col,),axis=1)
 training_set.describe() 
<import_modules>
print('
print('Intermediate results...')
 final_df = []
for current_strategy in list(RESULTS.iloc[:,2:]):
auc_score = metrics.roc_auc_score(RESULTS[TARGET], RESULTS[current_strategy])
 final_df.append([current_strategy, auc_score])
 final_df = pd.DataFrame(final_df, columns=['Stategy', 'Result'])
 final_df.sort_values(by=['Result'], ascending=False, inplace=True)
 print(final_df )
cols = ['deltaSeed','deltaMO', 'deltaWinPct','deltaPointsFor','deltaPointsAgainst','deltaFGM','deltaFGA','deltaFGM3','deltaFGA3','deltaFTM',
'deltaFTA','deltaOR','deltaDR','deltaAst','deltaTO','deltaStl','deltaBlk','deltaPF']
X = training_set[cols]
y = training_set['Result']
logit_model=sm.Logit(y,X)
 result=logit_model.fit()
print(result.summary2())
<define_search_space>
test_df['DT_W'] = test_df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 RESULTS['DT_W'] =(test_df['DT_W'].dt.year-2017)*52 + test_df['DT_W'].dt.weekofyear
for curent_time_block in range(RESULTS['DT_W'].min() , RESULTS['DT_W'].max() +1):
print('
print('Time Block:', curent_time_block)
 final_df = []
temp_df = RESULTS[RESULTS['DT_W']==curent_time_block]
for current_strategy in list(temp_df.iloc[:,2:]):
auc_score = metrics.roc_auc_score(temp_df[TARGET], temp_df[current_strategy])
 final_df.append([current_strategy, auc_score])
 final_df = pd.DataFrame(final_df, columns=['Stategy', 'Result'])
 final_df.sort_values(by=['Result'], ascending=False, inplace=True)
 print(final_df)
 print('
<compute_train_metric><EOS> 
print('
print('Small bonus')
 test_df = pd.read_pickle('.. /input/ieee-data-minification/test_transaction.pkl')
 kernel_with_identity = pd.read_csv('.. /input/ieee-gb-2-make-amount-useful-again/submission.csv')
 kernel_no_identity = pd.read_csv('.. /input/ieee-experimental/submission.csv')
 test_df = test_df[['TransactionID']]
test_df['isFraud'] = kernel_with_identity['isFraud'] + kernel_no_identity['isFraud']
test_df[['TransactionID','isFraud']].to_csv('submission.csv', index=False )