Kaggle competition: Tabular Playground Series - Jan 2021
%reset -f<set_options>
filterwarnings('ignore' )
!pip install GPUtil
def free_gpu_cache() :
print("Initial GPU Usage")
 gpu_usage()
torch.cuda.empty_cache()
cuda.select_device(0)
 cuda.close()
cuda.select_device(0)
 for obj in gc.get_objects() :
if torch.is_tensor(obj):
del obj
gc.collect()
print("GPU Usage after emptying the cache")
 gpu_usage()
free_gpu_cache()<import_modules>
train = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/train.csv',index_col = 'id')
 print('shape : {} '.format(train.shape))
train.head()
import re
import torch
from transformers import ElectraTokenizer, ElectraForSequenceClassification,AdamW
import torch
from sklearn.metrics import classification_report
import random
import time
import datetime
import numpy as np
import pandas as pd
from transformers import get_linear_schedule_with_warmup
from torch.utils.data import TensorDataset, DataLoader, RandomSampler, SequentialSampler
from sklearn.model_selection import train_test_split<set_options>
x = train.drop('target',axis=1)
 y = train['target']
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = 0.25,random_state = 42 )
if torch.cuda.is_available() :
device = torch.device("cuda")
 print('We will use the GPU:', torch.cuda.get_device_name(0))
else:
print('No GPU available, using the CPU instead.')
 device = torch.device("cpu" )<load_from_csv>
regressor = xgb.XGBRegressor(
 colsample_bytree=0.5,
alpha=0.01563,
learning_rate=0.01,
max_depth=15,
min_child_weight=257,
n_estimators=4000,
reg_lambda=0.003,
subsample=0.7,
random_state=2020,
metric_period=100,
silent=1)
 regressor.fit(x_train, y_train, early_stopping_rounds=6, eval_set=[(x_test, y_test)], verbose=1 )
train = pd.read_csv(".. /input/nlp-getting-started/train.csv")
 test = pd.read_csv(".. /input/nlp-getting-started/test.csv")
 df_train= train
df_test= test<categorify>
df_test = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/test.csv',index_col = 'id' )
def preprocess(text):
text=text.lower()
text = re.sub(r'https?:\/\/.*[\r
]*', '', text)
 text = re.sub(r'http?:\/\/.*[\r
]*', '', text)
 text=text.replace(r'&amp;?',r'and')
 text=text.replace(r'&lt;',r'<')
 text=text.replace(r'&gt;',r'>')
 text = re.sub(r"(?:\@)\w+", '', text)
 text=text.encode("ascii",errors="ignore" ).decode()
text=re.sub(r'[:"
text=re.sub(r'[!]+','!',text)
 text=re.sub(r'[?]+','?',text)
 text=re.sub(r'[.]+','.',text)
 text=re.sub(r"'","",text)
 text=re.sub(r"\(","",text)
 text=re.sub(r"\)","",text)
 text=" ".join(text.split())
 return text
df_train['text'] = df_train['text'].apply(preprocess)
 df_test['text'] = df_test['text'].apply(preprocess)
 df_train=df_train[df_train["text"]!='']<drop_column>
df_tahmin = pd.DataFrame(regressor.predict(df_test),index= df_test.index,columns = ['target'] )
<define_variables><EOS> 
df_tahmin.to_csv('mycsvfile.csv',index=True )