Kaggle competition: Flower Classification with TPUs
def read_and_concat_dataset(training_path, test_path):
train = pd.read_csv(training_path)
 train['train'] = 1
test = pd.read_csv(test_path)
 test['train'] = 0
data = train.append(test, ignore_index=True)
 return train, test, data
train, test, data = read_and_concat_dataset('.. /input/train.csv', '.. /input/test.csv')
 data = data.set_index('PassengerId' )<groupby>
preds1=np.load('.. /input/tpu-enet-b7-densenet-random-cut/probs.npz')
 preds1['a'].shape
def counting_values(data, variable1, variable2):
return data[[variable1, variable2]][data[variable2].isnull() ==False].groupby([variable1], as_index=False ).mean().sort_values(by=variable2, ascending=False )<count_values>
preds2=np.load('.. /input/kernel4-aug/probs.npz')
 preds2['a'].shape
counting_values(data, 'Sex','Survived' )<feature_engineering>
preds4=np.load('.. /input/fork-of-tpu-enet-b7-incepentionresnetv2-densene/probs.npz')
 preds4['a'].shape
data['Women'] = np.where(data.Sex=='female',1,0)
 comparing(data, 'Women','Survived' )<count_missing_values>
preds3=np.load('.. /input/fork-of-fork-of-tpu-enet-b7-incepentionresnetv2/probs.npz')
 preds3['a'].shape
data.isnull().sum()<count_missing_values>
preds51=np.load('.. /input/5-kfold-efficentne-e7-p1/probs.npz')
 preds51['a'].shape
data.isnull().sum()<groupby>
preds52=np.load('.. /input/5-kfold-efficentne-e7-p2/probs.npz')
 preds52['a'].shape
data.groupby('Pclass' ).Fare.mean()<data_type_conversions>
preds53=np.load('.. /input/5-kfold-efficentne-e7-p3/probs.npz')
 preds53['a'].shape
data.Fare = data.Fare.fillna(0 )<count_values>
preds54=np.load('.. /input/5-kfold-efficentne-e7-p4/probs.npz')
 preds54['a'].shape
print(data.Embarked.value_counts())
 data.Embarked = data.Embarked.fillna('S' )<feature_engineering>
preds55=np.load('.. /input/5-kfold-efficentne-e7-p5/probs.npz')
 preds55['a'].shape
data.Cabin = data.Cabin.fillna('Unknown_Cabin')
 data['Cabin'] = data['Cabin'].str[0]<count_values>
preds55=(preds51['a']+preds52['a']+preds53['a']+preds54['a']+preds55['a'])/5
data.groupby('Pclass' ).Cabin.value_counts()<feature_engineering>
preds55=0.65*preds4['a']+0.35*preds55
data['Cabin'] = np.where(( data.Pclass==1)&(data.Cabin=='U'),'C',
np.where(( data.Pclass==2)&(data.Cabin=='U'),'D',
np.where(( data.Pclass==3)&(data.Cabin=='U'),'G',
np.where(data.Cabin=='T','C',data.Cabin))))<drop_column>
del preds1,preds2,preds3,preds4,preds55
gc.collect()
data['Title'] = data.Name.str.extract('([A-Za-z]+)\.', expand=False)
 pd.crosstab(data['Title'], data['Sex'])
 data = data.drop('Name',axis=1 )<feature_engineering>
preds6=np.load('.. /input/flowertpuwin-densenet201/probs.npz')
 preds6['a'].shape
data['Title'] = np.where(( data.Title=='Capt')|(data.Title=='Countess')|(data.Title=='Don')|(data.Title=='Dona')
 |(data.Title=='Jonkheer')|(data.Title=='Lady')|(data.Title=='Sir')|(data.Title=='Major')|(data.Title=='Rev')|(data.Title=='Col'),'Other',data.Title)
 data['Title'] = data['Title'].replace('Ms','Miss')
 data['Title'] = data['Title'].replace('Mlle','Miss')
 data['Title'] = data['Title'].replace('Mme','Mrs' )<groupby>
preds7=np.load('.. /input/flowertpuwin-densenet201/probs.npz')
 preds7['a'].shape
data.groupby('Title' ).Age.mean()<feature_engineering>
preds8=np.load('.. /input/tpu-enet-b7-incepention-b6-new/probs.npz')
 preds8['a'].shape
data['Age'] = np.where(( data.Age.isnull())&(data.Title=='Master'),5,
np.where(( data.Age.isnull())&(data.Title=='Miss'),22,
np.where(( data.Age.isnull())&(data.Title=='Mr'),32,
np.where(( data.Age.isnull())&(data.Title=='Mrs'),37,
np.where(( data.Age.isnull())&(data.Title=='Other'),45,
np.where(( data.Age.isnull())&(data.Title=='Dr'),44,data.Age))))))<feature_engineering>
preds=np.argmax(preds, axis=1)
 preds.shape
data['FamilySize'] = data.SibSp + data.Parch + 1
data['Mother'] = np.where(( data.Title=='Mrs')&(data.Parch >0),1,0)
 data['Free'] = np.where(data['Fare']==0, 1,0)
 data = data.drop(['SibSp','Parch','Sex'],axis=1 )<count_values>
submission = pd.read_csv('/kaggle/input/flower-blending-v1/submission.csv')
 submission.head()
TypeOfTicket = []
for i in range(len(data.Ticket)) :
ticket = data.Ticket.iloc[i]
for c in string.punctuation:
ticket = ticket.replace(c,"")
 splited_ticket = ticket.split(" ")
 if len(splited_ticket)== 1:
TypeOfTicket.append('NO')
 else:
TypeOfTicket.append(splited_ticket[0])
 data['TypeOfTicket'] = TypeOfTicket
data.TypeOfTicket.value_counts()
data['TypeOfTicket'] = np.where(( data.TypeOfTicket!='NO')&(data.TypeOfTicket!='PC')&(data.TypeOfTicket!='CA')& 
(data.TypeOfTicket!='A5')&(data.TypeOfTicket!='SOTONOQ'),'other',data.TypeOfTicket)
 data = data.drop('Ticket',axis=1 )<count_values>
submission1=submission.copy()
submission1['label']=preds
submission1.head()
counting_values(data, 'Title','Survived' )<count_values>
submission1.to_csv('submission.csv', index=False)
<count_values><EOS> 
submission1['y']=submission['label']
submission1.corr()