Kaggle competition: Tabular Playground Series - Jan 2021
<SOS> metric: RMSE Kaggle data source: tabular-playground-series-jan-2021<load_pretrained>
!pip install -U git+https://github.com/mljar/mljar-supervised.git@master
!pip install -U matplotlib==3.1.3
torch.cuda.empty_cache()
tokenizer = ElectraTokenizer.from_pretrained('google/electra-base-discriminator')
 model = ElectraForSequenceClassification.from_pretrained('google/electra-base-discriminator',num_labels=2)
 model.cuda()<categorify>
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from supervised.automl import AutoML
indices=tokenizer.batch_encode_plus(texts,max_length=64,add_special_tokens=True, return_attention_mask=True,pad_to_max_length=True,truncation=True)
 input_ids=indices["input_ids"]
attention_masks=indices["attention_mask"]<split>
train=pd.read_csv(".. /input/tabular-playground-series-jan-2021/train.csv")
 test=pd.read_csv(".. /input/tabular-playground-series-jan-2021/test.csv" )
train_inputs, validation_inputs, train_labels, validation_labels = train_test_split(input_ids, labels,
random_state=42, test_size=0.2)
 train_masks, validation_masks, _, _ = train_test_split(attention_masks, labels,
random_state=42, test_size=0.2 )<data_type_conversions>
X = train.drop(columns=['target'])
 y = train['target'].values
X_train, X_test, y_train, y_test = train_test_split(
 X,
y,
test_size=0.25,
random_state=123, 
)
train_inputs = torch.tensor(train_inputs)
 validation_inputs = torch.tensor(validation_inputs)
 train_labels = torch.tensor(train_labels, dtype=torch.long)
 validation_labels = torch.tensor(validation_labels, dtype=torch.long)
 train_masks = torch.tensor(train_masks, dtype=torch.long)
 validation_masks = torch.tensor(validation_masks, dtype=torch.long )<create_dataframe>
automl = AutoML(algorithms=["CatBoost", "Xgboost", "LightGBM","Neural Network"],
model_time_limit=60*60,
start_random_models=10,
hill_climbing_steps=3,
top_models_to_improve=3,
golden_features=True,
features_selection=True,
stack_models=True,
train_ensemble=True,
explain_level=0,
validation_strategy={
"validation_type": "kfold",
"k_folds": 5,
"shuffle": False,
"stratify": True,
})
 automl.fit(X, y)
batch_size = 32
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_size)
 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_size )<choose_model_class>
predictions = automl.predict(X_test)
 print("Test MSE:", mean_squared_error(y_test, predictions,squared=False))
<compute_test_metric><EOS> 
preds = automl.predict(test)
 submission = test[['id']]
submission['target'] = preds
submission.to_csv('submission.csv', index = False )