Kaggle competition: IEEE-CIS Fraud Detection
<SOS> metric: AUC Kaggle data source: ieee-cis-fraud-detection<data_type_conversions>
%matplotlib inline
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
train_data['Embarked'] = train_data['Embarked'].fillna(value=train_data['Embarked'].mode() [0] )<count_missing_values>
def prepare_altair() :

 vega_url = 'https://cdn.jsdelivr.net/npm/vega@' + v5.SCHEMA_VERSION
vega_lib_url = 'https://cdn.jsdelivr.net/npm/vega-lib'
vega_lite_url = 'https://cdn.jsdelivr.net/npm/vega-lite@' + alt.SCHEMA_VERSION
vega_embed_url = 'https://cdn.jsdelivr.net/npm/vega-embed@3'
noext = "?noext"
paths = {
'vega': vega_url + noext,
'vega-lib': vega_lib_url + noext,
'vega-lite': vega_lite_url + noext,
'vega-embed': vega_embed_url + noext
}
workarounds = f
return workarounds
def add_autoincrement(render_func):
cache = {}
def wrapped(chart, id="vega-chart", autoincrement=True):
if autoincrement:
if id in cache:
counter = 1 + cache[id]
cache[id] = counter
else:
cache[id] = 0
actual_id = id if cache[id] == 0 else id + '-' + str(cache[id])
 else:
if id not in cache:
cache[id] = 0
actual_id = id
return render_func(chart, id=actual_id)
 return wrapped
@add_autoincrement
def render(chart, id="vega-chart"):

 chart_str =
return HTML(
 chart_str.format(
 id=id,
chart=json.dumps(chart)if isinstance(chart, dict)else chart.to_json(indent=None)
)
)
 workaround = prepare_altair()
HTML("".join((
"<script>",
workaround,
"</script>", 
)) )
train_data.isnull().sum()<rename_columns>
sample_sub = pd.read_csv('/kaggle/input/ieee-fraud-detection/sample_submission.csv')
 sample_sub.head(10 )
train_data['Sex'] = train_data['Sex'].replace(['male', 'female'],[1,0])
 train_data.rename(columns = {'Sex' : 'gender'}, inplace = True )<rename_columns>
del sample_sub
train_data['Embarked'] = train_data['Embarked'].replace(['S','C','Q'],[0,1,2])
 train_data.rename(columns = {'Embarked' : 'port'}, inplace = True )<rename_columns>
train_identity = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_identity.csv')
 train_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_transaction.csv')
 test_identity = pd.read_csv('/kaggle/input/ieee-fraud-detection/test_identity.csv')
 test_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/test_transaction.csv' )
train_data.rename(columns = {'Pclass' : 'passenger_cls'} )<drop_column>
train = pd.merge(train_transaction, train_identity, on='TransactionID', how='left')
 test = pd.merge(test_transaction, test_identity, on='TransactionID', how='left' )
train_data['family_members'] = train_data['SibSp'] + train_data['Parch']
train_data.drop(['SibSp', 'Parch'], axis = 1, inplace=True )<feature_engineering>
print(f'Train dataset: {train.shape[0]} rows & {train.shape[1]} columns')
 print(f'Test dataset: {test.shape[0]} rows & {test.shape[1]} columns' )
train_data.loc[ train_data['Age'] <= 21, 'Age'] = 0
train_data.loc[(train_data['Age'] > 21)&(train_data['Age'] <= 34), 'Age'] = 1
train_data.loc[(train_data['Age'] > 34)&(train_data['Age'] <= 54), 'Age'] = 2
train_data.loc[(train_data['Age'] > 60)&(train_data['Age'] <= 75), 'Age'] = 3
train_data.loc[ train_data['Age'] > 75, 'Age'] ;<feature_engineering>
train = reduce_mem_usage(train)
 test = reduce_mem_usage(test )
train_data.loc[ train_data['Fare'] <= 7.5, 'Fare'] = 0
train_data.loc[(train_data['Fare'] > 15)&(train_data['Fare'] <= 21.5), 'Fare'] = 1
train_data.loc[(train_data['Fare'] > 21.5)&(train_data['Age'] <= 29), 'Fare'] = 2
train_data.loc[(train_data['Fare'] > 29)&(train_data['Fare'] <= 36.5), 'Fare'] = 3
train_data.loc[ train_data['Fare'] > 36.5, 'Fare'] ;<drop_column>
del train_identity, train_transaction, test_identity, test_transaction
train_data.drop(['Ticket'], axis = 1, inplace=True )<count_missing_values>
data_null = train.isnull().sum() /len(train)* 100
data_null = data_null.drop(data_null[data_null == 0].index ).sort_values(ascending=False)[:500]
missing_data = pd.DataFrame({'Missing Ratio': data_null})
 missing_data.head()
test_data.isnull().sum()<drop_column>
def get_too_many_null_attr(data):
many_null_cols = [col for col in data.columns if data[col].isnull().sum() / data.shape[0] > 0.9]
return many_null_cols
test_data.drop(['Name', 'Ticket','Cabin'], axis = 1, inplace = True )<data_type_conversions>
def get_too_many_repeated_val(data):
big_top_value_cols = [col for col in train.columns if train[col].value_counts(dropna=False, normalize=True ).values[0] > 0.9]
return big_top_value_cols
test_data['Age'].fillna(value=test_data['Age'].mean() , inplace=True )<data_type_conversions>
train['id_03'].value_counts(dropna=False, normalize=True ).head()
test_data['Fare'].fillna(value=test_data['Fare'].mean() , inplace=True )<count_missing_values>
train['id_11'].value_counts(dropna=False, normalize=True ).head()
test_data.isnull().sum()<rename_columns>
for i in range(1, 10):
print(train['M' + str(i)].value_counts(dropna=False, normalize=True ).head())
 print('
' )
test_data['Sex'] = test_data['Sex'].replace(['male', 'female'],[1,0])
 test_data.rename(columns = {'Sex' : 'gender'}, inplace = True )<rename_columns>
del charts
test_data['Embarked'] = test_data['Embarked'].replace(['S','C','Q'],[0,1,2])
 test_data.rename(columns = {'Embarked' : 'port'}, inplace = True )<rename_columns>
def seed_everything(seed=0):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
test_data.rename(columns = {'Pclass' : 'passenger cls'} )<drop_column>
SEED = 42
seed_everything(SEED)
 TARGET = 'isFraud'
START_DATE = datetime.datetime.strptime('2017-11-30', '%Y-%m-%d' )
test_data['family_members'] = test_data['SibSp'] + test_data['Parch']
test_data.drop(['SibSp', 'Parch'], axis = 1, inplace=True )<feature_engineering>
def addNewFeatures(data):
data['uid'] = data['card1'].astype(str)+'_'+data['card2'].astype(str)
 data['uid2'] = data['uid'].astype(str)+'_'+data['card3'].astype(str)+'_'+data['card5'].astype(str)
 data['uid3'] = data['uid2'].astype(str)+'_'+data['addr1'].astype(str)+'_'+data['addr2'].astype(str)
 return data
test_data.loc[ test_data['Age'] <= 21, 'Age'] = 0
test_data.loc[(test_data['Age'] > 21)&(test_data['Age'] <= 34), 'Age'] = 1
test_data.loc[(test_data['Age'] > 34)&(test_data['Age'] <= 54), 'Age'] = 2
test_data.loc[(test_data['Age'] > 60)&(test_data['Age'] <= 75), 'Age'] = 3
test_data.loc[ test_data['Age'] > 75, 'Age'] ;<feature_engineering>
train = addNewFeatures(train)
 test = addNewFeatures(test )
test_data.loc[ test_data['Fare'] <= 7.5, 'Fare'] = 0
test_data.loc[(test_data['Fare'] > 15)&(test_data['Fare'] <= 21.5), 'Fare'] = 1
test_data.loc[(test_data['Fare'] > 21.5)&(test_data['Age'] <= 29), 'Fare'] = 2
test_data.loc[(test_data['Fare'] > 29)&(test_data['Fare'] <= 36.5), 'Fare'] = 3
test_data.loc[ test_data['Fare'] > 36.5, 'Fare'] ;<drop_column>
i_cols = ['card1','card2','card3','card5','uid','uid2','uid3']
for col in i_cols:
for agg_type in ['mean','std']:
new_col_name = col+'_TransactionAmt_'+agg_type
temp_df = pd.concat([train[[col, 'TransactionAmt']], test[[col,'TransactionAmt']]])
 temp_df = temp_df.groupby([col])['TransactionAmt'].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[new_col_name] = train[col].map(temp_df)
 test[new_col_name] = test[col].map(temp_df )
x = train_data.drop("Survived", axis = 1 )<prepare_x_and_y>
train = train.replace(np.inf,999)
 test = test.replace(np.inf,999 )
y = train_data["Survived"]<import_modules>
train['TransactionAmt'] = np.log1p(train['TransactionAmt'])
 test['TransactionAmt'] = np.log1p(test['TransactionAmt'] )
from sklearn.model_selection import train_test_split<import_modules>
emails = {'gmail': 'google', 'att.net': 'att', 'twc.com': 'spectrum', 'scranton.edu': 'other', 'optonline.net': 'other',
'hotmail.co.uk': 'microsoft', 'comcast.net': 'other', 'yahoo.com.mx': 'yahoo', 'yahoo.fr': 'yahoo',
'yahoo.es': 'yahoo', 'charter.net': 'spectrum', 'live.com': 'microsoft', 'aim.com': 'aol', 'hotmail.de': 'microsoft',
'centurylink.net': 'centurylink', 'gmail.com': 'google', 'me.com': 'apple', 'earthlink.net': 'other',
'gmx.de': 'other', 'web.de': 'other', 'cfl.rr.com': 'other', 'hotmail.com': 'microsoft', 'protonmail.com': 'other',
'hotmail.fr': 'microsoft', 'windstream.net': 'other', 'outlook.es': 'microsoft', 'yahoo.co.jp': 'yahoo',
'yahoo.de': 'yahoo', 'servicios-ta.com': 'other', 'netzero.net': 'other', 'suddenlink.net': 'other',
'roadrunner.com': 'other', 'sc.rr.com': 'other', 'live.fr': 'microsoft', 'verizon.net': 'yahoo',
'msn.com': 'microsoft', 'q.com': 'centurylink', 'prodigy.net.mx': 'att', 'frontier.com': 'yahoo',
'anonymous.com': 'other', 'rocketmail.com': 'yahoo', 'sbcglobal.net': 'att', 'frontiernet.net': 'yahoo',
'ymail.com': 'yahoo', 'outlook.com': 'microsoft', 'mail.com': 'other', 'bellsouth.net': 'other',
'embarqmail.com': 'centurylink', 'cableone.net': 'other', 'hotmail.es': 'microsoft', 'mac.com': 'apple',
'yahoo.co.uk': 'yahoo', 'netzero.com': 'other', 'yahoo.com': 'yahoo', 'live.com.mx': 'microsoft', 'ptd.net': 'other',
'cox.net': 'other', 'aol.com': 'aol', 'juno.com': 'other', 'icloud.com': 'apple'}
us_emails = ['gmail', 'net', 'edu']
for c in ['P_emaildomain', 'R_emaildomain']:
train[c + '_bin'] = train[c].map(emails)
 test[c + '_bin'] = test[c].map(emails)
 train[c + '_suffix'] = train[c].map(lambda x: str(x ).split('.')[-1])
 test[c + '_suffix'] = test[c].map(lambda x: str(x ).split('.')[-1])
 train[c + '_suffix'] = train[c + '_suffix'].map(lambda x: x if str(x)not in us_emails else 'us')
 test[c + '_suffix'] = test[c + '_suffix'].map(lambda x: x if str(x)not in us_emails else 'us' )
from sklearn.model_selection import train_test_split<split>
p = 'P_emaildomain'
r = 'R_emaildomain'
uknown = 'email_not_provided'
def setDomain(df):
df[p] = df[p].fillna(uknown)
 df[r] = df[r].fillna(uknown)
 df['email_check'] = np.where(( df[p]==df[r])&(df[p]!=uknown),1,0)
 df[p+'_prefix'] = df[p].apply(lambda x: x.split('.')[0])
 df[r+'_prefix'] = df[r].apply(lambda x: x.split('.')[0])
 return df
train=setDomain(train)
 test=setDomain(test )
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.4, random_state = 12 )<compute_train_metric>
def setTime(df):
df['TransactionDT'] = df['TransactionDT'].fillna(df['TransactionDT'].median())
 df['DT'] = df['TransactionDT'].apply(lambda x:(START_DATE + datetime.timedelta(seconds = x)))
 df['DT_M'] =(df['DT'].dt.year-2017)*12 + df['DT'].dt.month
df['DT_W'] =(df['DT'].dt.year-2017)*52 + df['DT'].dt.weekofyear
df['DT_D'] =(df['DT'].dt.year-2017)*365 + df['DT'].dt.dayofyear
df['DT_hour'] = df['DT'].dt.hour
df['DT_day_week'] = df['DT'].dt.dayofweek
df['DT_day'] = df['DT'].dt.day
df['D9_not_na'] = np.where(df['D9'].isna() ,0,1)
 df['D8_not_same_day'] = np.where(df['D8']>=1,1,0)
 df['D8_D9_decimal_dist'] = df['D8'].fillna(0)-df['D8'].fillna(0 ).astype(int)
 df['D8_D9_decimal_dist'] =(( df['D8_D9_decimal_dist']-df['D9'])**2)**0.5
df['D8'] = df['D8'].fillna(-1 ).astype(int)
 return df
train=setTime(train)
 test=setTime(test )
dtree = DecisionTreeClassifier()
dtree.fit(x_train, y_train)
 y_pred = dtree.predict(x_test)
 dtree_accuracy = round(accuracy_score(y_pred, y_test)* 100, 2)
 print(dtree_accuracy )<predict_on_test>
train["lastest_browser"] = np.zeros(train.shape[0])
 test["lastest_browser"] = np.zeros(test.shape[0])
 def setBrowser(df):
df.loc[df["id_31"]=="samsung browser 7.0",'lastest_browser']=1
df.loc[df["id_31"]=="opera 53.0",'lastest_browser']=1
df.loc[df["id_31"]=="mobile safari 10.0",'lastest_browser']=1
df.loc[df["id_31"]=="google search application 49.0",'lastest_browser']=1
df.loc[df["id_31"]=="firefox 60.0",'lastest_browser']=1
df.loc[df["id_31"]=="edge 17.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 69.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 67.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 63.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 63.0 for ios",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 64.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 64.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 64.0 for ios",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 65.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 65.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 65.0 for ios",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 66.0",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 66.0 for android",'lastest_browser']=1
df.loc[df["id_31"]=="chrome 66.0 for ios",'lastest_browser']=1
return df
train=setBrowser(train)
 test=setBrowser(test )
randomforest = RandomForestClassifier(n_estimators=30, max_depth = 4)
 randomforest.fit(x_train, y_train)
 y_pred = randomforest.predict(x_test)
 acc_randomforest = round(accuracy_score(y_pred, y_test)* 100, 2)
 print(acc_randomforest )<compute_train_metric>
def setDevice(df):
df['DeviceInfo'] = df['DeviceInfo'].fillna('unknown_device' ).str.lower()
df['device_name'] = df['DeviceInfo'].str.split('/', expand=True)[0]
df.loc[df['device_name'].str.contains('SM', na=False), 'device_name'] = 'Samsung'
df.loc[df['device_name'].str.contains('SAMSUNG', na=False), 'device_name'] = 'Samsung'
df.loc[df['device_name'].str.contains('GT-', na=False), 'device_name'] = 'Samsung'
df.loc[df['device_name'].str.contains('Moto G', na=False), 'device_name'] = 'Motorola'
df.loc[df['device_name'].str.contains('Moto', na=False), 'device_name'] = 'Motorola'
df.loc[df['device_name'].str.contains('moto', na=False), 'device_name'] = 'Motorola'
df.loc[df['device_name'].str.contains('LG-', na=False), 'device_name'] = 'LG'
df.loc[df['device_name'].str.contains('rv:', na=False), 'device_name'] = 'RV'
df.loc[df['device_name'].str.contains('HUAWEI', na=False), 'device_name'] = 'Huawei'
df.loc[df['device_name'].str.contains('ALE-', na=False), 'device_name'] = 'Huawei'
df.loc[df['device_name'].str.contains('-L', na=False), 'device_name'] = 'Huawei'
df.loc[df['device_name'].str.contains('Blade', na=False), 'device_name'] = 'ZTE'
df.loc[df['device_name'].str.contains('BLADE', na=False), 'device_name'] = 'ZTE'
df.loc[df['device_name'].str.contains('Linux', na=False), 'device_name'] = 'Linux'
df.loc[df['device_name'].str.contains('XT', na=False), 'device_name'] = 'Sony'
df.loc[df['device_name'].str.contains('HTC', na=False), 'device_name'] = 'HTC'
df.loc[df['device_name'].str.contains('ASUS', na=False), 'device_name'] = 'Asus'
df.loc[df.device_name.isin(df.device_name.value_counts() [df.device_name.value_counts() < 200].index), 'device_name'] = "Others"
df['had_id'] = 1
gc.collect()
return df
train=setDevice(train)
 test=setDevice(test )
logreg = LogisticRegression(solver='liblinear', dual = False)
 logreg.fit(x_train, y_train)
 y_pred = logreg.predict(x_test)
 acc_log = round(logreg.score(x_train, y_train)* 100, 2)
 acc_log
accuracy_score(y_test, y_pred )<choose_model_class>
i_cols = ['card1','card2','card3','card5',
'C1','C2','C3','C4','C5','C6','C7','C8','C9','C10','C11','C12','C13','C14',
'D1','D2','D3','D4','D5','D6','D7','D8',
'addr1','addr2',
'dist1','dist2',
'P_emaildomain', 'R_emaildomain',
'DeviceInfo','device_name',
'id_30','id_33',
'uid','uid2','uid3',
]
for col in i_cols:
temp_df = pd.concat([train[[col]], test[[col]]])
 fq_encode = temp_df[col].value_counts(dropna=False ).to_dict()
train[col+'_fq_enc'] = train[col].map(fq_encode)
 test[col+'_fq_enc'] = test[col].map(fq_encode)
 for col in ['DT_M','DT_W','DT_D']:
temp_df = pd.concat([train[[col]], test[[col]]])
 fq_encode = temp_df[col].value_counts().to_dict()
train[col+'_total'] = train[col].map(fq_encode)
 test[col+'_total'] = test[col].map(fq_encode)
 periods = ['DT_M','DT_W','DT_D']
i_cols = ['uid']
for period in periods:
for col in i_cols:
new_column = col + '_' + period
temp_df = pd.concat([train[[col,period]], test[[col,period]]])
 temp_df[new_column] = temp_df[col].astype(str)+ '_' +(temp_df[period] ).astype(str)
 fq_encode = temp_df[new_column].value_counts().to_dict()
train[new_column] =(train[col].astype(str)+ '_' + train[period].astype(str)).map(fq_encode)
 test[new_column] =(test[col].astype(str)+ '_' + test[period].astype(str)).map(fq_encode)
 train[new_column] /= train[period+'_total']
test[new_column] /= test[period+'_total']
dt = RandomForestClassifier(n_estimators=30, max_depth = 4 )<train_model>
train = train.drop(cols_to_drop, axis=1 )
dt.fit(x_train, y_train )<predict_on_test>
class ModifiedLabelEncoder(LabelEncoder):
def fit_transform(self, y, *args, **kwargs):
return super().fit_transform(y ).reshape(-1, 1)
 def transform(self, y, *args, **kwargs):
return super().transform(y ).reshape(-1, 1 )
y_test_predict = dt.predict(x_test )<compute_test_metric>
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self, attr):
self.attributes = attr
def fit(self, X, y=None):
return self
def transform(self, X):
return X[self.attributes].values
print(classification_report(y_test, y_test_predict))<prepare_x_and_y>
cat_attr = list(train.select_dtypes(include=['object'] ).columns)
 num_attr = list(train.select_dtypes(exclude=['object'] ).columns)
 num_attr.remove('isFraud')
 for col in noisy_cat_cols:
if col in cat_attr:
print("Deleting " + col)
 cat_attr.remove(col)
 for col in noisy_num_cold:
if col in num_attr:
print("Deleting " + col)
 num_attr.remove(col )
x_test = test_data<predict_on_test>
num_pipeline = Pipeline([ 
('selector', DataFrameSelector(num_attr)) , 
('imputer', SimpleImputer(strategy="median")) , 
('scaler', StandardScaler()),
])
 cat_pipeline = Pipeline([ 
('selector', DataFrameSelector(cat_attr)) , 
('imputer', SimpleImputer(strategy="most_frequent")) ,
])
 full_pipeline = FeatureUnion(transformer_list=[ 
('num_pipeline', num_pipeline), 
('cat_pipeline', cat_pipeline),
] )
y_test_predict = dt.predict(test_data )<save_to_csv>
def encodeCategorical(df_train, df_test):
for f in df_train.drop('isFraud', axis=1 ).columns:
if df_train[f].dtype=='object' or df_test[f].dtype=='object':
lbl = preprocessing.LabelEncoder()
lbl.fit(list(df_train[f].values)+ list(df_test[f].values))
df_train[f] = lbl.transform(list(df_train[f].values))
df_test[f] = lbl.transform(list(df_test[f].values))
return df_train, df_test
output_data = pd.DataFrame({'PassengerId' : test_data.PassengerId, 'Survived' : y_test_predict})
 output_data.to_csv('Titanic_Survival_Decision_Tree', index = False)
 print("Submission is successfully" )<import_modules>
y_train = train['isFraud']
train, test = encodeCategorical(train, test )
import pandas as pd
from sklearn.tree import DecisionTreeClassifier<load_from_csv>
X_train = pd.DataFrame(full_pipeline.fit_transform(train))
gc.collect()
train = pd.read_csv('.. /input/titanic/train.csv')
 test = pd.read_csv('.. /input/titanic/test.csv' )<drop_column>
del train
train = train.drop(["Name", "Ticket", "Cabin"], axis=1)
 test = test.drop(["Name", "Ticket", "Cabin"], axis=1 )<categorify>
test = test.drop(cols_to_drop, axis=1)
 test = pd.DataFrame(full_pipeline.transform(test))
new_data_train = pd.get_dummies(train)
 new_data_test = pd.get_dummies(test )<sort_values>
def makePredictions(tr_df, tt_df, target, lgb_params, NFOLDS=2):
folds = KFold(n_splits=NFOLDS, shuffle=True, random_state=SEED)
 X,y = tr_df, y_train
P = tt_df
predictions = np.zeros(len(tt_df))
for fold_,(trn_idx, val_idx)in enumerate(folds.split(X, y)) :
print('Fold:',fold_)
 tr_x, tr_y = X.iloc[trn_idx,:], y[trn_idx]
vl_x, vl_y = X.iloc[val_idx,:], y[val_idx]
print(len(tr_x),len(vl_x))
tr_data = lgb.Dataset(tr_x, label=tr_y)
 vl_data = lgb.Dataset(vl_x, label=vl_y)
 estimator = lgb.train(
 lgb_params,
tr_data,
valid_sets = [tr_data, vl_data],
verbose_eval = 200, 
)
 pp_p = estimator.predict(P)
 predictions += pp_p/NFOLDS
del tr_x, tr_y, vl_x, vl_y, tr_data, vl_data
gc.collect()
tt_df['prediction'] = predictions
return tt_df
new_data_train.isnull().sum().sort_values(ascending=False ).head(10 )<data_type_conversions>
lgb_params = {
'objective':'binary',
'boosting_type':'gbdt',
'metric':'auc',
'n_jobs':-1,
'learning_rate':0.064,
'num_leaves': 2**8,
'max_depth':-1,
'tree_learner':'serial',
'colsample_bytree': 0.7,
'subsample_freq':1,
'subsample':0.7,
'n_estimators':800,
'max_bin':255,
'verbose':-1,
'seed': SEED,
'early_stopping_rounds':100,
}
new_data_train["Age"].fillna(new_data_train["Age"].mean() , inplace=True)
 new_data_test["Age"].fillna(new_data_test["Age"].mean() , inplace=True )<sort_values>
lgb_params['learning_rate'] = 0.005
lgb_params['n_estimators'] = 1800
lgb_params['early_stopping_rounds'] = 100
test_predictions = makePredictions(X_train, test, TARGET, lgb_params, NFOLDS=8 )
new_data_test.isnull().sum().sort_values(ascending=False ).head(10 )<data_type_conversions>
lgb_submission = pd.DataFrame({
"isFraud": test_predictions['prediction'],
} )
<prepare_x_and_y><EOS> 
lgb_submission.insert(0, "TransactionID", np.arange(3663549, 3663549 + 506691))
lgb_submission.to_csv('prediction.csv', index=False )