Kaggle competition: Predicting Red Hat Business Value
<SOS> metric: AUC Kaggle data source: predicting-red-hat-business-value<install_modules>
import numpy as np
import pandas as pd
import xgboost as xgb
!pip install -q efficientnet<import_modules>
def cleanPeople(people):
people = people.drop(['date'],axis=1)
 people['people_id'] = people['people_id'].apply(lambda x : x.split('_')[1])
 people['people_id'] = pd.to_numeric(people['people_id'] ).astype(int)
 fields = list(people.columns)
 cat_data = fields[1:11]
bool_data = fields[11:]
for data in cat_data:
people[data] = people[data].fillna('type 0')
 people[data] = people[data].apply(lambda x: x.split(' ')[1])
 people[data] = pd.to_numeric(people[data] ).astype(int)
 for data in bool_data:
people[data] = pd.to_numeric(people[data] ).astype(int)
 return people
def cleanAct(data, train=False):
data = data.drop(['date'],axis = 1)
 if train:
data = data.drop(['outcome'],axis=1)
 data['people_id'] = data['people_id'].apply(lambda x : x.split('_')[1])
 data['people_id'] = pd.to_numeric(data['people_id'] ).astype(int)
 data['activity_id'] = data['activity_id'].apply(lambda x: x.split('_')[1])
 data['activity_id'] = pd.to_numeric(data['activity_id'] ).astype(int)
 fields = list(data.columns)
 cat_data = fields[2:13]
for column in cat_data:
data[column] = data[column].fillna('type 0')
 data[column] = data[column].apply(lambda x : x.split(' ')[1])
 data[column] = pd.to_numeric(data[column] ).astype(int)
 return data
people = pd.read_csv(".. /input/people.csv")
 people = cleanPeople(people)
 act_train = pd.read_csv(".. /input/act_train.csv",parse_dates=['date'])
 act_train_cleaned = cleanAct(act_train,train=True)
 act_test = pd.read_csv(".. /input/act_test.csv",parse_dates=['date'])
 act_test_cleaned = cleanAct(act_test)
 train = act_train_cleaned.merge(people,on='people_id', how='left')
 test = act_test_cleaned.merge(people, on='people_id', how='left')
 train = train.drop(['people_id'],axis=1)
 train = train.drop(['activity_id'],axis=1)
 test = test.drop(['people_id','activity_id'],axis=1)
 output = act_train['outcome']
X_train, X_test, y_train, y_test = train_test_split(train,output, test_size=0.2, random_state =7 )
import re
import cv2
import math
import time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from tqdm import tqdm_notebook as tqdm
from sklearn.model_selection import train_test_split
from kaggle_datasets import KaggleDatasets
import tensorflow as tf
import tensorflow.keras.backend as K
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Model,Sequential
from tensorflow.keras import optimizers
import efficientnet.tfkeras as efn<train_on_grid>
model = xgb.XGBClassifier(max_depth=8,n_estimators=500,learning_rate=0.1,objective='binary:logistic',seed =7,reg_lambda=1 )
AUTO = tf.data.experimental.AUTOTUNE
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)
 DATASET = '384x384-melanoma-tfrecords-70k-images'
GCS_PATH = KaggleDatasets().get_gcs_path(DATASET )<define_variables>
model.fit(X_train,y_train )
SEED = 42
BATCH_SIZE = 8 * strategy.num_replicas_in_sync
SIZE = [384,384]
LR = 0.00004
EPOCHS = 15
WARMUP = 5
WEIGHT_DECAY = 0
LABEL_SMOOTHING = 0.05
TTA = 4<define_variables>
results = model.predict_proba(X_test)
 s = results[:,1]
score = roc_auc_score(y_test,s)
 print(score )
<split><EOS> 
results = model.predict_proba(test)
 s = results[:,1]
activity = act_test['activity_id']
result = pd.DataFrame({'activity_id': activity, 'outcome': s})
 result.to_csv("Result.csv",index=False )