Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<create_dataframe>
plt.style.use('ggplot')
 np.random.seed(7)
 torch.cuda.manual_seed_all(7 )
situation_2 = ship_team_1+ship_team_2_tic2
full_gs_and_as(dataset = have_family,id_list=situation_2,ticket_kind = "Ticket2",check_list = [],with_friend=[],count_maiden = True )<categorify>
train_dir=".. /input/train/train"
test_dir=".. /input/test/test"
train = pd.read_csv('.. /input/train.csv')
 sub_file = pd.read_csv(".. /input/sample_submission.csv")
 data_folder = Path(".. /input" )
check_list = [[70, 185, 1057, 1268, 1286], [408, 438, 530, 775, 832, 944], [438, 530, 775, 944], [477, 727, 923, 1211],
[672, 821, 984, 1200], [727, 923, 1211], [821, 984, 1200]]
fillfull_p2(have_family,check_list,check_more = [] )<load_pretrained>
trfm = get_transforms(do_flip=True, flip_vert=True, max_rotate=10.0, max_zoom=1.1, max_lighting=0.2, max_warp=0.2, p_affine=0.75, p_lighting=0.75 )
check_list = [[70, 185, 1057, 1268, 1286], [672, 821, 984, 1200], [821, 984, 1200]]
fullfill_ave_survival(have_family,check_list,check_more=[] )<filter>
test_img = ImageList.from_df(sub_file, path=data_folder/'test', folder='test')
 databunch =(ImageList.from_df(train, path=data_folder/'train', folder='train')
.split_by_rand_pct(0.01)
.label_from_df() 
.add_test(test_img)
.transform(trfm, size=48)
.databunch(path='.', bs=64, device= torch.device('cuda:0')) 
.normalize(imagenet_stats)
 )
remain_second_family = list(have_family[(have_family.PassengerId.isin(have_secondary_family1+have_secondary_family2))
&(have_family.Group_size.isna())]["PassengerId"].values)
 print(len(remain_second_family))<drop_column>
databunch.show_batch(rows=3, figsize=(8,8))
second_family = have_secondary_family1+have_secondary_family2
for i in remain_second_family:
second_family.remove(i)
 print(second_family )<filter>
learn = cnn_learner(databunch, models.resnet34, metrics=[error_rate, accuracy])
 learn.fit_one_cycle(5 )
have_family[have_family.PassengerId.isin([70, 185, 1057, 1268, 1286])][["Pclass_Gender","Survived","Ave_Survival"]]<feature_engineering>
learn.unfreeze()
learn.fit_one_cycle(5, max_lr=slice(1e-03))
next_check_2 = []
have_grouped = []
for i,j in have_family[have_family.PassengerId.isin(next_check)].groupby(["Surname"]):
if(len(j)) >=2:
family_size = j.Family_size.mean()
j_size = j.shape[0]
j_passid = list(j.PassengerId.values)
 if j_size == family_size:
have_grouped = have_grouped+[j_passid]
have_family.loc[(have_family.PassengerId.isin(j_passid)) ,"Group_size"] = j_size
have_family.loc[(have_family.PassengerId.isin(j_passid)) ,"Ave_Survival"] = j.Survived.mean()
else:
next_check_2 = next_check_2+[j_passid]
else:
j_passid = list(j.PassengerId.values)
 next_check_2 = next_check_2+[j_passid]
print("have grouped",have_grouped)
 print("next more check",next_check_2 )<groupby>
learn.show_results(rows=3 )
need_more_check = [41,193,69,1106,581,1133,1296,248,756,722,313,1041,443,893]
can_groupby_ticket2 = []
maybe_wrong = []
for i,j in have_family[have_family.PassengerId.isin(need_more_check)].groupby(["Embarked","Ticket2","Pclass"]):
if len(j)>=2:
can_groupby_ticket2 = can_groupby_ticket2+[i[1]]
else:
maybe_wrong = maybe_wrong+[i[1]]
print("can groupby ticket2",can_groupby_ticket2)
 print("maybe wrong",maybe_wrong )<categorify>
interp = ClassificationInterpretation.from_learner(learn)
 losses,idxs = interp.top_losses()
len(databunch.valid_ds)==len(losses)==len(idxs )
def get_from_id_tic2(dataset,passid,tic2):
return dataset[(dataset.PassengerId.isin(passid))
&(dataset.Ticket2.isin(tic2)) ][['Age', 'Embarked', 'Parch', 'SibSp','Ticket','Surname', 'Maiden','Family_size',
'Pclass_Gender','Cabin_Title',"Survived","Ave_Survival"]]<split>
predictions1=learn.get_preds(DatasetType.Test)
 predictions2=learn.get_preds(DatasetType.Test)
 predictions3=learn.get_preds(DatasetType.Test)
 predictions4=learn.get_preds(DatasetType.Test)
 predictions5=learn.get_preds(DatasetType.Test)
 predictions6=learn.get_preds(DatasetType.Test)
 predictions7=learn.get_preds(DatasetType.Test)
 predictions8=learn.get_preds(DatasetType.Test)
 comb_output=[predictions1[0],predictions2[0],predictions3[0],predictions4[0],
predictions5[0],predictions6[0],predictions7[0],predictions8[0]]
comb_output=torch.sum(torch.stack(comb_output),dim=0 )
<feature_engineering><EOS> 
sub_file.has_cactus = comb_output.numpy() [:, 0]
sub_file.to_csv('submission.csv', index=False )