Kaggle competition: Home Credit Default Risk
<SOS> metric: AUC Kaggle data source: home-credit-default-risk<save_to_csv>
import os
import gc
import numpy as np
import pandas as pd
from scipy.stats import kurtosis
from sklearn.metrics import roc_auc_score
from sklearn.preprocessing import MinMaxScaler
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
from sklearn.model_selection import train_test_split, cross_val_score, StratifiedKFold
import xgboost as xgb
from xgboost import XGBClassifier
os.chdir('/kaggle/working/')
 os.curdir
sol = pd.DataFrame(predictions)
 sol = sol.rename(columns={0:'Action'})
 sol.index = range(1, 58922,1)
 sol = sol.rename_axis('Id')
 sol.to_csv('submission.csv' )<load_pretrained>
DATA_DIRECTORY = ".. /input/home-credit-loan-better-data-processing"
with zipfile.ZipFile('/kaggle/input/sentiment-analysis-on-movie-reviews/train.tsv.zip','r')as zip_ref:
zip_ref.extractall("./sentiment-analysis-on-movie-reviews/")
 with zipfile.ZipFile('/kaggle/input/sentiment-analysis-on-movie-reviews/test.tsv.zip','r')as zip_ref:
zip_ref.extractall("./sentiment-analysis-on-movie-reviews/" )<load_from_csv>
train = pd.read_csv(os.path.join(DATA_DIRECTORY, 'train.csv'))
test = pd.read_csv(os.path.join(DATA_DIRECTORY, 'test.csv'))
labels = pd.read_csv(os.path.join(DATA_DIRECTORY, 'labels.csv'))
data_source=pd.read_table("/kaggle/working/sentiment-analysis-on-movie-reviews/train.tsv",sep='\t')
 data_source=data_source[['Phrase','Sentiment']].copy()
data_source<string_transform>
train = train.rename(columns = lambda x:re.sub('[^A-Za-z0-9_]+', '', x))
test = test.rename(columns = lambda x:re.sub('[^A-Za-z0-9_]+', '', x))
labels = labels.rename(columns = lambda x:re.sub('[^A-Za-z0-9_]+', '', x))
dff=[len(i.split(" ")) for i in data_source.Phrase[:10]]
max(dff )<import_modules>
train=np.nan_to_num(train)
 test=np.nan_to_num(test)
 labels=np.nan_to_num(labels )
from transformers import TFBertModel, BertConfig, BertTokenizerFast, TFAutoModel
from tensorflow.keras.layers import Input, Dropout, Dense
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.initializers import TruncatedNormal
from tensorflow.keras.losses import CategoricalCrossentropy
from tensorflow.keras.metrics import CategoricalAccuracy
from tensorflow.keras.utils import to_categorical
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import tensorflow as tf
from sklearn.model_selection import train_test_split<split>
train = pd.DataFrame(train)
 test = pd.DataFrame(test)
 labels=pd.DataFrame(labels )
X_train_data, X_validation_data, y_train_data, y_validation_data = train_test_split(data_source.index.values,
data_source.Sentiment.values,
test_size=0.10,
random_state=42,
stratify=data_source.Sentiment)
<feature_engineering>
X_train, X_test, y_train, y_test = train_test_split(train, labels, random_state=42 )
data_source['data_type'] = ['not_set']*data_source.shape[0]
data_source.loc[X_train_data, 'data_type'] = 'training'
data_source.loc[X_validation_data, 'data_type'] = 'validation'<count_missing_values>
clf = DummyClassifier(strategy= 'most_frequent' ).fit(X_train,y_train)
 y_pred = clf.predict(X_test)
 print('y actual :
' + str(y_test.value_counts()))
print('y predicted :
' + str(pd.Series(y_pred ).value_counts()))
data_source.isnull().sum()<filter>
print('Accuracy Score : ' + str(accuracy_score(y_test,y_pred)))
 print('Precision Score : ' + str(precision_score(y_test,y_pred)))
 print('Recall Score : ' + str(recall_score(y_test,y_pred)))
 print('F1 Score : ' + str(f1_score(y_test,y_pred)))
 print('Confusion Matrix :
' + str(confusion_matrix(y_test,y_pred)) )
data_source[data_source.data_type=='training'].Phrase<load_pretrained>
clf = LGBMClassifier().fit(X_train,y_train)
 y_pred = clf.predict(X_test)
 print('Accuracy Score : ' + str(accuracy_score(y_test,y_pred)))
 print('Precision Score : ' + str(precision_score(y_test,y_pred)))
 print('Recall Score : ' + str(recall_score(y_test,y_pred)))
 print('F1 Score : ' + str(f1_score(y_test,y_pred)))
 print('Confusion Matrix :
' + str(confusion_matrix(y_test,y_pred)) )
max_token_length = max(dff)+3
number_of_samples = len(data_source)
 bert = 'bert-base-cased'
config = BertConfig.from_pretrained(bert)
 config.output_hidden_states = False
tokenizer = BertTokenizerFast.from_pretrained(pretrained_model_name_or_path = bert, config = config)
<categorify>
clf = LogisticRegression()
grid_values = {'penalty': ['l2'],'C':[0.001,.009,0.01,.09,1,5,10,25]}
grid_clf_acc = GridSearchCV(clf, param_grid = grid_values,scoring = 'recall')
 grid_clf_acc.fit(X_train, y_train)
 y_pred_acc = grid_clf_acc.predict(X_test)
 print('Accuracy Score : ' + str(accuracy_score(y_test,y_pred_acc)))
 print('Precision Score : ' + str(precision_score(y_test,y_pred_acc)))
 print('Recall Score : ' + str(recall_score(y_test,y_pred_acc)))
 print('F1 Score : ' + str(f1_score(y_test,y_pred_acc)))
 confusion_matrix(y_test,y_pred_acc )
def map_function(input_ids, masks,labels):
return {'input_ids': input_ids, 'attention_mask': masks},labels<categorify>
pred = model.predict_proba(df_test )
<categorify><EOS> 
submit = test[['SK_ID_CURR']]
submit['TARGET'] = pred
submit.to_csv('lgbm_Minimized_code.csv', index = False )