Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<import_modules>
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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import Perceptron
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.ensemble import StackingClassifier
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.metrics import f1_score,mean_squared_error<load_from_csv>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
data = pd.read_csv("/kaggle/input/titanic/train.csv")
 test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 data.shape<count_unique_values>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
data.nunique().sort_values(ascending=False ).head(5 )<drop_column>
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' )
data.drop(["Name","Ticket","Cabin"],axis=1,inplace=True)
 data.head() ,data.shape<feature_engineering>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
imp = SimpleImputer(missing_values=np.nan, strategy='mean')
 data.Age = imp.fit_transform(data[['Age']] ).ravel()
imp2 = SimpleImputer(missing_values=np.nan,strategy='most_frequent')
 data.Embarked = imp2.fit_transform(data[['Embarked']] ).ravel()
data.Age.mean() ,data.Age.std() ,data.Age.isnull().sum()<groupby>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
data.groupby('Sex' ).Survived.mean()<data_type_conversions>
train_DenseNet201 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_2/train_DenseNet201.npy')
 test_DenseNet201 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_2/test_DenseNet201.npy' )
data['relatives'] = data['SibSp'] + data['Parch']
data.loc[data['relatives'] > 0, 'not_alone'] = 0
data.loc[data['relatives'] == 0, 'not_alone'] = 1
data['not_alone'] = data['not_alone'].astype(int )<categorify>
X_train, X_val, y_train, y_val = train_test_split(train_DenseNet201, target, test_size=0.1, random_state=42 )
data = data.join(pd.get_dummies(data['Sex']))
data = data.join(pd.get_dummies(data['Embarked']))
data.tail()<categorify>
%%time
lr = LogisticRegression(C=0.002, max_iter=10000)
 lr.fit(X_train, y_train )
test_data.drop(["Name","Ticket","Cabin"],axis=1,inplace=True)
 test_data['relatives'] = test_data['SibSp'] + test_data['Parch']
test_data.loc[test_data['relatives'] > 0, 'not_alone'] = 0
test_data.loc[test_data['relatives'] == 0, 'not_alone'] = 1
test_data['not_alone'] = test_data['not_alone'].astype(int)
 test_data.Age = imp.transform(test_data[['Age']] ).ravel()
test_data.Embarked = imp2.transform(test_data[['Embarked']] ).ravel()
test_data = test_data.join(pd.get_dummies(test_data['Sex']))
test_data = test_data.join(pd.get_dummies(test_data['Embarked']))
test_data.shape<define_variables>
val_preds = lr.predict_proba(X_val)[:,1]
f = ['Pclass','Age','SibSp','Parch','Fare','relatives','not_alone','female','C','Q']
len(f )<data_type_conversions>
roc_auc_score(y_val, val_preds )
test_data.Fare.fillna(method = 'ffill',inplace=True )<prepare_x_and_y>
log_loss(y_val, val_preds )
X = data[f]
X_test = test_data[f]
y = data['Survived']<choose_model_class>
test_preds = lr.predict_proba(test_DenseNet201)[:,1]
<choose_model_class><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()