Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<feature_engineering>
import numpy as np
import pandas as pd
import zipfile
from sklearn.model_selection import train_test_split, KFold
from sklearn.metrics import log_loss, roc_auc_score
from sklearn.linear_model import LogisticRegression
import os
df.loc[(df.Age.isnull())&(df.Initial=='Master'),"Age"]=5
df.loc[(df.Age.isnull())&(df.Initial=='Miss'),"Age"]=22
df.loc[(df.Age.isnull())&(df.Initial=='Mr'),"Age"]=33
df.loc[(df.Age.isnull())&(df.Initial=='Mrs'),"Age"]=36
df.loc[(df.Age.isnull())&(df.Initial=='Other'),"Age"]=46<set_options>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
print(df.Embarked.mode())
 df.Embarked.fillna("S",inplace=True )<feature_engineering>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
df["Family_size"]=df["SibSp"]+df["Parch"]
df["Alone"]=0
df.loc[df.Family_size==0,"Alone"]=1<feature_engineering>
train_image_list = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/train_image_list.npy')
 test_image_list = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/test_image_list.npy' )
df['Age_band']=0
df.loc[df['Age']<=16,'Age_band']=0
df.loc[(df['Age']>16)&(df['Age']<=32),'Age_band']=1
df.loc[(df['Age']>32)&(df['Age']<=48),'Age_band']=2
df.loc[(df['Age']>48)&(df['Age']<=64),'Age_band']=3
df.loc[df['Age']>64,'Age_band']=4<feature_engineering>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
df['Fare_cat']=0
df.loc[df['Fare']<=7.91,'Fare_cat']=0
df.loc[(df['Fare']>7.91)&(df['Fare']<=14.454),'Fare_cat']=1
df.loc[(df['Fare']>14.454)&(df['Fare']<=31),'Fare_cat']=2
df.loc[(df['Fare']>31)&(df['Fare']<=513),'Fare_cat']=3<categorify>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
df['Sex'].replace(['male','female'],[0,1],inplace=True)
 df['Embarked'].replace(['S','C','Q'],[0,1,2],inplace=True)
 df['Initial'].replace(['Mr','Mrs','Miss','Master','Other'],[0,1,2,3,4],inplace=True )<drop_column>
train_InceptionResNetV2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/train_InceptionResNetV2.npy')
 test_InceptionResNetV2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/test_InceptionResNetV2.npy' )
df.drop(['Name','Age','Ticket','Fare','Cabin','Fare_Range','PassengerId'],axis=1,inplace=True )<count_missing_values>
X_train, X_val, y_train, y_val = train_test_split(train_InceptionResNetV2, target, test_size=0.1, random_state=42 )
df.isnull().sum()<feature_engineering>
%%time
lr = LogisticRegression(C=0.005, max_iter=10000)
 lr.fit(X_train, y_train )
test_df.loc[(test_df.Age.isnull())&(test_df.Initial=='Master'),"Age"]=5
test_df.loc[(test_df.Age.isnull())&(test_df.Initial=='Miss'),"Age"]=22
test_df.loc[(test_df.Age.isnull())&(test_df.Initial=='Mr'),"Age"]=33
test_df.loc[(test_df.Age.isnull())&(test_df.Initial=='Mrs'),"Age"]=36
test_df.loc[(test_df.Age.isnull())&(test_df.Initial=='Other'),"Age"]=46
test_df.Embarked.fillna("S",inplace=True )<feature_engineering>
val_preds = lr.predict_proba(X_val)[:,1]
test_df["Family_size"]=test_df["SibSp"]+test_df["Parch"]
test_df["Alone"]=0
test_df.loc[df.Family_size==0,"Alone"]=1<feature_engineering>
roc_auc_score(y_val, val_preds )
test_df['Age_band']=0
test_df.loc[test_df['Age']<=16,'Age_band']=0
test_df.loc[(test_df['Age']>16)&(test_df['Age']<=32),'Age_band']=1
test_df.loc[(test_df['Age']>32)&(test_df['Age']<=48),'Age_band']=2
test_df.loc[(test_df['Age']>48)&(test_df['Age']<=64),'Age_band']=3
test_df.loc[test_df['Age']>64,'Age_band']=4<filter>
log_loss(y_val, val_preds )
test_df[test_df.Fare.isnull() ]<feature_engineering>
test_preds = lr.predict_proba(test_InceptionResNetV2)[:,1]
<categorify><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()