Kaggle competition: Tabular Playground Series - Jan 2021
def generate_input_attention_mask(tweets):
tokenized_tweets = [bert_tokenizer.tokenize(tweet)for tweet in tweets]
input_ids = [bert_tokenizer.convert_tokens_to_ids(x)for x in tokenized_tweets]
input_ids = pad_sequences(input_ids, maxlen=MAX_LEN, dtype="long", truncating="post", padding="post")
 attention_masks = []
for seq in input_ids:
seq_mask = [float(i>0)for i in seq]
attention_masks.append(seq_mask)
 return input_ids, attention_masks<feature_engineering>
!pip install python-vivid
train_input_ids, train_attention_masks = generate_input_attention_mask(train_df['cleaned_text'] )<compute_test_metric>
import seaborn as sns
import matplotlib.pyplot as plt
from vivid.estimators.base import MetaBlock
from vivid.estimators.boosting.mixins import BoostingEarlyStoppingMixin
from catboost import CatBoostRegressor
def recall(y_true, y_pred):
true_positives = K.sum(K.round(y_true * y_pred))
possible_positives = K.sum(y_true)
 recall = true_positives /(possible_positives + K.epsilon())
 return recall
def precision(y_true, y_pred):
true_positives = K.sum(K.round(y_true * y_pred))
predicted_positives = K.sum(K.round(y_pred))
precision = true_positives /(predicted_positives + K.epsilon())
 return precision
def f1_score(y_true, y_pred):
prec = precision(y_true, y_pred)
 rec = recall(y_true, y_pred)
 return 2*(( prec*rec)/(prec+rec+K.epsilon()))<split>
from vivid.features.base import BinningCountBlock
from vivid.features.base import CountEncodingBlock
from vivid.features.base import FilterBlock
from vivid.estimators.boosting import XGBRegressorBlock
from vivid.estimators.boosting import LGBMRegressorBlock
from vivid.estimators.boosting.block import create_boosting_seed_blocks
from vivid.estimators.linear import TunedRidgeBlock
from vivid.estimators.svm import SVRBlock
from vivid.estimators.ensumble import RFRegressorBlock
from vivid.estimators.base import EnsembleBlock, BaseBlock
train_inputs, validation_inputs, train_labels, validation_labels = train_test_split(train_input_ids, train_df['target'], train_size=0.8, random_state=100)
 train_masks, validation_masks, _, _ = train_test_split(train_attention_masks, train_df['target'], train_size=0.8, random_state=100)
 train_inputs = torch.tensor(train_inputs, dtype=torch.long)
 validation_inputs = torch.tensor(validation_inputs, dtype=torch.long)
 train_labels = torch.tensor(train_labels, dtype=torch.long)
 validation_labels = torch.tensor(validation_labels.values, dtype=torch.long)
 train_masks = torch.tensor(train_masks, dtype=torch.long)
 validation_masks = torch.tensor(validation_masks, dtype=torch.long )<create_dataframe>
train_df = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/train.csv')
 test_df = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/test.csv')
 sample_submission_df = pd.read_csv('/kaggle/input/tabular-playground-series-jan-2021/sample_submission.csv')
 feature_columns = [
'cont1',
'cont2',
'cont3',
'cont4',
'cont5',
'cont6',
'cont7',
'cont8',
'cont9',
'cont10',
'cont11',
'cont12',
'cont13',
'cont14',
]
y = train_df['target'].values
train_data = TensorDataset(train_inputs, train_masks, train_labels)
 train_sampler = RandomSampler(train_data)
 train_dataloader = DataLoader(train_data, sampler=train_sampler, batch_size=BATCH_SZ)
 validation_data = TensorDataset(validation_inputs, validation_masks, validation_labels)
 validation_sampler = SequentialSampler(validation_data)
 validation_dataloader = DataLoader(validation_data, sampler=validation_sampler, batch_size=BATCH_SZ )<load_pretrained>
!pip install ptitprince
model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)
 model.cuda()<compute_train_metric>
!pip freeze | grep seaborn
param_optimizer = list(model.named_parameters())
 no_decay = ['bias', 'gamma', 'beta']
optimizer_grouped_parameters = [
{'params': [p for n, p in param_optimizer if not any(nd in n for nd in no_decay)],
'weight_decay_rate': 0.01},
{'params': [p for n, p in param_optimizer if any(nd in n for nd in no_decay)],
'weight_decay_rate': 0.0}
]
optimizer = BertAdam(optimizer_grouped_parameters,
lr=2e-5,
warmup=.1)
 def flat_accuracy(preds, labels):
pred_flat = np.argmax(preds, axis=1 ).flatten()
labels_flat = labels.flatten()
return np.sum(pred_flat == labels_flat)/ len(labels_flat )<train_model>
!pip install -U seaborn
train_loss_set = []
epochs = 4
for _ in range(epochs):
model.train()
tr_loss = 0
nb_tr_examples, nb_tr_steps = 0, 0
for step, batch in enumerate(train_dataloader):
batch = tuple(t.to(device)for t in batch)
 b_input_ids, b_input_mask, b_labels = batch
optimizer.zero_grad()
loss = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask, labels=b_labels)
 train_loss_set.append(loss.item())
 loss.backward()
optimizer.step()
tr_loss += loss.item()
nb_tr_examples += b_input_ids.size(0)
 nb_tr_steps += 1
print("Train loss: {}".format(tr_loss/nb_tr_steps))<predict_on_test>
from ptitprince import RainCloud
model.eval()
eval_accuracy = 0
nb_eval_steps = 0
for batch in validation_dataloader:
batch = tuple(t.to(device)for t in batch)
 b_input_ids, b_input_mask, b_labels = batch
with torch.no_grad() :
logits = model(b_input_ids, token_type_ids=None, attention_mask=b_input_mask)
 logits = logits.detach().cpu().numpy()
label_ids = b_labels.to('cpu' ).numpy()
tmp_eval_accuracy = flat_accuracy(logits, label_ids)
 eval_accuracy += tmp_eval_accuracy
nb_eval_steps += 1
print("Validation Accuracy: {}".format(eval_accuracy/nb_eval_steps))<feature_engineering>
np.percentile(y, [.5, 1, 10, 20] )
test_df.drop(columns=['keyword', 'location'], inplace=True)
 test_df['cleaned_text'] = np.vectorize(clean_text )(test_df['text'])
 test_df['cleaned_text'] = np.vectorize(add_special_token )(test_df['cleaned_text'])
 test_input_ids, test_attention_masks = generate_input_attention_mask(test_df['cleaned_text'] )<create_dataframe>
from sklearn.decomposition import PCA
test_inputs = torch.tensor(test_input_ids, dtype=torch.long)
 test_attention = torch.tensor(test_attention_masks, dtype=torch.long)
 test_data = TensorDataset(test_inputs, test_attention)
 test_sampler = SequentialSampler(test_data)
 test_dataloader = DataLoader(test_data, sampler=test_sampler, batch_size = BATCH_SZ )<predict_on_test>
model = PCA(n_components=2)
 model.fit(train_df[feature_columns] )
model.eval()
predictions = []
for batch in test_dataloader:
batch = tuple(t.to(device)for t in batch)
 b_input_ids, b_mask = batch
with torch.no_grad() :
logits = model(b_input_ids, token_type_ids=None, attention_mask = b_mask)
 logits = logits.detach().cpu().numpy()
predictions.append(logits)
 test_predictions = [item for sublist in predictions for item in sublist]
test_predictions = np.argmax(test_predictions, axis=1 ).flatten()<save_to_csv>
z = model.transform(train_df[feature_columns] )
submission = pd.DataFrame({'id':test_df['id'], 'target':test_predictions})
 submission.to_csv('./submission.csv', index=False )<import_modules>
from sklearn.mixture import GaussianMixture
import numpy as np
import pandas as pd
import tensorflow as tf
import csv
import re<categorify>
clf = GaussianMixture(n_components=3)
 x = train_df[feature_columns].values
clf.fit(x)
 z = clf.predict_proba(x )
def convert_test_attributes_to_onehot(df, value_list):
one_hots = np.zeros(( len(df), len(value_list)))
 for index, row in df.iterrows() :
if row['keyword'] != '':
try:
one_hots[index, value_list.index(row['keyword'])] = 1
except ValueError:
continue
if row['keyword'] != '':
try:
one_hots[index, value_list.index(row['location'])] = 1
except ValueError:
continue
return one_hots
def convert_attributes_to_onehot(df):
one_hot_keywords = pd.get_dummies(train_data['keyword'])
 one_hot_locations = pd.get_dummies(train_data['location'])
 return pd.concat([one_hot_keywords, one_hot_locations.reindex(one_hot_keywords.index)], axis=1)
 def vectorize_tweets(dataframe, df_glove):
vectorized_data = np.zeros(( len(dataframe), MAX_TWEET_LENGTH, VECTORS_PER_WORD))
for index, row in dataframe.iterrows() :
i = 0
for word in re.sub(r'\W+', ' ', row['text'].lower() ).split(' '):
try:
vectorized_data[index, i, :] = df_glove.loc[word]
except KeyError:
continue
i += 1
if index % 100 == 99:
print('Processing text number ' + str(index + 1)+ ' of ' + str(len(dataframe)))
 return vectorized_data<choose_model_class>
from vivid.core import BaseBlock
def build_model(lstm_shape, dense_shape):
dropout = 0.8
dense_input = tf.keras.layers.Input(shape=(dense_shape))
dense1 = tf.keras.layers.Dense(50 )(dense_input)
 lstm_input = tf.keras.layers.Input(shape=(lstm_shape))
lstm1 = tf.keras.layers.GaussianNoise(0.075 )(lstm_input)
 lstm2 = tf.keras.layers.LSTM(units=500, return_sequences=True )(lstm1)
 lstm3 = tf.keras.layers.Dropout(dropout )(lstm2)
 lstm4 = tf.keras.layers.LSTM(units=100, return_sequences=True )(lstm3)
 lstm5 = tf.keras.layers.Flatten()(lstm4)
 lstm6 = tf.keras.layers.Dense(20 )(lstm5)
 concat1 = tf.keras.layers.Concatenate()([dense1, lstm5])
 concat2 = tf.keras.layers.Dropout(dropout )(concat1)
 concat3 = tf.keras.layers.Dense(80 )(concat2)
 outputs = tf.keras.layers.Dense(1, activation='sigmoid' )(concat3)
 model = tf.keras.Model(inputs=[dense_input, lstm_input], outputs=outputs)
 model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.00005, beta_1=0.9, beta_2=0.998,),
loss=tf.keras.losses.BinaryCrossentropy() ,
metrics=['acc'])
 return model<define_variables>
class PCABlock(BaseBlock):
def __init__(self, n_components=3, columns=None, *args, **kwrgs):
self.n_components = n_components
if columns is None: columns = feature_columns
self.columns = columns
super().__init__(name='pca_n={}'.format(n_components), *args, **kwrgs)
 def fit(self, source_df, y, experiment=None)-> pd.DataFrame:
clf = PCA(n_components=self.n_components)
 clf.fit(source_df[self.columns].values)
 self.clf_ = clf
return self.transform(source_df)
 def transform(self, source_df):
z = self.clf_.transform(source_df[self.columns])
 out_df = pd.DataFrame(z)
 return out_df.add_prefix('PCA_')
 class GaussianMixtureBlock(BaseBlock):
def __init__(self, n_components=3, columns=None, *args, **kwrgs):
self.n_components = n_components
if columns is None: columns = feature_columns
self.columns = columns
super().__init__(name='GMM_n={}'.format(n_components), *args, **kwrgs)
 def fit(self, source_df, y, experiment=None)-> pd.DataFrame:
clf = GaussianMixture(n_components=self.n_components)
 clf.fit(source_df[self.columns].values)
 self.clf_ = clf
return self.transform(source_df)
 def transform(self, source_df):
z = self.clf_.predict_proba(source_df[self.columns])
 z = np.clip(z, 1e-6,1 - 1e-6)
 out_df = pd.DataFrame(z)
 return out_df.add_prefix('GMM_' )
MAX_TWEET_LENGTH = 280
VECTORS_PER_WORD = 50
BATCH_SIZE = 256
NUM_EPOCHS = 40<load_from_csv>
PCABlock().fit(train_df, y )
print('Loading test and training data')
 test_data = pd.read_csv('/kaggle/input/nlp-getting-started/test.csv')
 train_data = pd.read_csv('/kaggle/input/nlp-getting-started/train.csv')
 print('Loading GloVe file')
 glove_data = pd.read_csv('/kaggle/input/glove50d/glove.6B.50d.txt', sep=' ', index_col=0, header = None, quoting=csv.QUOTE_NONE, encoding='utf-8')
 glove_data.head()
df_one_hot_attributes = convert_attributes_to_onehot(train_data)
 df_test_one_hot_attributes = convert_test_attributes_to_onehot(test_data, df_one_hot_attributes.columns.to_list())
 df_one_hot_attributes.head()
vectorized_training_data = vectorize_tweets(train_data, glove_data)
 vectorized_testing_data = vectorize_tweets(test_data, glove_data )<train_model>
GaussianMixtureBlock().fit(train_df, y )
model = build_model([MAX_TWEET_LENGTH, VECTORS_PER_WORD], len(df_one_hot_attributes.columns))
model.summary()
checkpoint_save = tf.keras.callbacks.ModelCheckpoint('saved_model.h5', save_best_only=True, monitor='val_acc', mode='min')
 model.fit(x=[df_one_hot_attributes, vectorized_training_data], y=train_data['target'], batch_size=BATCH_SIZE, epochs=NUM_EPOCHS, verbose=1, shuffle=True)
 print('Training complete.Commencing creation of submission file')
 df_submission = pd.DataFrame()
df_submission['id'] = test_data['id']
predictions = model.predict([df_test_one_hot_attributes, vectorized_testing_data])
 prediction_list = []
for prediction in predictions:
if prediction < 0.5:
prediction_list += [0]
else:
prediction_list += [1]
df_submission['target'] = prediction_list
df_submission.head(5)
 df_submission.to_csv('submission.csv', index=False)
 print('All done.' )<import_modules>
from vivid.estimators.boosting import LGBMRegressorBlock
from vivid.runner import create_runner
import tensorflow as tf
from transformers import BertTokenizer, TFBertModel, AdamWeightDecay
from tensorflow import keras
import matplotlib.pyplot as plt
import string
import re
import numpy as np
import pandas as pd
import emoji
import os
from sklearn.metrics import accuracy_score
from skopt.utils import use_named_args
from skopt.space import Real, Integer, Categorical
from skopt import gp_minimize
from sklearn.model_selection import train_test_split
from sklearn.svm import LinearSVC
from sklearn.naive_bayes import GaussianNB
from sklearn.linear_model import LogisticRegression, SGDClassifier
from sklearn.preprocessing import MinMaxScaler
from sklearn.pipeline import make_pipeline
from sklearn.ensemble import StackingClassifier
from sklearn.model_selection import KFold<load_from_csv>
class CatRegressorBlock(BoostingEarlyStoppingMixin, MetaBlock):

 model_class = CatBoostRegressor
fit_verbose = 100
early_stopping_rounds = 200
initial_params = {
'learning_rate':.05,
'verbose': 100,
'num_boost_round': 20000
}
def get_fit_params_on_each_fold(self, *args, **kwrgs):

 params = super().get_fit_params_on_each_fold(*args, **kwrgs)
 params['verbose'] = self.fit_verbose
remove_keys = [
'eval_metric',
'callbacks'
]
for k in remove_keys:
if k in params:
del params[k]
return params
train = pd.read_csv('.. /input/nlp-getting-started/train.csv', header = 0, encoding="utf8")
 test = pd.read_csv('.. /input/nlp-getting-started/test.csv', header = 0, encoding="utf8")
 train = train.drop(columns=['id', 'keyword', 'location'])
 test = test.drop(columns=['id', 'keyword', 'location'])
 train = train.drop_duplicates().reset_index(drop=True)
 train.sample(10, random_state=18 )<feature_engineering>
feature_blocks = [
BinningCountBlock(name='BINS', column=feature_columns),
CountEncodingBlock(name='CE', column=feature_columns),
FilterBlock(name='F', column=feature_columns),
PCABlock(n_components=3),
GaussianMixtureBlock(n_components=3)
 ]
runner = create_runner(blocks=[
CatRegressorBlock(name='cat', parent=feature_blocks)
 ] )
def remove_tweet_object(tweet):
tweet = re.sub(r"https?://\S+|www\.\S+", " ", tweet)
 tweet = re.sub(r"
tweet = re.sub(r"@\w+", " ", tweet)
 tweet = emoji.get_emoji_regexp().sub(" ", tweet)
 return tweet
def text_filter(tweet):
tweet = tweet.lower()
tweet = re.sub(r"’", "'", tweet)
 tweet = remove_tweet_object(tweet)
 return tweet
train["text"] = train["text"].apply(lambda x: text_filter(x))
test["text"] = test["text"].apply(lambda x: text_filter(x))
train.sample(10, random_state=18 )<split>
y_cutted = np.clip(y, 5, np.inf )
X_train, X_val, y_train, y_val = train_test_split(train.text, train.target, test_size=0.2, random_state=42 )<load_pretrained>
oof_results = runner.fit(train_df[feature_columns], y=y_cutted )
name_bert = "bert-base-uncased"
tokenizer = BertTokenizer.from_pretrained(name_bert, do_lower_case=True)
 bert_model = TFBertModel.from_pretrained(name_bert, output_hidden_states=True, trainable=True)
 bert_w = bert_model.get_weights()<concatenate>
class FillnaBlock(BaseBlock):
def fit(self, source_df, y, experiment)-> pd.DataFrame:
self.fill_values_ = source_df.dropna().median()
return self.transform(source_df)
 def transform(self, source_df):
return source_df.fillna(self.fill_values_ )
combined = pd.concat([X_train, X_val, test.text], axis=0)
 combined = tokenizer(combined.values.tolist() , padding=True, truncation=True, return_tensors='tf')
 train_input =(combined["input_ids"][:len(X_train)], combined["attention_mask"][:len(X_train)], combined["token_type_ids"][:len(X_train)])
 val_input =(combined["input_ids"][len(X_train):len(X_train)+len(X_val)], combined["attention_mask"][len(X_train):len(X_train)+len(X_val)], combined["token_type_ids"][len(X_train):len(X_train)+len(X_val)])
 test_input =(combined["input_ids"][len(X_train)+len(X_val):], combined["attention_mask"][len(X_train)+len(X_val):], combined["token_type_ids"][len(X_train)+len(X_val):] )<choose_model_class>
feature_blocks = [
BinningCountBlock(name='BINS', column=feature_columns),
CountEncodingBlock(name='CE', column=feature_columns),
FilterBlock(name='F', column=feature_columns),
PCABlock(n_components=3),
GaussianMixtureBlock(n_components=3)
 ]
filled_feature_block = FillnaBlock(name='FNA', parent=feature_blocks )
bert_model.set_weights(bert_w)
 optimizer = AdamWeightDecay(learning_rate=3e-5, weight_decay_rate=0.01, exclude_from_weight_decay=["LayerNorm", "layer_norm", "bias"])
 loss = keras.losses.BinaryCrossentropy(from_logits=False, label_smoothing=0.0)
 input_word_ids = keras.layers.Input(shape=(train_input[0].shape[1],), dtype=tf.int32, name="input_ids")
 input_mask = keras.layers.Input(shape=(train_input[0].shape[1],), dtype=tf.int32, name="attention_mask")
 segment_ids = keras.layers.Input(shape=(train_input[0].shape[1],), dtype=tf.int32, name="token_type_ids")
 outputs = bert_model([input_word_ids, input_mask, segment_ids])
 drop = keras.layers.Dropout(0.1 )(outputs[1])
 relu = keras.layers.Dense(96, "relu" )(drop)
 drop = keras.layers.Dropout(0.1 )(relu)
 out = keras.layers.Dense(1, "sigmoid" )(drop)
 model = keras.models.Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=out)
 model.compile(optimizer=optimizer, loss=loss, metrics=["accuracy"])
 model.summary()
history_bert = model.fit(
 train_input,
y_train,
validation_data=(val_input, y_val),
epochs=1,
batch_size=32,
callbacks=[tf.keras.callbacks.EarlyStopping(monitor="val_accuracy", patience=1, mode='auto', restore_best_weights=True)]
)<predict_on_test>
single_models = [
create_boosting_seed_blocks(feature_class=XGBRegressorBlock,
prefix='xgb_',
parent=feature_blocks),
create_boosting_seed_blocks(feature_class=LGBMRegressorBlock,
prefix='lgb_',
parent=feature_blocks),
CatRegressorBlock(name='cat', parent=feature_blocks),
RFRegressorBlock(name='rf', parent=filled_feature_block),
TunedRidgeBlock(name='ridge',
add_init_param={ 'target_scaling': 'standard' },
n_trials=30,
parent=filled_feature_block)
 ]
stacking_models = [
EnsembleBlock(prefix='ens', parent=single_models),
TunedRidgeBlock(name='stacking_ridge', n_trials=30, parent=single_models,
add_init_param={ 'target_scaling': 'standard' }),
LGBMRegressorBlock(name='stacked_lgb', parent=[*single_models, *feature_blocks]),
CatRegressorBlock(name='stacked_cat', parent=[*single_models, *feature_blocks]),
XGBRegressorBlock(name='stacked_xgb', parent=[*single_models, *feature_blocks])
 ]
two_stage_stacking_models = [
TunedRidgeBlock(name='stage-2_ridge', n_trials=30, parent=stacking_models,
add_init_param={ 'target_scaling': 'standard' },)
 ]
model_bert_enc = keras.models.Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=relu)
 train_text_vect = model_bert_enc.predict(train_input)
 val_text_vect = model_bert_enc.predict(val_input)
 test_text_vect = model_bert_enc.predict(test_input)
 print("Done" )<choose_model_class>
runner = create_runner(two_stage_stacking_models,
experiment=LocalExperimentBackend(to='/kaggle/working/'))
space = [Real(1, 1e3, prior="log-uniform", name="C_svm", transform="identity"),
Real(1, 1e3, prior="log-uniform", name="C_lr", transform="identity"),
Categorical(['hinge', 'squared_hinge'], name="loss_svm", transform="identity"),
Categorical(['l1', 'l2', 'elasticnet'], name="penalty_sgd", transform="identity"),
Categorical(['hinge', 'log', 'modified_huber', 'squared_hinge', 'perceptron'], name="loss_sgd", transform="identity"),
]
@use_named_args(space)
 def opt_model(C_svm, loss_svm, penalty_sgd, loss_sgd, C_lr):
estimators = [('1', make_pipeline(MinMaxScaler() , LinearSVC(C=C_svm, loss=loss_svm, random_state=42))), 
('2', make_pipeline(MinMaxScaler() , GaussianNB())) , 
('3', make_pipeline(MinMaxScaler() , SGDClassifier(penalty=penalty_sgd, loss=loss_sgd, random_state=42))),
]
clf = StackingClassifier(estimators=estimators, final_estimator=LogisticRegression(C=C_lr, random_state=42), n_jobs=-1, cv=KFold(n_splits=5, shuffle=True, random_state=42), stack_method='predict')
 clf.fit(train_text_vect, y_train)
 return -clf.score(train_text_vect, y_train)
 res = gp_minimize(opt_model, space, n_initial_points=10, n_calls=50, verbose=True, random_state=0, n_jobs=-1 )<train_model>
oof_results = runner.fit(train_df, y=y_cutted )
estimators = [ 
('1', make_pipeline(MinMaxScaler() , LinearSVC(C=res.x[0], loss=res.x[2] ,random_state=42))), 
('2', make_pipeline(MinMaxScaler() , GaussianNB())) , 
('3', make_pipeline(MinMaxScaler() , SGDClassifier(penalty=res.x[3], loss=res.x[4],random_state=42))),
]
clf = StackingClassifier(estimators=estimators, final_estimator=LogisticRegression(C=res.x[1],random_state=42), n_jobs=-1, cv=KFold(n_splits=5, shuffle=True, random_state=42), stack_method='predict')
 clf.fit(train_text_vect, y_train)
 print(clf.score(train_text_vect, y_train))
print(clf.score(val_text_vect, y_val))<save_to_csv>
test_results = runner.predict(test_df )
df_submission = pd.read_csv('.. /input/nlp-getting-started/sample_submission.csv', index_col=0 ).fillna('')
 df_submission['target'] = clf.predict(test_text_vect)
 df_submission.to_csv('submission.csv')
 df_submission<import_modules>
oof_df = pd.DataFrame()
for result in oof_results:
oof_df[result.block.name] = result.out_df.values[:, 0]
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename)) 
<load_from_csv>
score_df = pd.DataFrame()
for name, pred in oof_df.T.iterrows() :
score_i = regression_metrics(y, pred)
 score_df = score_df.append(pd.Series(score_i, name=name))
tweets = pd.read_csv('/kaggle/input/nlp-getting-started/train.csv')
 test = pd.read_csv('/kaggle/input/nlp-getting-started/test.csv' )<string_transform>
score_df.sort_values('rmse' )
<string_transform><EOS> 
for result in test_results:
out_df = result.out_df
sub_df = sample_submission_df.copy()
sub_df['target'] = result.out_df.values[:, 0]
to = f'/kaggle/working/{str(result.block.name)}_submission.csv'
print('save to {}'.format(to))
sub_df.to_csv(to, index=False )