Kaggle competition: Santander Value Prediction Challenge
<SOS> metric: RMSLE Kaggle data source: santander-value-prediction-challenge<set_options>
plt.style.use('seaborn')
 sns.set(font_scale=2)
 %matplotlib inline
py.init_notebook_mode(connected=True)
logging.basicConfig(level=logging.INFO)
 transformers_logger = logging.getLogger("transformers")
 transformers_logger.setLevel(logging.WARNING )<split>
df_train = pd.read_csv('.. /input/train.csv')
 df_test = pd.read_csv('.. /input/test.csv')
 print('Train(rows, columns)', df_train.shape)
 print('test(rows, columns)', df_test.shape )
X = df_train['text']
y = df_train['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y )<create_dataframe>
columns = df_train.columns
r_value_array = []
for num in range(2, df_train.shape[1]):
x = df_train[columns[num]]
y = df_train['target']
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
 r_value_array.append(r_value )
train_df = pd.DataFrame(X_train)
 train_df['target'] = y_train
eval_df = pd.DataFrame(X_test)
 eval_df['target'] = y_test<init_hyperparams>
df_r_values = pd.DataFrame({'column': columns[2:], 'r_value': r_value_array} )
logging.basicConfig(level=logging.INFO)
 transformers_logger = logging.getLogger("transformers")
 transformers_logger.setLevel(logging.WARNING)

model = ClassificationModel('xlnet', 'xlnet-base-cased', args={'num_train_epochs':2, 'train_batch_size':16, 'max_seq_length':128})
 model.train_model(train_df)
 result, model_outputs, wrong_predictions = model.eval_model(eval_df, acc=sklearn.metrics.accuracy_score )<predict_on_test>
high_r_value_dataframe = df_r_values.loc[df_r_values.r_value.abs() > 0.05, :]
predictions, raw_outputs = model.predict(df_test.text.tolist() )<save_to_csv>
new_df_train = df_train[high_r_value_dataframe['column']]
new_df_test = df_test[high_r_value_dataframe['column']]
Y = np.log(df_train.target+1 ).values
sample_sub=pd.read_csv("/kaggle/input/nlp-getting-started/sample_submission.csv")
 sample_sub['target'] = predictions
sample_sub.to_csv("submission_01092020_xlnet_base.csv", index=False )<import_modules>
lgbm_params = {
'task': 'train',
'boosting_type': 'gbdt',
'objective': 'regression',
'metric': 'rmse',
'max_depth': 8,
'num_leaves': 32,
'feature_fraction': 0.8,
'bagging_fraction': 0.8,
'learning_rate': 0.01,
'verbose': 1
}
import numpy as np
import pandas as pd
import random
import plotly.express as px
import seaborn as sns
import matplotlib.pyplot as plt
import torch
from torch.utils.data import TensorDataset, DataLoader, random_split
from transformers import BertTokenizer
from transformers import BertForSequenceClassification, AdamW
from transformers import get_linear_schedule_with_warmup<set_options>
kf = KFold(n_splits=10, shuffle=True, random_state=1989 )
seed = 0
random.seed(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed_all(seed)
 torch.backends.cudnn.deterministic = True
device = torch.device("cuda" )<load_from_csv>
Y_target = []
for fold_id,(train_idx, val_idx)in enumerate(kf.split(new_df_train)) :
print('FOLD:',fold_id)
 X_train = new_df_train.values[train_idx]
y_train = Y[train_idx]
X_valid = new_df_train.values[val_idx]
y_valid = Y[val_idx]
lgtrain = lgb.Dataset(X_train, y_train,
feature_name=new_df_train.columns.tolist() , 
)
 lgvalid = lgb.Dataset(X_valid, y_valid,
feature_name=new_df_train.columns.tolist() , 
)
 modelstart = time.time()
lgb_clf = lgb.train(
 lgbm_params,
lgtrain,
num_boost_round=30000,
valid_sets=[lgtrain, lgvalid],
valid_names=['train','valid'],
early_stopping_rounds=100,
verbose_eval=100 
)
 test_pred = lgb_clf.predict(new_df_test.values)
 Y_target.append(np.exp(test_pred)-1)
 print('fold finish after', time.time() -modelstart )
train = pd.read_csv("/kaggle/input/nlp-getting-started/train.csv")
 test = pd.read_csv("/kaggle/input/nlp-getting-started/test.csv")
 print("Shape of train data : ",train.shape)
 print("Shape of test data : ",test.shape )<feature_engineering>
Y_target = np.array(Y_target)
 sub = pd.read_csv('.. /input/sample_submission.csv')
 sub['target'] = Y_target.mean(axis=0)
 sub.to_csv('simple_r_value_filter_result.csv', index=False )