Kaggle competition: Titanic - Machine Learning from Disaster
from glob import glob
from sklearn.model_selection import GroupKFold, StratifiedKFold
import cv2
from skimage import io
import torch
from torch import nn
import os
from datetime import datetime
import time
import random
import cv2
import torchvision
from torchvision import transforms
import pandas as pd
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
from torch.utils.data import Dataset,DataLoader
from torch.utils.data.sampler import SequentialSampler, RandomSampler
from torch.cuda.amp import autocast, GradScaler
import sklearn
import warnings
import joblib
from sklearn.metrics import roc_auc_score, log_loss
from sklearn import metrics
import warnings
import cv2
import pydicom
import timm
from scipy.ndimage.interpolation import zoom
from sklearn.metrics import log_loss<init_hyperparams>
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
 train_data.head()
CFG = {
'fold_num': 10,
'seed': 719,
'model_arch': 'tf_efficientnet_b3_ns',
'img_size': 512,
'epochs': 32,
'train_bs': 32,
'valid_bs': 32,
'lr': 0.03*1e-4,
'num_workers': 4,
'accum_iter': 2,
'verbose_step': 1,
'device': 'cuda:0',
'tta': 1,
'used_epochs': [6,7,8,9],
'weights': [1,1,1,1],
'PseEpochs':3,
'weight_decay':1e-6,
'T_0': 10,
'min_lr': 1e-7,
}<load_from_csv>
test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 test_data.head()
train = pd.read_csv('.. /input/cassava-leaf-disease-classification/train.csv')
 train<count_values>
def fill_age_random(df, age_column):

 if age_column+"_filled" not in df:
df.insert(( df.columns.get_loc(age_column)+1), age_column+"_filled", df[age_column])
 keys = []
values = []
for key, value in df[age_column].value_counts().items() :
keys.append(key)
 values.append(value)
 indices = [idx for idx, b in enumerate(df[age_column].isna())if b == True]
for idx, series in df.iterrows() :
if idx in indices:
df.loc[idx, age_column+"_filled"] = random.choices(keys, values)
 return df
train.label.value_counts()<load_from_csv>
y_train = train_data["Survived"]
train_data["Sex_cat"] = train_data["Sex"].astype("category")
 test_data["Sex_cat"] = test_data["Sex"].astype("category")
 features = ["Pclass", "Sex_cat", "Age_filled"]
X_train = train_data[features].copy()
X_test = test_data[features].copy()
X_train["Sex_cat"] = train_data["Sex_cat"].cat.codes
X_test["Sex_cat"] = test_data["Sex_cat"].cat.codes
model = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)
 model.fit(X_train, y_train)
 predictions = model.predict(X_test)
 output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
 output.to_csv('my_submission.csv', index=False)
 print("Your submission is succesfully saved!" )