Kaggle competition: Home Credit Default Risk
data = pd.read_csv('.. /input/nlp-getting-started/train.csv' )<string_transform>
%matplotlib inline
warnings.filterwarnings('ignore')
 pd.set_option('display.max_rows', 100)
 pd.set_option('display.max_columns', 200 )
def create_corpus(target):
corpus = []
for i in data[data['target']==target]['text'].str.split() :
for x in i:
corpus.append(x)
 return corpus<categorify>
app_train = pd.read_csv('.. /input/home-credit-default-risk/application_train.csv')
 app_test = pd.read_csv('.. /input/home-credit-default-risk/application_test.csv' )
lemmatizer = WordNetLemmatizer()
def preprocess_data(data):
text = re.sub(r'https?://\S+|www\.\S+|http?://\S+',' ',data)
 text = re.sub(r"won't", " will not", text)
 text = re.sub(r"won't've", " will not have", text)
 text = re.sub(r"can't", " can not", text)
 text = re.sub(r"don't", " do not", text)
 text = re.sub(r"can't've", " can not have", text)
 text = re.sub(r"ma'am", " madam", text)
 text = re.sub(r"let's", " let us", text)
 text = re.sub(r"ain't", " am not", text)
 text = re.sub(r"shan't", " shall not", text)
 text = re.sub(r"sha
't", " shall not", text)
 text = re.sub(r"o'clock", " of the clock", text)
 text = re.sub(r"y'all", " you all", text)
 text = re.sub(r"n't", " not", text)
 text = re.sub(r"n't've", " not have", text)
 text = re.sub(r"'re", " are", text)
 text = re.sub(r"'s", " is", text)
 text = re.sub(r"'d", " would", text)
 text = re.sub(r"'d've", " would have", text)
 text = re.sub(r"'ll", " will", text)
 text = re.sub(r"'ll've", " will have", text)
 text = re.sub(r"'t", " not", text)
 text = re.sub(r"'ve", " have", text)
 text = re.sub(r"'m", " am", text)
 text = re.sub(r"'re", " are", text)
 text = re.sub(r'<.*?>',' ',text)
 text = re.sub(r'[0-9]', '', text)
 text = re.sub("["
u"\U0001F600-\U0001F64F"
u"\U0001F300-\U0001F5FF"
u"\U0001F680-\U0001F6FF"
u"\U0001F1E0-\U0001F1FF"
u"\U00002702-\U000027B0"
u"\U000024C2-\U0001F251"
"]+",' ',text)
 text = re.sub('[^a-zA-Z]',' ',text)
 text = re.sub(r"\([^() ]*\)", "", text)
 text = re.sub('@\S+', '', text)
 text = re.sub('[%s]' % re.escape (<feature_engineering>
print('Training data shape: ', app_train.shape)
 app_train.head()
common_words = ['via','like','build','get','would','one','two','feel',
'lol','fuck','take','way','may','first','latest','want',
'make','back','see','know','let','look','come','got',
'still','say','think','great','pleas','amp']
def text_cleaning(data):
return ' '.join(i for i in data.split() if i not in common_words)
 data["Cleaned_text"] = data["Cleaned_text"].apply(text_cleaning )<features_selection>
app_train['TARGET'].value_counts()
def top_ngrams(data,n,grams):
count_vec = CountVectorizer(ngram_range=(grams,grams)).fit(data)
 bow = count_vec.transform(data)
 add_words = bow.sum(axis=0)
 word_freq = [(word, add_words[0, idx])for word, idx in count_vec.vocabulary_.items() ]
word_freq = sorted(word_freq, key = lambda x: x[1], reverse=True)
 return word_freq[:n]<create_dataframe>
app_train.dtypes.value_counts()
common_uni = top_ngrams(data["Cleaned_text"],10,1)
 common_bi = top_ngrams(data["Cleaned_text"],10,2)
 common_tri = top_ngrams(data["Cleaned_text"],10,3)
 common_uni_df = pd.DataFrame(common_uni,columns=['word','freq'])
 common_bi_df = pd.DataFrame(common_bi,columns=['word','freq'])
 common_tri_df = pd.DataFrame(common_tri,columns=['word','freq'] )<prepare_x_and_y>
np.linspace(20,70,num=11 )
X_inp_clean = data['Cleaned_text']
X_inp_original = data['text']
y_inp = data['target']<train_model>
age_data=app_train[['TARGET','DAYS_BIRTH']]
age_data['DAYS_BIRTH']=-age_data['DAYS_BIRTH']
age_data['YEARS_BIRTH']=age_data['DAYS_BIRTH']/365
age_data['YEARS_BINNED']=pd.cut(age_data['YEARS_BIRTH'],bins=np.linspace(20,70,num=11))
age_data.head(10 )
word_tokenizer = Tokenizer()
word_tokenizer.fit_on_texts(X_inp_clean.values)
 vocab_length = len(word_tokenizer.word_index)+ 1<string_transform>
age_groups = age_data.groupby('YEARS_BINNED' ).mean()
age_groups
def embed(corpus):
return word_tokenizer.texts_to_sequences(corpus)
 longest_train = max(X_inp_clean.values, key=lambda sentence: len(word_tokenize(sentence)))
 length_long_sentence = len(word_tokenize(longest_train))
padded_sentences = pad_sequences(embed(X_inp_clean.values),
length_long_sentence, padding='post' )<feature_engineering>
anom = app_train[app_train['DAYS_EMPLOYED'] == 365243]
non_anom = app_train[app_train['DAYS_EMPLOYED'] != 365243]
print('이상값이 아닌 data의 target 평균: %0.2f%%' %(100 * non_anom['TARGET'].mean()))
print('이상값인 data의 target 평균: %0.2f%%' %(100 * anom['TARGET'].mean()))
embeddings_dictionary = dict()
embedding_dim = 100
glove_file = open('.. /input/glove6b100dtxt/glove.6B.100d.txt')
 for line in glove_file:
records = line.split()
word = records[0]
vector_dimensions = np.asarray(records[1:], dtype='float32')
 embeddings_dictionary [word] = vector_dimensions
glove_file.close()<feature_engineering>
app_test['DAYS_EMPLOYED_ANOM']=app_test['DAYS_EMPLOYED']==365243
app_test['DAYS_EMPLOYED'].replace({365243:np.nan}, inplace=True)
 print('%d 개의 data 중에 testing data에서 %d 개의 이상값이 있다.'%(len(app_test),app_test['DAYS_EMPLOYED_ANOM'].sum()))
embedding_matrix = np.zeros(( vocab_length, embedding_dim))
for word, index in word_tokenizer.word_index.items() :
embedding_vector = embeddings_dictionary.get(word)
 if embedding_vector is not None:
embedding_matrix[index] = embedding_vector<split>
app_train['DAYS_BIRTH'] = app_train['DAYS_BIRTH'] / -365
app_test['DAYS_BIRTH'] = app_test['DAYS_BIRTH'] / -365
ext=app_train[['TARGET','EXT_SOURCE_1','EXT_SOURCE_2','EXT_SOURCE_3','DAYS_BIRTH']]
extcorr = ext.corr()
extcorr
X_train, X_val, y_train, y_val = train_test_split(padded_sentences,
y_inp.values,test_size=0.2,random_state=1 )<choose_model_class>
app_train.dtypes.value_counts()
def CNN(hp):
model = keras.Sequential()
hp_learning_rate = hp.Choice('learning_rate', values=[3e-2, 3e-3, 3e-4, 3e-5])
 model.add(Embedding(vocab_length, 100, weights=[embedding_matrix],
input_length=length_long_sentence,trainable=False))
model.add(Conv1D(filters=hp.Int('conv_1_filter',min_value=21,max_value=200,step=14),
kernel_size=hp.Choice('conv_1_kernel',values=[3,4,5]),
activation='relu'))
model.add(Dropout(0.3))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
 model.add(Dense(units = hp.Int('dense_1',min_value=21,max_value=150,step=14),
activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1,activation='sigmoid'))
model.compile(optimizer=keras.optimizers.Adam(learning_rate=hp_learning_rate),
loss=keras.losses.BinaryCrossentropy(from_logits=True),
metrics=['accuracy'])
 return model<choose_model_class>
object_columns = app_train.dtypes[app_train.dtypes == 'object'].index.tolist()
object_columns
tuner_CNN = kt.Hyperband(CNN,objective='val_accuracy',
max_epochs=15,factor=5,
directory='my_dir',
project_name='DisasterTweets_kt',
overwrite=True )<train_on_grid>
cond_1 =(app_train['TARGET'] == 1)
 cond_0 =(app_train['TARGET'] == 0)
 for a in obj:
print(a)
 print('
연체인 경우
',app_train[cond_1][a].value_counts() /app_train[cond_1].shape[0])
 print('
연체가 아닌 경우
',app_train[cond_0][a].value_counts() /app_train[cond_0].shape[0])
 print('----------------------------' )
stop_early = EarlyStopping(monitor='val_loss', mode='min',
verbose=1, patience=10)
 tuner_CNN.search(X_train, y_train, epochs=15,
validation_data=(X_val,y_val),callbacks=[stop_early])
 best_hps_CNN=tuner_CNN.get_best_hyperparameters(num_trials=1)[0]<train_model>
def missing_values_table(df):
miss = df.isnull().sum()
miss_percent = 100 * miss / len(df)
 mis_table = pd.concat([miss, miss_percent], axis=1)
 mis_val_table = mis_table.rename(
 columns = {0 : 'Missing Values', 1 : '% of Total Values'})
 mis_val_table = mis_val_table[
mis_val_table.iloc[:,1] != 0].sort_values(
 '% of Total Values', ascending=False ).round(1)
 print("선택된 데이터프레임은 " + str(df.shape[1])+ "개의 컬럼이 있다.
 "
"그중에서 " + str(mis_val_table.shape[0])+
" 개는 결측값이 있는 컬럼이다.")
 return mis_val_table
model_CNN = tuner_CNN.hypermodel.build(best_hps_CNN)
 checkpoint = ModelCheckpoint(
 'model_CNN.h5',
monitor = 'val_loss',
verbose = 1,
save_best_only = True 
)
 history_CNN = model_CNN.fit(X_train, y_train,epochs=50,
validation_data=(X_val,y_val),
callbacks=[checkpoint,stop_early] )<choose_model_class>
missing_values = missing_values_table(app_train)
 missing_values.head(20 )
def MultichannelCNN(hp):
inputs1 = Input(shape=(length_long_sentence,))
embedding1 = Embedding(vocab_length, 100, weights=[embedding_matrix],
input_length=length_long_sentence, trainable=False )(inputs1)
 conv1 = Conv1D(filters=hp.Int('conv_1_filter',min_value=21,max_value=150,step=14),
kernel_size=hp.Choice('conv_1_kernel',values=[3,4,5,6,7,8]),
activation='relu' )(embedding1)
 drop1 = Dropout(0.3 )(conv1)
 pool1 = MaxPooling1D()(drop1)
 flat1 = Flatten()(pool1)
 inputs2 = Input(shape=(length_long_sentence,))
embedding2 = Embedding(vocab_length, 100, weights=[embedding_matrix],
input_length=length_long_sentence,trainable=False )(inputs2)
 conv2 = Conv1D(filters=hp.Int('conv_2_filter',min_value=21,max_value=150,step=14),
kernel_size=hp.Choice('conv_2_kernel',values=[3,4,5,6,7,8]),
activation='relu' )(embedding2)
 drop2 = Dropout(0.3 )(conv2)
 pool2 = MaxPooling1D()(drop2)
 flat2 = Flatten()(pool2)
 merged = concatenate([flat1, flat2])
 dense1 = Dense(units = hp.Int('dense_1',min_value=21,max_value=120,step=14),
activation='relu' )(merged)
 drop4 = Dropout(0.5 )(dense1)
 outputs = Dense(1, activation='sigmoid' )(drop4)
 model = Model(inputs=[inputs1, inputs2], outputs=outputs)
 hp_learning_rate = hp.Choice('learning_rate', values=[3e-2, 3e-3, 3e-4, 3e-5])
 model.compile(optimizer=keras.optimizers.Adam(learning_rate=hp_learning_rate),
loss=keras.losses.BinaryCrossentropy(from_logits=True),
metrics=['accuracy'])
 return model<train_on_grid>
apps = pd.concat([app_train,app_test])
 print(apps.shape )
tuner_MCNN = kt.Hyperband(MultichannelCNN,objective='val_accuracy',
max_epochs=15,factor=5,
directory='my_dir',
project_name='DisasterTweetsMCNN_kt',
overwrite=True)
 stop_early = EarlyStopping(monitor='val_loss', mode='min',
verbose=1, patience=10)
 tuner_MCNN.search([X_train,X_train], y_train, epochs=15,
validation_data=([X_val,X_val], y_val),
callbacks=[stop_early])
 best_hps_MCNN=tuner_MCNN.get_best_hyperparameters(num_trials=1)[0]<train_model>
apps['TARGET'].value_counts(dropna=False )
model_MCNN = tuner_MCNN.hypermodel.build(best_hps_MCNN)
 checkpoint = ModelCheckpoint(
 'model_MCNN.h5',
monitor = 'val_loss',
verbose = 1,
save_best_only = True 
)
 history_MCNN = model_MCNN.fit([X_train,X_train], y_train,epochs=50,
validation_data=([X_val,X_val], y_val),
callbacks=[checkpoint,stop_early] )<choose_model_class>
object_col = apps.dtypes[apps.dtypes == 'object'].index.tolist()
for column in object_col:
apps[column] = pd.factorize(apps[column])[0]
def BiLSTM(hp):
model = Sequential()
model.add(Embedding(input_dim=embedding_matrix.shape[0],
output_dim=embedding_matrix.shape[1],
weights = [embedding_matrix],
input_length=length_long_sentence,trainable = False))
model.add(Bidirectional(CuDNNLSTM(units = hp.Int('dense_1',
min_value=21,max_value=120,step=14)
 ,return_sequences = True)))
 model.add(GlobalMaxPool1D())
 model.add(BatchNormalization())
 model.add(Dropout(0.2))
model.add(Dense(units = hp.Int('dense_1',min_value=21,
max_value=120,step=14),
activation = "relu"))
model.add(Dropout(0.3))
model.add(Dense(units = hp.Int('dense_1',min_value=21,
max_value=100,step=14),
activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(1, activation = 'sigmoid'))
hp_learning_rate = hp.Choice('learning_rate',
values=[3e-2, 3e-3, 3e-4, 3e-5])
 model.compile(optimizer=keras.optimizers.Adam(learning_rate=hp_learning_rate),
loss=keras.losses.BinaryCrossentropy(from_logits=True),
metrics=['accuracy'])
 return model<train_model>
apps['CREDIT_INCOME_PERCENT'] = apps['AMT_CREDIT'] / apps['AMT_INCOME_TOTAL']
apps['ANNUITY_INCOME_PERCENT'] = apps['AMT_ANNUITY'] / apps['AMT_INCOME_TOTAL']
apps['CREDIT_TERM'] = apps['AMT_ANNUITY'] / apps['AMT_CREDIT']
apps['GOODS_CREDIT_RATIO'] = apps['AMT_GOODS_PRICE']/apps['AMT_CREDIT']
apps['CREDIT_GOODS_DIFF'] = apps['AMT_CREDIT'] - apps['AMT_GOODS_PRICE']
apps['GOODS_INCOME_RATIO'] = apps['AMT_GOODS_PRICE']/apps['AMT_INCOME_TOTAL']
tuner_BiLSTM = kt.Hyperband(BiLSTM,objective='val_accuracy',
max_epochs=15,factor=5,
directory='my_dir',
project_name='DisasterTweetsBiLSTM_kt',
overwrite=True)
 stop_early = EarlyStopping(monitor='val_loss', mode='min',
verbose=1, patience=12)
 tuner_BiLSTM.search(X_train, y_train, epochs=15,
validation_data=(X_val, y_val),
callbacks=[stop_early])
 best_hps_BiLSTM=tuner_BiLSTM.get_best_hyperparameters(num_trials=1)[0]<train_model>
apps['APPS_EXT_SOURCE_MEAN'] = apps[['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']].mean(axis=1)
 apps['APPS_EXT_SOURCE_STD'] = apps[['EXT_SOURCE_1', 'EXT_SOURCE_2', 'EXT_SOURCE_3']].std(axis=1 )
model_BiLSTM = tuner_BiLSTM.hypermodel.build(best_hps_BiLSTM)
 checkpoint = ModelCheckpoint(
 'model_BiLSTM.h5',
monitor = 'val_loss',
verbose = 1,
save_best_only = True 
)
 history_BiLSTM = model_BiLSTM.fit(X_train, y_train, epochs=50,
validation_data=(X_val, y_val),
callbacks=[checkpoint,stop_early] )<categorify>
apps['APPS_EXT_SOURCE_STD'] = apps['APPS_EXT_SOURCE_STD'].fillna(apps['APPS_EXT_SOURCE_STD'].mean() )
onehot_encoder = OneHotEncoder(sparse=False)
 y =(np.asarray(y_inp)).reshape(-1,1)
 Y = onehot_encoder.fit_transform(y)
 X_train, X_val, y_train, y_val = train_test_split(X_inp_clean,Y,
test_size=0.2, random_state=1 )<load_pretrained>
apps['EMPLOYED_BIRTH_RATIO'] = apps['DAYS_EMPLOYED']/apps['DAYS_BIRTH']
apps['INCOME_EMPLOYED_RATIO'] = apps['AMT_INCOME_TOTAL']/apps['DAYS_EMPLOYED']
apps['INCOME_BIRTH_RATIO'] = apps['AMT_INCOME_TOTAL']/apps['DAYS_BIRTH']
apps['CAR_BIRTH_RATIO'] = apps['OWN_CAR_AGE'] / apps['DAYS_BIRTH']
apps['CAR_EMPLOYED_RATIO'] = apps['OWN_CAR_AGE'] / apps['DAYS_EMPLOYED']
model_checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_fast=True )<define_variables>
ccb = pd.read_csv('.. /input/home-credit-default-risk/credit_card_balance.csv' )
tokenizer("Hello, this one sentence!", "And this sentence goes with it." )<categorify>
app_ccb = ccb.merge(app_train, left_on='SK_ID_CURR', right_on='SK_ID_CURR', how='outer')
 app_ccb.shape
def regular_encode(texts, tokenizer, maxlen=512):
enc_di = tokenizer.batch_encode_plus(
 texts,
return_token_type_ids=False,
pad_to_max_length=True,
max_length=maxlen,
add_special_tokens = True,
truncation=True 
)
 return np.array(enc_di['input_ids'])
 X_train_t = regular_encode(list(X_train), tokenizer, maxlen=512)
 X_val_t = regular_encode(list(X_val), tokenizer, maxlen=512 )<define_variables>
missing_values = missing_values_table(ccb)
 missing_values.head(20 )
AUTO = tf.data.experimental.AUTOTUNE
batch_size = 16
train_dataset =(
 tf.data.Dataset 
.from_tensor_slices(( X_train_t, y_train)) 
.repeat() 
.shuffle(1995)
.batch(batch_size)
.prefetch(AUTO)
)
 valid_dataset =(
 tf.data.Dataset 
.from_tensor_slices(( X_val_t, y_val)) 
.batch(batch_size)
.cache() 
.prefetch(AUTO)
 )<choose_model_class>
app_ccb.groupby('SK_ID_CURR' ).count()
def build_model(transformer, max_len=512):
input_word_ids = Input(shape=(max_len,), dtype=tf.int32,
name="input_word_ids")
 sequence_output = transformer(input_word_ids)[0]
cls_token = sequence_output[:, 0, :]
out = Dense(2, activation='softmax' )(cls_token)
 model = Model(inputs=input_word_ids, outputs=out)
 model.compile(optimizer=keras.optimizers.Adam(lr=1e-5),
loss='categorical_crossentropy', metrics=['accuracy'])
 return model<load_pretrained>
app_ccb.groupby('SK_ID_CURR')['SK_ID_CURR'].count()
transformer_layer = TFAutoModel.from_pretrained(model_checkpoint)
 model_DistilBert = build_model(transformer_layer )<train_model>
app_ccb_target = ccb.merge(app_train[['SK_ID_CURR', 'TARGET']], on='SK_ID_CURR', how='left')
 app_ccb_target.shape
n_steps = X_train.shape[0] // batch_size
history_DistilBert = model_DistilBert.fit(train_dataset,
steps_per_epoch=n_steps,
validation_data=valid_dataset,
epochs=3 )<feature_engineering>
num_columns = app_ccb_target.dtypes[app_ccb_target.dtypes != 'object'].index.tolist()
test = pd.read_csv('.. /input/nlp-getting-started/test.csv')
 test["Cleaned_text"] = test["text"].apply(preprocess_data)
 test["Cleaned_text"] = test["Cleaned_text"].apply(text_cleaning)
 test_sentences = pad_sequences(embed(test.Cleaned_text.values),
length_long_sentence, padding='post' )<save_to_csv>
num_columns = [column for column in num_columns if column not in ['SK_ID_PREV', 'SK_ID_CURR', 'TARGET']]
num_columns
predsCNN = model_CNN.predict_classes(test_sentences)
 predictions_test = pd.DataFrame(predsCNN)
 test_id = pd.DataFrame(test["id"])
 submissionCNN = pd.concat([test_id,predictions_test],axis=1)
 submissionCNN.columns = ["id","target"]
submissionCNN.to_csv("submissionCNN.csv",index=False )<save_to_csv>
print(app_ccb_target.groupby('TARGET' ).agg({'AMT_BALANCE': ['mean', 'median', 'count','sum','max']}))
print(app_ccb_target.groupby('TARGET' ).agg({'AMT_CREDIT_LIMIT_ACTUAL': ['mean', 'median', 'count','sum','max']}))
print(app_ccb_target.groupby('TARGET' ).agg({'AMT_INST_MIN_REGULARITY': ['mean', 'median', 'count','sum','max']}))
print(app_ccb_target.groupby('TARGET' ).agg({'CNT_INSTALMENT_MATURE_CUM': ['mean', 'median', 'count','sum','max']}))
print(app_ccb_target.groupby('TARGET' ).agg({'AMT_INST_MIN_REGULARITY': ['mean', 'median', 'count','sum','max']}))
print(app_ccb_target.groupby('TARGET' ).agg({'AMT_CREDIT_LIMIT_ACTUAL': ['mean', 'median', 'count','sum','max']}))
predsMCNN = model_MCNN.predict([test_sentences,test_sentences])
 predsMCNN =(predsMCNN[:,0] > 0.5 ).astype(np.int)
 predictions_test = pd.DataFrame(predsMCNN)
 submissionMCNN = pd.concat([test_id,predictions_test],axis=1)
 submissionMCNN.columns = ["id","target"]
submissionMCNN.to_csv("submissionMCNN.csv",index=False )<save_to_csv>
ccb_amt_agg=ccb_amt_agg.reset_index()
ccb_amt_agg
predsBiLSTM = model_BiLSTM.predict(test_sentences)
 predsBiLSTM =(predsBiLSTM[:,0] > 0.5 ).astype(np.int)
 predictions_test = pd.DataFrame(predsBiLSTM)
 submissionBiLSTM = pd.concat([test_id,predictions_test],axis=1)
 submissionBiLSTM.columns = ["id","target"]
submissionBiLSTM.to_csv("submissionBiLSTM.csv",index=False )<save_to_csv>
ccb_amt_agg=ccb_amt_agg.drop(['CCB_SK_ID_CURR_COUNT'],axis=1)
 ccb_amt_agg
X_test = regular_encode(list(test.Cleaned_text), tokenizer, maxlen=512)
 test1 =(tf.data.Dataset.from_tensor_slices(X_test ).batch(batch_size))
pred = model_DistilBert.predict(test1,verbose = 0)
 pred = np.argmax(pred,axis=-1)
 pred = pred.astype('int32')
 res=pd.read_csv('.. /input/nlp-getting-started/sample_submission.csv',index_col=None)
 res['target'] = pred
res.to_csv('submissionDistilBert.csv',index=False )<install_modules>
apps = apps.merge(ccb_amt_agg, left_on='SK_ID_CURR', right_on='SK_ID_CURR', how='left')
 app_ccb.shape
!pip install -U lightautoml<import_modules>
object_col = apps.dtypes[apps.dtypes == 'object'].index.tolist()
for column in object_col:
apps[column] = pd.factorize(apps[column])[0]
from lightautoml.automl.presets.tabular_presets import TabularAutoML, TabularUtilizedAutoML
from lightautoml.dataset.roles import DatetimeRole, CategoryRole
from lightautoml.tasks import Task
from sklearn.metrics import classification_report, roc_auc_score<load_from_csv>
apps_train = apps[~apps['TARGET'].isnull() ]
apps_test = apps[apps['TARGET'].isnull() ]
apps.shape, apps_train.shape, apps_test.shape
train_df = pd.read_csv('.. /input/cat-in-the-dat/train.csv')
 test_df = pd.read_csv('.. /input/cat-in-the-dat/test.csv')
 submission_df = pd.read_csv('.. /input/cat-in-the-dat/sample_submission.csv' )<define_variables>
ftr_app = apps_train.drop(['SK_ID_CURR', 'TARGET'], axis=1)
 target_app = apps_train['TARGET']
train_x, valid_x, train_y, valid_y = train_test_split(ftr_app, target_app, test_size=0.3, random_state=2020)
 train_x.shape, valid_x.shape
N_THREADS = 4
N_FOLDS = 5
RANDOM_STATE = 42
TEST_SIZE = 0.2
TIMEOUT = 1800
TARGET_NAME = 'target'
np.random.seed(RANDOM_STATE )<data_type_conversions>
clf = LGBMClassifier(
 n_jobs=-1,
n_estimators=1000,
learning_rate=0.02,
num_leaves=32,
subsample=0.8,
max_depth=12,
silent=-1,
verbose=-1 
)
 clf.fit(train_x, train_y, eval_set=[(train_x, train_y),(valid_x, valid_y)], eval_metric= 'auc', verbose= 100,
early_stopping_rounds= 100 )
def preprocess(df):
df['time'] =(np.datetime64('2018-01-01')+ df['day'].astype(np.dtype('timedelta64[D]')) + df['month'].astype(np.dtype('timedelta64[M]')) ).astype(str)
 return df.drop(columns=['id', 'day', 'month'])
 train = preprocess(train_df)
 test = preprocess(test_df )<drop_column>
preds = clf.predict_proba(apps_test.drop(['SK_ID_CURR', 'TARGET'], axis=1)) [:, 1 ]
task = Task('binary',)
 roles = {'target': TARGET_NAME,
DatetimeRole(base_date=True, seasonality=('m', 'd', 'wd', 'hour'), base_feats=True): 'time',
CategoryRole(ordinal=False): ['bin_0', 'bin_1', 'bin_2', 'bin_3', 'bin_4', 'nom_0', 'nom_1', 'nom_2', 'nom_3', 'nom_4', 'nom_5', 'nom_6', 'nom_7', 'nom_8', 'nom_9',],
CategoryRole(ordinal=True): ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5',],
}<choose_model_class>
apps_test['TARGET'] = preds
apps_test[['SK_ID_CURR', 'TARGET']].to_csv('apps_baseline05.csv', index=False )