Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<load_from_csv>
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import kurtosis
from scipy.stats import skew
testset = ImageDataset(csv_file='.. /input/sample_sub.csv', root_dir='.. /input/data/data/', transform=transform)
 testloader = DataLoader(testset, batch_size=32, num_workers=4, shuffle=False )<load_from_csv>
plt.rcParams['figure.figsize'] =(8,5)
 plt.style.use("ggplot" )
submission = pd.read_csv('.. /input/sample_sub.csv')
 submission.head()<categorify>
train=pd.read_csv(".. /input/titanic/train.csv")
 test=pd.read_csv(".. /input/titanic/test.csv" )
predictions = []
for inputs, labels in testloader:
if gpu:
inputs = Variable(inputs.cuda())
 else:
inputs = Variable(inputs)
 outputs = model(inputs)
 _, predicted = torch.max(outputs.data, 1)
 for i in range(len(predicted)) :
predictions.append(int(predicted[i]))
submission['Category'] = predictions<save_to_csv>
train.isna().sum()
submission.to_csv('VGG19_submission1.csv', index=False, encoding='utf-8' )<set_options>
test.isna().sum()
%matplotlib inline<load_from_csv>
train.drop("Cabin",axis=1,inplace=True)
 test.drop("Cabin",axis=1,inplace=True )
df = pd.read_csv('.. /input/train.csv')
 df.head()<load_from_csv>
df=pd.DataFrame(train.groupby(["Pclass","Sex"] ).sum().Survived)
 df.reset_index(inplace=True)
 df
class ImageDataset(Dataset):
def __init__(self, csv_file, root_dir, transform=None):

 self.data_frame = pd.read_csv(csv_file)
 self.root_dir = root_dir
self.transform = transform
def __len__(self):
return len(self.data_frame)
 def __getitem__(self, idx):
img_name = os.path.join(self.root_dir, self.data_frame['Id'][idx])
 image = Image.open(img_name ).convert('RGB')
 label = np.array(self.data_frame['Category'][idx])
 if self.transform:
image = self.transform(image)
 sample =(image, label)
 return sample<load_from_csv>
train["age_category"]=""
for i in range(891):
if train.loc[i,"Age"]<1:
train.loc[i,"age_category"]="Infants"
elif 1<=train.loc[i,"Age"]<18:
train.loc[i,"age_category"]="Children"
elif 18<=train.loc[i,"Age"]<65:
train.loc[i,"age_category"]="Adults"
elif train.loc[i,"Age"]>=65:
train.loc[i,"age_category"]="Elders"
else:
train.loc[i,"age_category"]="Unknown"
train.head()
transform = transforms.Compose([transforms.RandomResizedCrop(224),
transforms.ToTensor()
])
 trainset = ImageDataset(csv_file = '.. /input/train.csv', root_dir = '.. /input/data/data/', transform=transform)
 trainloader = torch.utils.data.DataLoader(trainset, batch_size=16, shuffle=True, num_workers=0 )<define_variables>
df_2=pd.DataFrame(train.groupby(["age_category",] ).sum().Survived)
 df_2["Total"]=train["age_category"].value_counts()
df_2.reset_index(inplace=True)
 df_2
for i in range(len(trainset)) :
sample = trainset[i]
print(i, sample[0].size() , " | Label: ", sample[1])
 if i == 9:
break<train_model>
df_3=train.groupby("SibSp" ).sum().Survived
df_3
train_on_gpu = torch.cuda.is_available()
if not train_on_gpu:
print('CUDA is not available.Training on CPU...')
 else:
print('CUDA is available! Training on GPU...' )<choose_model_class>
df_4=train.groupby("Parch" ).sum().Survived
df_4
model = models.resnext101_32x8d(pretrained=True )<find_best_params>
data={"Class":["Class1","Class2","Class3"],
"Passengers":[train[train.Pclass==1].shape[0],train[train.Pclass==2].shape[0],train[train.Pclass==3].shape[0]]}
for param in model.parameters() :
param.requires_grad = True
for param in model.parameters() :
param.requires_grad = True
for name, child in model.named_children() :
if name in ['layer3', 'layer4', 'fc']:
print(name + ' is unfrozen')
 for param in child.parameters() :
param.requires_grad = True
else:
print(name + ' is frozen')
 for param in child.parameters() :
param.requires_grad = False<choose_model_class>
data={"Class":["Class1","Class2","Class3"],
"Passengers":[train[train.Pclass==1].shape[0],train[train.Pclass==2].shape[0],train[train.Pclass==3].shape[0]]}
Class=pd.DataFrame(data,columns=["Class","Passengers"])
 Class
model.fc = nn.Sequential(
 nn.Linear(2048, 4096),
nn.ReLU() ,
nn.Linear(4096, 256),
nn.ReLU() ,
nn.Linear(256, 67),
nn.LogSoftmax(dim=1))<choose_model_class>
train["status"]=""
for i in range(891):
if "Mr." in(train.Name[i].split()):
train.loc[i,"status"]="Mister"
elif "Miss." in(train.Name[i].split()):
train.loc[i,"status"]="Miss"
elif "Mrs." in(train.Name[i].split()):
train.loc[i,"status"]="Mistress"
elif "Rev." in(train.Name[i].split()):
train.loc[i,"status"]="Reverend"
elif "Master." in(train.Name[i].split()):
train.loc[i,"status"]="Master"
elif "Mlle." in(train.Name[i].split()):
train.loc[i,"status"]="Mademoiselle"
elif "Dr." in(train.Name[i].split()):
train.loc[i,"status"]="Doctor"
else:
train.loc[i,"status"]="Other"
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(filter(lambda p: p.requires_grad, model.parameters()), lr=0.0006, momentum=0.9)
<train_on_grid>
train.status.value_counts()
epochs=20
for e in range(epochs):
running_loss = 0
corr = torch.tensor(( 0), dtype=torch.int64)
 for images, labels in trainloader:
images = images.cuda()
labels=labels.cuda()
optimizer.zero_grad()
output = model(images)
 _, out = torch.max(output, 1)
 loss = criterion(output, labels)
 loss.backward()
corr+=sum(out==labels)
 optimizer.step()
running_loss += loss.item()
else:
print("Epoch {} - Training loss: {}".format(e, running_loss/len(trainloader)))
 print(corr,"/10934")
<train_model>
train[train.status=='Other']
model.eval() 
<load_from_csv>
print(train.Sex.value_counts())
 print("{:.2f} % of people were males".format(( train.Sex.value_counts() [0]/891)*100))
print("{:.2f} % of people were females".format(( train.Sex.value_counts() [1]/891)*100))
submission = pd.read_csv('.. /input/sample_sub.csv')
 submission.head()<load_from_csv>
print(train.groupby("Sex" ).sum().Survived)
 print("{:.2f} % of females survived".format(( train.groupby("Sex" ).sum().Survived[0]/314)*100))
print("{:.2f} % of males survived".format(( train.groupby("Sex" ).sum().Survived[1]/577)*100))
testset = ImageDataset(csv_file = '.. /input/sample_sub.csv', root_dir = '.. /input/data/data/', transform=transform)
 testloader = torch.utils.data.DataLoader(testset, batch_size=16, shuffle=False, num_workers=0 )<prepare_output>
print("Skewness of Age distribution is {:.2f}".format(skew(train.dropna().Age)))
 print("Kurtosis of Age distribution is {:.2f}".format(kurtosis(train.dropna().Age)) )
predictions=[]
for data, target in testloader:
if train_on_gpu:
data, target = data.cuda() , target.cuda()
output = model(data)
 _, pred = torch.max(output, 1)
 for i in range(len(pred)) :
predictions.append(int(pred[i])) 
<prepare_output>
train.SibSp.value_counts()
submission['Category'] = predictions<save_to_csv>
train.Parch.value_counts()
submission.to_csv('submission1.csv', index=False, encoding='utf-8')
<prepare_x_and_y>
train.drop("Ticket",axis=1,inplace=True)
 train.head()
with open(".. /input/train.json")as f:
data = json.load(f)
 X = []
Y = []
for element in data:
img = cv2.resize(np.array(Image.open(".. /input/train/train/" + element["filename"])) ,(64,64))
X.append(np.array(img/255))
Y.append(element["class"])
 y_train = np.array(to_categorical(Y))
x_train = np.array(X)
 base_model = ResNet50(weights='imagenet', include_top=False)
 x = base_model.output
x = GlobalAveragePooling2D()(x)
 x = Dense(1024, activation='relu' )(x)
 predictions = Dense(29, activation='softmax' )(x)
 model = Model(inputs=base_model.input, outputs=predictions)
 model.compile(optimizer=SGD(lr=0.0001, momentum=0.9),
loss='categorical_crossentropy',
metrics=["accuracy"])
 hist = model.fit(x_train,
y_train,
batch_size=32,
validation_split=0.2,
epochs=10)
<load_from_csv>
train.groupby("Pclass" ).mean().Fare
with open(".. /input/sandbox.csv")as f:
data = f.readlines()
content = [x.strip() for x in data]
just_names = [x.split(',')[0] for x in content[1:]]<predict_on_test>
train.Embarked.value_counts()
results = []
for c in tqdm(just_names):
img = Image.open(".. /input/test/test/" + c)
 img = np.array(img,dtype=np.float32)/ 255
res = model.predict(np.array([img]))
results.append(np.argmax(res[0]))<save_to_csv>
embarked=pd.DataFrame(train[["Pclass","Embarked"]].value_counts(sort=False))
embarked.reset_index(inplace=True)
 embarked.columns=["Class","Embarked","No.of passengers"]
embarked
with open("submission.csv","w")as f:
f.write("ID,Class"+'
')
 for ID,Class in zip(just_names,results):
f.write(ID + "," + str(Class)+ "
" )<import_modules>
train[(train.status=="Master")&(train.Age.isna())]
import numpy as np
import pandas as pd
import skimage.io
from skimage.transform import resize
import matplotlib.pyplot as plt
from tqdm import tqdm
import os<load_from_csv>
mean_age_children=round(train[(train["age_category"]=="Children")|(train["age_category"]=="Infants")].Age.mean())
 mean_age_children
path_to_train = '.. /input/tl-signs-hse-itmo-2020-winter/train/train/'
data = pd.read_csv('.. /input/tl-signs-hse-itmo-2020-winter/train.csv')
 train_dataset_info = []
for name, label in zip(data['filename'], data['class_number']):
train_dataset_info.append({
'path':os.path.join(path_to_train, name),
'label':int(label)- 1})
 train_dataset_info = np.array(train_dataset_info )<train_model>
train[(train.status=="Master")&(train.Age.isna())]=train[(train.status=="Master")&(train.Age.isna())].fillna(mean_age_children)
 train[train.status=="Master"].Age.isna().sum()
class data_generator:

 def create_train(dataset_info, batch_size, shape):
while True:
random_indexes = np.random.choice(len(dataset_info), batch_size)
 batch_images = np.empty(( batch_size, shape[0], shape[1], shape[2]))
batch_labels = np.zeros(( batch_size, 66))
for i, idx in enumerate(random_indexes):
image = data_generator.load_image(
 dataset_info[idx]['path'], shape)
 batch_images[i] = image
batch_labels[i][dataset_info[idx]['label']] = 1
yield batch_images, batch_labels
def load_image(path, shape):
image = skimage.io.imread(path)
 image = resize(image,(shape[0], shape[1]), mode='reflect')
 return image<train_model>
train[(train.status=="Mistress")&(train.Age.isna())]
train_datagen = data_generator.create_train(
 train_dataset_info, 5,(48, 48, 3))<choose_model_class>
mean_age_mistress=round(train[train.status=="Mistress"].Age.mean())
 mean_age_mistress
def create_model(input_shape, n_out):
model = Sequential([
Conv2D(32,(3,3), padding='same', activation=tf.nn.relu,
input_shape=(48, 48, 3)) ,
MaxPooling2D(( 2, 2), strides=2),
Conv2D(64,(3,3), padding='same', activation=tf.nn.relu),
MaxPooling2D(( 2, 2), strides=2),
Flatten() ,
Dense(128, activation=tf.nn.relu),
Dense(66, activation=tf.nn.softmax)
 ])
 return model<choose_model_class>
train[(train.status=="Mistress")&(train.Age.isna())]=train[(train.status=="Mistress")&(train.Age.isna())].fillna(mean_age_mistress)
 train[train.status=="Mistress"].Age.isna().sum()
keras.backend.clear_session()
model = create_model(
 input_shape=(48, 48, 3),
n_out=66)
 model.compile(
 loss='categorical_crossentropy',
optimizer=Adam(1e-04),
metrics=['acc'])
 model.summary()<train_model>
train[(train.status=="Mister")&(train.Age.isna())]
epochs = 100; batch_size = 16
checkpointer = ModelCheckpoint(
 '.. /working/InceptionResNetV2.model',
verbose=2,
save_best_only=True)
 np.random.seed(2018)
 indexes = np.arange(train_dataset_info.shape[0])
 np.random.shuffle(indexes)
 train_indexes = indexes[:20000]
valid_indexes = indexes[20000:]
train_generator = data_generator.create_train(
 train_dataset_info[train_indexes], batch_size,(48, 48, 3))
validation_generator = data_generator.create_train(
 train_dataset_info[valid_indexes], 100,(48, 48, 3))
history = model.fit_generator(
 train_generator,
steps_per_epoch=100,
validation_data=next(validation_generator),
epochs=epochs,
verbose=1,
callbacks=[checkpointer] )<load_from_csv>
mean_age_mister=round(train[train.status=="Mister"].Age.mean())
 mean_age_mister
submit = pd.read_csv('.. /input/tl-signs-hse-itmo-2020-winter/sample_submission.csv')
 predicted = []
for name in tqdm(submit['filename']):
path = os.path.join('.. /input/tl-signs-hse-itmo-2020-winter/test/test', name)
 image = data_generator.load_image(path,(48, 48, 3))
score_predict = model.predict(image[np.newaxis])[0]
label_predict = np.argmax(score_predict)
 str_predict_label = str(label_predict + 1)
 predicted.append(str_predict_label )<save_to_csv>
train[(train.status=="Mister")&(train.Age.isna())]=train[(train.status=="Mister")&(train.Age.isna())].fillna(mean_age_mister)
 train[train.status=="Mister"].Age.isna().sum()
submit['class_number'] = predicted
submit.to_csv('submission_neural.csv', index=False )<load_from_csv>
for i in range(888):
if train.loc[i,"Age"]<1:
train.loc[i,"age_category"]="Infants"
elif 1<=train.loc[i,"Age"]<18:
train.loc[i,"age_category"]="Children"
elif 18<=train.loc[i,"Age"]<65:
train.loc[i,"age_category"]="Adults"
elif train.loc[i,"Age"]>=65:
train.loc[i,"age_category"]="Elders"
else:
train.loc[i,"age_category"]="Unknown"
trainDF = pd.read_csv('.. /input/train.csv')
 trainDF.head()<split>
print(train.Age.isna().sum())
 train[train.Age.isna() ]
train_x, val_x, train_y, val_y = train_test_split(trainDF['review'], trainDF['sentiment'], test_size=0.1, shuffle=True )<feature_engineering>
mean_age_maleAdult=round(train[(train["age_category"]=="Adults")&(train.Sex=="male")].Age.mean())
 mean_age_maleAdult
tfidf_vect = TfidfVectorizer(analyzer='word', token_pattern=r'\w{1,}', max_features=25000)
 tfidf_vect.fit(trainDF['review'])
 xtrain_tfidf = tfidf_vect.transform(train_x)
 xval_tfidf = tfidf_vect.transform(val_x )<categorify>
mean_age_femaleAdult=round(train[(train["age_category"]=="Adults")&(train.Sex=="female")].Age.mean())
 print(mean_age_femaleAdult)
 mean_age_femaleChildren=round(train[(train["age_category"]=="Children")&(train.Sex=="female")].Age.mean())
 print(mean_age_femaleChildren )
xtrain_tfidf = xtrain_tfidf.toarray()
xval_tfidf = xval_tfidf.toarray()
train_y = np.array(train_y)
 val_y = np.array(val_y )<categorify>
train[(train.Age.isna())&(train.Parch==0)]=train[(train.Age.isna())&(train.Parch==0)].fillna(mean_age_femaleAdult)
 train[train.Age.isna() ]
train_dataset = TensorDataset(torch.from_numpy(xtrain_tfidf ).double() , torch.from_numpy(train_y ).double())
 train_dataloader = DataLoader(train_dataset, shuffle=True, batch_size=64)
 val_dataset = TensorDataset(torch.from_numpy(xval_tfidf ).double() , torch.from_numpy(val_y ).double())
 val_dataloader = DataLoader(val_dataset, shuffle=True, batch_size=64)
 dataloaders = {'train': train_dataloader, 'val': val_dataloader}
dataset_sizes = {'train': len(train_dataset), 'val': len(val_dataset)}<init_hyperparams>
train[train.Age.isna() ]=train[train.Age.isna() ].fillna(mean_age_femaleChildren )
epochs = 30
input_dim = 25000
output_dim = 1
lr_rate = 0.001<choose_model_class>
for i in range(891):
if train.loc[i,"Age"]<1:
train.loc[i,"age_category"]="Infants"
elif 1<=train.loc[i,"Age"]<18:
train.loc[i,"age_category"]="Children"
elif 18<=train.loc[i,"Age"]<65:
train.loc[i,"age_category"]="Adults"
elif train.loc[i,"Age"]>=65:
train.loc[i,"age_category"]="Elders"
else:
train.loc[i,"age_category"]="Unknown"
model = nn.Sequential(nn.Linear(input_dim, 2048),
nn.Dropout(0.5),
nn.ReLU() ,
nn.Linear(2048, 256),
nn.Dropout(0.5),
nn.ReLU() ,
nn.Linear(256, output_dim),
nn.Sigmoid() ).double()<choose_model_class>
train.isna().sum()
criterion = torch.nn.BCEWithLogitsLoss()
optimizer = torch.optim.Adam(model.parameters() , lr=lr_rate )<train_on_grid>
train[train.Embarked.isna() ]
def train_model(model):
model = model.cuda()
best_acc = 0.0
best_model_wts = copy.deepcopy(model.state_dict())
 for epoch in range(int(epochs)) :
train_loss = 0
val_loss = 0
val_acc = 0
model.train()
for inputs, labels in train_dataloader:
inputs, labels = inputs.cuda() , labels.cuda()
optimizer.zero_grad()
outputs = model(inputs)
 loss = criterion(outputs.squeeze() , labels)
 loss.backward()
optimizer.step()
train_loss += loss.item()
else:
model.eval()
num_correct = 0
for inputs, labels in val_dataloader:
inputs, labels = inputs.cuda() , labels.cuda()
outputs = model(inputs)
 predictions = torch.round(outputs.squeeze())
 loss = criterion(predictions, labels)
 val_loss += loss.item()
equals =(predictions == labels.data)
 num_correct += torch.sum(equals.data ).item()
val_acc = num_correct / len(val_dataset)
 if val_acc > best_acc:
best_acc = val_acc
best_model_wts = copy.deepcopy(model.state_dict())
 print('---------Epoch {} -----------'.format(epoch))
print('Train Loss: {:.6f} Val Loss: {:.6f} Val Accuracy: {:.6f}'.format(
 train_loss/len(train_dataset), val_loss/len(val_dataset), val_acc))
model.load_state_dict(best_model_wts)
 return model<train_model>
train.fillna("S",inplace=True)
 train.isna().sum()
model = train_model(model )<load_from_csv>
test.drop("Ticket",axis=1,inplace=True)
 test["age_category"]=""
for i in range(418):
if test.loc[i,"Age"]<1:
test.loc[i,"age_category"]="Infants"
elif 1<=test.loc[i,"Age"]<18:
test.loc[i,"age_category"]="Children"
elif 18<=train.loc[i,"Age"]<65:
test.loc[i,"age_category"]="Adults"
elif test.loc[i,"Age"]>=65:
test.loc[i,"age_category"]="Elders"
else:
test.loc[i,"age_category"]="Unknown"
test["status"]=""
for i in range(418):
if "Mr." in(test.Name[i].split()):
test.loc[i,"status"]="Mister"
elif "Miss." in(test.Name[i].split()):
test.loc[i,"status"]="Miss"
elif "Mrs." in(test.Name[i].split()):
test.loc[i,"status"]="Mistress"
elif "Rev." in(test.Name[i].split()):
test.loc[i,"status"]="Reverend"
elif "Master." in(test.Name[i].split()):
test.loc[i,"status"]="Master"
elif "Dr." in(test.Name[i].split()):
test.loc[i,"status"]="Doctor"
else:
test.loc[i,"status"]="Other"
mean_age_children=round(test[(test["age_category"]=="Children")|(test["age_category"]=="Infants")].Age.mean())
 test[(test.status=="Master")&(test.Age.isna())]=test[(test.status=="Master")&(test.Age.isna())].fillna(mean_age_children)
 mean_age_mistress=round(test[test.status=="Mistress"].Age.mean())
 test[(test.status=="Mistress")&(test.Age.isna())]=test[(test.status=="Mistress")&(test.Age.isna())].fillna(mean_age_mistress)
 mean_age_mister=round(test[test.status=="Mister"].Age.mean())
 test[(test.status=="Mister")&(test.Age.isna())]=test[(test.status=="Mister")&(test.Age.isna())].fillna(mean_age_mister)
 for i in range(418):
if test.loc[i,"Age"]<1:
test.loc[i,"age_category"]="Infants"
elif 1<=test.loc[i,"Age"]<18:
test.loc[i,"age_category"]="Children"
elif 18<=train.loc[i,"Age"]<65:
test.loc[i,"age_category"]="Adults"
elif test.loc[i,"Age"]>=65:
test.loc[i,"age_category"]="Elders"
else:
test.loc[i,"age_category"]="Unknown"
mean_age_femaleAdult=round(test[(test["age_category"]=="Adults")&(test.Sex=="female")].Age.mean())
 mean_age_femaleChildren=round(test[(test["age_category"]=="Children")&(test.Sex=="female")].Age.mean())
 test[(test.Age.isna())&(test.Parch==0)]=test[(test.Age.isna())&(test.Parch==0)].fillna(mean_age_femaleAdult)
 test[test.Age.isna() ]=test[test.Age.isna() ].fillna(mean_age_femaleChildren)
 for i in range(418):
if test.loc[i,"Age"]<1:
test.loc[i,"age_category"]="Infants"
elif 1<=test.loc[i,"Age"]<18:
test.loc[i,"age_category"]="Children"
elif 18<=test.loc[i,"Age"]<65:
test.loc[i,"age_category"]="Adults"
elif test.loc[i,"Age"]>=65:
test.loc[i,"age_category"]="Elders"
else:
test.loc[i,"age_category"]="Unknown"
fare_mean=test[test.Pclass==3].Fare.mean()
test.fillna(fare_mean,inplace=True)
 print(test.isna().sum())
test_df = pd.read_csv('.. /input/test.csv')
 xtest_tfidf = tfidf_vect.transform(test_df['review'])
 xtest_tfidf = xtest_tfidf.toarray()<prepare_x_and_y>
label_encoder = LabelEncoder()
col=["Sex","Embarked","age_category"]
for i in col:
train[i]=label_encoder.fit_transform(train[i])
 test[i]=label_encoder.fit_transform(test[i])
test_y = np.zeros(xtest_tfidf.shape[0] )<create_dataframe>
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
test_dataset = TensorDataset(torch.from_numpy(xtest_tfidf), torch.from_numpy(test_y))
test_dataloader = DataLoader(test_dataset, shuffle=False, batch_size=64 )<predict_on_test>
features1=["Pclass","Sex","Fare","age_category"]
X1=train[features1]
y1=train.Survived
X_train1, X_test1, y_train1,y_test1=train_test_split(X1,y1,test_size=0.22,random_state=0)
 DT1=DecisionTreeClassifier(random_state=1)
 DT1.fit(X_train1,y_train1)
 y_pred1=DT1.predict(X_test1)
 score=(round(accuracy_score(y_pred1,y_test1)*100,2))
score
def predict(model, test_dataloader):
model.eval()
predictions = []
for inputs, _ in test_dataloader:
inputs = inputs.cuda()
output = model(inputs)
 preds = torch.round(output)
 predictions.extend([p.item() for p in preds])
 return predictions
predictions = predict(model, test_dataloader )<create_dataframe>
features2=["Pclass","Sex","Fare"]
X2=train[features2]
y2=train.Survived
X_train2, X_test2, y_train2,y_test2=train_test_split(X2,y2,test_size=0.21,random_state=0)
 DT2=DecisionTreeClassifier(random_state=1)
 DT2.fit(X_train2,y_train2)
 y_pred2=DT2.predict(X_test2)
 score=round(accuracy_score(y_pred2,y_test2)*100,2)
 score
sub_df = pd.DataFrame()
sub_df['Id'] = test_df['Id']
sub_df['sentiment'] = [int(p)for p in predictions]<save_to_csv>
xgb = GradientBoostingClassifier(random_state=1)
 xgb.fit(X_train1, y_train1)
 y_pred = xgb.predict(X_test1)
 score_xgb = round(accuracy_score(y_pred, y_test1)* 100, 2)
 score_xgb
sub_df.to_csv('my_submission.csv', index=False)
<install_modules>
Jack=[3,1,7.89,0]
Rose=[1,0,60,0]
predictions=xgb.predict([Jack,Rose])
 print("Did Jack survived? {}".format(predictions[0]))
print("Did Rose survived? {}".format(predictions[1]))
!pip install -q --upgrade efficientnet tensorflow_addons<import_modules>
ids = test['PassengerId']
X_test=test[features1]
predictions = xgb.predict(X_test)
 df = pd.DataFrame({ 'PassengerId' : ids, 'Survived': predictions })
 df.to_csv('submission.csv', index=False )