Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<feature_engineering>
FEATURE = True
warnings.filterwarnings("ignore")
 print("XGBoost version:", xgb.__version__)
 print("Tensorflow version " + tf.__version__)
 AUTO = tf.data.experimental.AUTOTUNE
str_type = ['ProductCD', 'card4', 'card6', 'P_emaildomain', 'R_emaildomain','M1', 'M2', 'M3', 'M4','M5',
'M6', 'M7', 'M8', 'M9', 'id_12', 'id_15', 'id_16', 'id_23', 'id_27', 'id_28', 'id_29', 'id_30',
'id_31', 'id_33', 'id_34', 'id_35', 'id_36', 'id_37', 'id_38', 'DeviceType', 'DeviceInfo']
str_type += ['id-12', 'id-15', 'id-16', 'id-23', 'id-27', 'id-28', 'id-29', 'id-30',
'id-31', 'id-33', 'id-34', 'id-35', 'id-36', 'id-37', 'id-38']
cols = ['TransactionID', 'TransactionDT', 'TransactionAmt',
'ProductCD', 'card1', 'card2', 'card3', 'card4', 'card5', 'card6',
'addr1', 'addr2', 'dist1', 'dist2', 'P_emaildomain', 'R_emaildomain',
'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11',
'C12', 'C13', 'C14', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8',
'D9', 'D10', 'D11', 'D12', 'D13', 'D14', 'D15', 'M1', 'M2', 'M3', 'M4',
'M5', 'M6', 'M7', 'M8', 'M9']
v = [1, 3, 4, 6, 8, 11]
v += [13, 14, 17, 20, 23, 26, 27, 30]
v += [36, 37, 40, 41, 44, 47, 48]
v += [54, 56, 59, 62, 65, 67, 68, 70]
v += [76, 78, 80, 82, 86, 88, 89, 91]
v += [107, 108, 111, 115, 117, 120, 121, 123]
v += [124, 127, 129, 130, 136]
v += [138, 139, 142, 147, 156, 162]
v += [165, 160, 166]
v += [178, 176, 173, 182]
v += [187, 203, 205, 207, 215]
v += [169, 171, 175, 180, 185, 188, 198, 210, 209]
v += [218, 223, 224, 226, 228, 229, 235]
v += [240, 258, 257, 253, 252, 260, 261]
v += [264, 266, 267, 274, 277]
v += [220, 221, 234, 238, 250, 271]
v += [294, 284, 285, 286, 291, 297]
v += [303, 305, 307, 309, 310, 320]
v += [281, 283, 289, 296, 301, 314]
cols += ['V'+str(x)for x in v]
dtypes = {}
for c in cols+['id_0'+str(x)for x in range(1,10)]+['id_'+str(x)for x in range(10,34)]+\
['id-0'+str(x)for x in range(1,10)]+['id-'+str(x)for x in range(10,34)]:
dtypes[c] = 'float32'
for c in str_type: dtypes[c] = 'category'
df_train["year"] = df_train["datetime"].dt.year
df_train["month"] = df_train["datetime"].dt.month
df_train["day"] = df_train["datetime"].dt.day
df_train["hour"] = df_train["datetime"].dt.hour
df_train["minute"] = df_train["datetime"].dt.minute
df_train["second"] = df_train["datetime"].dt.second
df_test["year"] = df_test["datetime"].dt.year
df_test["month"] = df_test["datetime"].dt.month
df_test["day"] = df_test["datetime"].dt.day
df_test["hour"] = df_test["datetime"].dt.hour
df_test["minute"] = df_test["datetime"].dt.minute
df_test["second"] = df_test["datetime"].dt.second
df_train.shape 
<feature_engineering>
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 )
df_train["dayofweek"] = df_train["datetime"].dt.dayofweek
df_test["dayofweek"] = df_test["datetime"].dt.dayofweek
df_train.shape 
<count_values>
MIXED_PRECISION = False
XLA_ACCELERATE = True
if MIXED_PRECISION:
if tpu: policy = tf.keras.mixed_precision.experimental.Policy('mixed_bfloat16')
 else: policy = tf.keras.mixed_precision.experimental.Policy('mixed_float16')
 mixed_precision.set_policy(policy)
 print('Mixed precision enabled')
 if XLA_ACCELERATE:
tf.config.optimizer.set_jit(True)
 print('Accelerated Linear Algebra enabled' )
df_train["dayofweek"].value_counts() 
<feature_engineering>
%%time
if FEATURE:
X_train = pd.read_csv('.. /input/ieee-with-feature/IEEE_Train.csv', index_col = 'TransactionID')
 X_test = pd.read_csv('.. /input/ieee-with-feature/IEEE_Test.csv', index_col = 'TransactionID')
 y_train = pd.read_csv('.. /input/ieee-with-feature/IEEE_Target.csv', index_col = 'TransactionID')
 else:
X_train = pd.read_csv('.. /input/ieee-fraud-detection/train_transaction.csv',index_col='TransactionID', dtype=dtypes, usecols=cols+['isFraud'])
 train_id = pd.read_csv('.. /input/ieee-fraud-detection/train_identity.csv',index_col='TransactionID', dtype=dtypes)
 X_train = X_train.merge(train_id, how='left', left_index=True, right_index=True)
 X_test = pd.read_csv('.. /input/ieee-fraud-detection/test_transaction.csv',index_col='TransactionID', dtype=dtypes, usecols=cols)
 test_id = pd.read_csv('.. /input/ieee-fraud-detection/test_identity.csv',index_col='TransactionID', dtype=dtypes)
 fix = {o:n for o, n in zip(test_id.columns, train_id.columns)}
test_id.rename(columns=fix, inplace=True)
 X_test = X_test.merge(test_id, how='left', left_index=True, right_index=True)
 y_train = X_train['isFraud'].copy()
del train_id, test_id, X_train['isFraud']; x = gc.collect()
print('Train shape',X_train.shape,'test shape',X_test.shape )
def concatenate_year_month(datetime):
return "{0}-{1}".format(datetime.year, datetime.month)
 df_train["year_month"] = df_train["datetime"].apply(concatenate_year_month)
 df_test["year_month"] = df_test["datetime"].apply(concatenate_year_month)
 print(df_train.shape)
 df_train[["datetime", "year_month"]].head() 
<define_variables>
def detect_outliers(df, n, features):
outlier_indices = []
for col in features:
Q1 = np.percentile(df[col], 25)
 Q3 = np.percentile(df[col], 75)
 IQR = Q3 - Q1
outlier_step = 1.5 * IQR
outlier_list_col = df[(df[col] < Q1 - outlier_step)|(df[col] > Q3 + outlier_step)].index
outlier_indices.extend(outlier_list_col)
 outlier_indices = Counter(outlier_indices)
 multiple_outliers = list(k for k, v in outlier_indices.items() if v > n)
 return multiple_outliers
Outliers_to_drop = detect_outliers(df_train, 2, ["temp", "atemp", "casual", "registered", "humidity", "windspeed", "count"])
<filter>
if not FEATURE:
for i in range(1,16):
if i in [1,2,3,5,9]: continue
X_train['D'+str(i)] = X_train['D'+str(i)] - X_train.TransactionDT/np.float32(24*60*60)
 X_test['D'+str(i)] = X_test['D'+str(i)] - X_test.TransactionDT/np.float32(24*60*60 )
df_train.loc[Outliers_to_drop]<drop_column>
%%time
if not FEATURE:
for i,f in enumerate(X_train.columns):
if(np.str(X_train[f].dtype)=='category')|(X_train[f].dtype=='object'):
df_comb = pd.concat([X_train[f],X_test[f]],axis=0)
 df_comb,_ = df_comb.factorize(sort=True)
 if df_comb.max() >32000: print(f,'needs int32')
 X_train[f] = df_comb[:len(X_train)].astype('int16')
 X_test[f] = df_comb[len(X_train):].astype('int16')
 elif f not in ['TransactionAmt','TransactionDT']:
mn = np.min(( X_train[f].min() ,X_test[f].min()))
X_train[f] -= np.float32(mn)
 X_test[f] -= np.float32(mn)
 X_train[f].fillna(-1,inplace=True)
 X_test[f].fillna(-1,inplace=True )
df_train = df_train.drop(Outliers_to_drop, axis = 0 ).reset_index(drop=True)
 df_train.shape<filter>
def encode_FE(df1, df2, cols):
for col in cols:
df = pd.concat([df1[col],df2[col]])
 vc = df.value_counts(dropna=True, normalize=True ).to_dict()
vc[-1] = -1
nm = col+'_FE'
df1[nm] = df1[col].map(vc)
 df1[nm] = df1[nm].astype('float32')
 df2[nm] = df2[col].map(vc)
 df2[nm] = df2[nm].astype('float32')
 print(nm,', ',end='')
 def encode_LE(col,train=X_train,test=X_test,verbose=True):
df_comb = pd.concat([train[col],test[col]],axis=0)
 df_comb,_ = df_comb.factorize(sort=True)
 nm = col
if df_comb.max() >32000:
train[nm] = df_comb[:len(train)].astype('int32')
 test[nm] = df_comb[len(train):].astype('int32')
 else:
train[nm] = df_comb[:len(train)].astype('int16')
 test[nm] = df_comb[len(train):].astype('int16')
 del df_comb; x=gc.collect()
if verbose: print(nm,', ',end='')
 def encode_AG(main_columns, uids, aggregations=['mean'], train_df=X_train, test_df=X_test,
fillna=True, usena=False):
for main_column in main_columns:
for col in uids:
for agg_type in aggregations:
new_col_name = main_column+'_'+col+'_'+agg_type
temp_df = pd.concat([train_df[[col, main_column]], test_df[[col,main_column]]])
 if usena: temp_df.loc[temp_df[main_column]==-1,main_column] = np.nan
temp_df = temp_df.groupby([col])[main_column].agg([agg_type] ).reset_index().rename(
 columns={agg_type: new_col_name})
 temp_df.index = list(temp_df[col])
 temp_df = temp_df[new_col_name].to_dict()
train_df[new_col_name] = train_df[col].map(temp_df ).astype('float32')
 test_df[new_col_name] = test_df[col].map(temp_df ).astype('float32')
 if fillna:
train_df[new_col_name].fillna(-1,inplace=True)
 test_df[new_col_name].fillna(-1,inplace=True)
 print("'"+new_col_name+"'",', ',end='')
 def encode_CB(col1,col2,df1=X_train,df2=X_test):
nm = col1+'_'+col2
df1[nm] = df1[col1].astype(str)+'_'+df1[col2].astype(str)
 df2[nm] = df2[col1].astype(str)+'_'+df2[col2].astype(str)
 encode_LE(nm,verbose=False)
 print(nm,', ',end='')
 def encode_AG2(main_columns, uids, train_df=X_train, test_df=X_test):
for main_column in main_columns:
for col in uids:
comb = pd.concat([train_df[[col]+[main_column]],test_df[[col]+[main_column]]],axis=0)
 mp = comb.groupby(col)[main_column].agg(['nunique'])['nunique'].to_dict()
train_df[col+'_'+main_column+'_ct'] = train_df[col].map(mp ).astype('float32')
 test_df[col+'_'+main_column+'_ct'] = test_df[col].map(mp ).astype('float32')
 print(col+'_'+main_column+'_ct, ',end='' )
trainWind0 = df_train.loc[df_train["windspeed"] == 0]
trainWindNot0 = df_train.loc[df_train["windspeed"] != 0] 
<feature_engineering>
%%time
if not FEATURE:
X_train['cents'] =(X_train['TransactionAmt'] - np.floor(X_train['TransactionAmt'])).astype('float32')
 X_test['cents'] =(X_test['TransactionAmt'] - np.floor(X_test['TransactionAmt'])).astype('float32')
 print('cents, ', end='')
 encode_FE(X_train,X_test,['addr1','card1','card2','card3','P_emaildomain'])
 encode_CB('card1','addr1')
 encode_CB('card1_addr1','P_emaildomain')
 encode_FE(X_train,X_test,['card1_addr1','card1_addr1_P_emaildomain'])
 encode_AG(['TransactionAmt','D9','D11'],['card1','card1_addr1','card1_addr1_P_emaildomain'],['mean','std'],usena=True )
def predict_windspeed(data):
dataWind0 = data.loc[data["windspeed"] == 0]
dataWindNot0 = data.loc[data["windspeed"] != 0]
wcol = ["season", "weather", "humidity", "day", "temp", "atemp"]
dataWindNot0["windspeed"] = dataWindNot0["windspeed"].astype("str")
 rf_wind = RandomForestClassifier()
rf_wind.fit(dataWindNot0[wcol], dataWindNot0["windspeed"])
 wind0 = rf_wind.predict(X=dataWind0[wcol])
 predictWind0 = dataWind0
predictWindNot0 = dataWindNot0
predictWind0["windspeed"] = wind0
data = predictWindNot0.append(predictWind0)
 data["windspeed"] = data["windspeed"].astype("float")
 data.reset_index(inplace = True)
 data.drop("index", inplace = True, axis = 1)
 return data 
<categorify>
if not FEATURE:
cols = list(X_train.columns)
 cols.remove('TransactionDT')
 for c in ['D6','D7','D8','D9','D12','D13','D14']:
cols.remove(c)
 for c in ['C3','M5','id_08','id_33']:
cols.remove(c)
 for c in ['card4','id_07','id_14','id_21','id_30','id_32','id_34']:
cols.remove(c)
 for c in ['id_'+str(x)for x in range(22,28)]:
cols.remove(c )
df_train = pd.get_dummies(df_train, columns = ["weather"], prefix = "weather")
 df_test = pd.get_dummies(df_test, columns = ["weather"], prefix = "weather")
 df_train = pd.get_dummies(df_train, columns = ["season"], prefix = "season")
 df_test = pd.get_dummies(df_test, columns = ["season"], prefix = "season")
<drop_column>
if not FEATURE:
print('NOW USING THE FOLLOWING',len(cols),'FEATURES.')
 np.array(cols )
datetime_test = df_test['datetime']
df_train.drop(["datetime", "registered","casual","holiday", "year_month", "minute", "second"], axis = 1, inplace = True)
 df_test.drop(["datetime","holiday", "year_month", "minute", "second"], axis = 1, inplace = True)
<split>
if not FEATURE:
START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d')
 X_train['DT_M'] = X_train['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 X_train['DT_M'] =(X_train['DT_M'].dt.year-2017)*12 + X_train['DT_M'].dt.month
X_test['DT_M'] = X_test['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 X_test['DT_M'] =(X_test['DT_M'].dt.year-2017)*12 + X_test['DT_M'].dt.month
X_train = df_train.drop("count_Log", axis = 1 ).values
target_label = df_train["count_Log"].values
X_test = df_test.values
X_tr, X_vld, y_tr, y_vld = train_test_split(X_train, target_label, test_size = 0.2, random_state = 2000 )<train_model>
if not FEATURE:
X_train['day'] = X_train.TransactionDT /(24*60*60)
 X_train['uid'] = X_train.card1_addr1.astype(str)+'_'+np.floor(X_train.day-X_train.D1 ).astype(str)
 X_test['day'] = X_test.TransactionDT /(24*60*60)
 X_test['uid'] = X_test.card1_addr1.astype(str)+'_'+np.floor(X_test.day-X_test.D1 ).astype(str )
regressor = GradientBoostingRegressor(n_estimators=2000, learning_rate=0.05,
max_depth=4,
min_samples_leaf=15, min_samples_split=10, random_state =42)
 regressor.fit(X_tr,y_tr )<choose_model_class>
%%time
if not FEATURE:
encode_FE(X_train,X_test,['uid'])
 encode_AG(['TransactionAmt','D4','D9','D10','D15'],['uid'],['mean','std'],fillna=True,usena=True)
 encode_AG(['C'+str(x)for x in range(1,15)if x!=3],['uid'],['mean'],X_train,X_test,fillna=True,usena=True)
 encode_AG(['M'+str(x)for x in range(1,10)],['uid'],['mean'],fillna=True,usena=True)
 encode_AG2(['P_emaildomain','dist1','DT_M','id_02','cents'], ['uid'], train_df=X_train, test_df=X_test)
 encode_AG(['C14'],['uid'],['std'],X_train,X_test,fillna=True,usena=True)
 encode_AG2(['C13','V314'], ['uid'], train_df=X_train, test_df=X_test)
 encode_AG2(['V127','V136','V309','V307','V320'], ['uid'], train_df=X_train, test_df=X_test)
 X_train['outsider15'] =(np.abs(X_train.D1-X_train.D15)>3 ).astype('int8')
 X_test['outsider15'] =(np.abs(X_test.D1-X_test.D15)>3 ).astype('int8')
 print('outsider15' )
models=[GradientBoostingRegressor() ]
model_names=['regressor']
rmsle=[]
d={}
for model in range(len(models)) :
clf=models[model]
clf.fit(X_tr,y_tr)
 test_pred=clf.predict(X_vld)
 rmsle.append(np.sqrt(mean_squared_log_error(test_pred,y_vld)))
 d={'Modelling Algo':model_names,'RMSLE':rmsle}
d<compute_train_metric>
cols = list(X_train.columns)
 cols.remove('TransactionDT')
 for c in ['D6','D7','D8','D9','D12','D13','D14']:
cols.remove(c)
 for c in ['DT_M','day','uid']:
cols.remove(c)
 for c in ['C3','M5','id_08','id_33']:
cols.remove(c)
 for c in ['card4','id_07','id_14','id_21','id_30','id_32','id_34']:
cols.remove(c)
 for c in ['id_'+str(x)for x in range(22,28)]:
cols.remove(c )
accuracies = cross_val_score(estimator = regressor, X = X_tr, y = y_tr, cv = 8 )<save_to_csv>
def create_model(data, catcols, numcols, hidden_units, spatial_dropout_rate, dropout_rate):
inp_cat = []
outputs = []
for c in catcols:
num_unique_values = int(data[c].nunique())
 embed_dim = int(min(np.ceil(( num_unique_values)/ 2), 50))
inp = layers.Input(shape =(1,))
out = layers.Embedding(num_unique_values + 1, embed_dim, name = c )(inp)
 out = layers.SpatialDropout1D(spatial_dropout_rate )(out)
 out = layers.Reshape(( embed_dim,))(out)
 inp_cat.append(inp)
 outputs.append(out)
 inp_num = layers.Input(shape =(len(numcols),))
outputs.append(inp_num)
 x = layers.Concatenate()(outputs)
 x = layers.BatchNormalization()(x)
 for units in hidden_units:
x = layers.Dense(units, activation = "relu" )(x)
 x = layers.Dropout(dropout_rate )(x)
 x = layers.BatchNormalization()(x)
 y = layers.Dense(1, activation = 'sigmoid' )(x)
 model = Model(inputs = [inp_cat, inp_num], outputs = y)
 return model
use_logvals = 1
pred_xgb = regressor.predict(X_test)
 sub_xgb = pd.DataFrame()
sub_xgb['datetime'] = datetime_test
sub_xgb['count'] = pred_xgb
if use_logvals == 1:
sub_xgb['count'] = np.exp(sub_xgb['count'])
 sub_xgb.to_csv('xgb.csv',index=False )<import_modules>
catcols = []
numcols = []
for c in X_train[cols].columns:
if(X_train[c].dtype == 'int64')or(X_train[c].dtype == 'int32'):
catcols.append(c)
 else:
numcols.append(c)
 print(catcols )
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from xgboost.sklearn import XGBRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import accuracy_score
from keras.callbacks import ModelCheckpoint
from keras.models import Sequential
from keras.layers import Dense, Activation, Flatten
from keras.layers import Dropout
import lightgbm as lgb
from sklearn.metrics import mean_squared_error
from math import sqrt<load_from_csv>
for c in catcols:
le = LabelEncoder()
le.fit(np.concatenate([X_train[c], X_test[c]]))
X_train[c] = le.transform(X_train[c])
 X_test[c] = le.transform(X_test[c])
 del le
gc.collect()
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )<load_from_csv>
%%time
scaler = StandardScaler()
scaler.fit(pd.concat([X_train[numcols], X_test[numcols]]))
X_train[numcols] = scaler.transform(X_train[numcols])
 X_test[numcols] = scaler.transform(X_test[numcols])
 del scaler
gc.collect()
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )<data_type_conversions>
hidden_units = [1024, 512, 256]
spatial_dropout_rate = 0.3
dropout_rate = 0.5
data = pd.concat([X_train[cols], X_test[cols]])
 with strategy.scope() :
model = create_model(data, catcols, numcols, hidden_units, spatial_dropout_rate, dropout_rate)
 model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = [tf.metrics.AUC(name = 'AUC')])
 model.summary()
del data
gc.collect()
def add_dates(data , column , suffix='time_' , year = True , month = True , day = False ,dayofweek = True, hour = True , minute = False , second = False , date = False , time = False):
data['add_date_date_time'] = pd.to_datetime(data[column])
 if year == True:
data[suffix+'year']=data['add_date_date_time'].dt.year
if month == True:
data[suffix+'month']=data['add_date_date_time'].dt.month
if day == True:
data[suffix+'day']=data['add_date_date_time'].dt.day
if hour == True:
data[suffix+'hour']=data['add_date_date_time'].dt.hour
if minute == True:
data[suffix+'minute']=data['add_date_date_time'].dt.minute
if date == True:
data[suffix+'date']=data['add_date_date_time'].dt.date
if time == True:
data[suffix+'time']=data['add_date_date_time'].dt.time
if second == True:
data[suffix+'second']=data['add_date_date_time'].dt.second
if dayofweek == True:
data[suffix+'dayofweek']=data['add_date_date_time'].dt.dayofweek
data = data.drop(columns = ['add_date_date_time'] , axis =1)
 return data
train = add_dates(train , column = 'datetime')
 define_data(train , columns = True )<count_unique_values>
def unique_count(data , columns = []):
for col in columns :
print('Unique Data Percentage in ',col)
 print(( data[col].value_counts() /data.shape[0])*100)
 print('
')
 unique_count(train , columns = ['season','weather','time_year', 'time_dayofweek'] )<groupby>
class CosineAnnealingScheduler(callbacks.Callback):

 def __init__(self, T_max, eta_max, eta_min = 0, verbose = 0):
super(CosineAnnealingScheduler, self ).__init__()
self.T_max = T_max
self.eta_max = eta_max
self.eta_min = eta_min
self.verbose = verbose
def on_epoch_begin(self, epoch, logs = None):
if not hasattr(self.model.optimizer, 'lr'):
raise ValueError('Optimizer must have a "lr" attribute.')
 lr = self.eta_min +(self.eta_max - self.eta_min)*(1 + math.cos(math.pi * epoch / self.T_max)) / 2
K.set_value(self.model.optimizer.lr, lr)
 if self.verbose > 0:
print('
Epoch %05d: CosineAnnealingScheduler setting learning '
'rate to %s.' %(epoch + 1, lr))
def on_epoch_end(self, epoch, logs = None):
logs = logs or {}
logs['lr'] = K.get_value(self.model.optimizer.lr )
def hour_group(s):
if(( 0<=s)&(s<=6)) :
return 1
elif(( s==7)|(s==9)) :
return 2
elif(( s==8)|(s==16)|(s==19)) :
return 3
elif(( 10<=s)&(s<=15)) :
return 4
elif(( s==17)|(s==18)) :
return 5
elif(20<=s):
return 6 
<data_type_conversions>
train['time_hour_group'] = train['time_hour'].apply(hour_group ).astype(str)
<feature_engineering>
sample_submission = pd.read_csv('.. /input/ieee-fraud-detection/sample_submission.csv')
 sample_submission.isFraud = preds
sample_submission.to_csv('sub_dl.csv',index=False)
 plt.hist(sample_submission.isFraud,bins=100)
 plt.ylim(( 0,5000))
plt.title('DL Submission')
 plt.show()
train = new_col_categorical(train,columns=['season','weather','time_year', 'time_dayofweek' , 'time_month','time_hour_group'] , remove_original = False )<feature_engineering>
X_test['isFraud'] = sample_submission.isFraud.values
X_train['isFraud'] = y_train.values
comb = pd.concat([X_train[['isFraud']],X_test[['isFraud']]],axis=0)
 uids = pd.read_csv('/kaggle/input/ieee-submissions-and-uids/uids_v4_no_multiuid_cleaning.. csv',usecols=['TransactionID','uid'] ).rename({'uid':'uid2'},axis=1)
 comb = comb.merge(uids,on='TransactionID',how='left')
 mp = comb.groupby('uid2' ).isFraud.agg(['mean'])
 comb.loc[comb.uid2>0,'isFraud'] = comb.loc[comb.uid2>0].uid2.map(mp['mean'])
 uids = pd.read_csv('/kaggle/input/ieee-submissions-and-uids/uids_v1_no_multiuid_cleaning.csv',usecols=['TransactionID','uid'] ).rename({'uid':'uid3'},axis=1)
 comb = comb.merge(uids,on='TransactionID',how='left')
 mp = comb.groupby('uid3' ).isFraud.agg(['mean'])
 comb.loc[comb.uid3>0,'isFraud'] = comb.loc[comb.uid3>0].uid3.map(mp['mean'])
 sample_submission.isFraud = comb.iloc[len(X_train):].isFraud.values
sample_submission.to_csv('sub_dl_PP.csv',index=False )
<data_type_conversions><EOS>