Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<categorify>
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
titanic['Embarked_fz'] = pd.factorize(titanic['Embarked'], sort=True)[0]<prepare_x_and_y>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
X = titanic.drop({'PassengerId', 'Survived', 'SibSp', 'Parch', 'Embarked'}, axis=1)
 y = titanic['Survived']<split>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42 )<choose_model_class>
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' )
clf = RandomForestClassifier()<define_search_space>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
parametrs = { 'n_estimators': range(10, 51, 10),
'max_depth': range(1,13, 2),
'min_samples_leaf': range(1,8),
'min_samples_split': range(2,10,2)}<train_on_grid>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
grid = GridSearchCV(clf, parametrs, cv=5)
 grid.fit(X_train, y_train )<find_best_params>
train_EB2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/train_EB2.npy')
 test_EB2 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/test_EB2.npy' )
grid.best_estimator_<predict_on_test>
X_train, X_val, y_train, y_val = train_test_split(train_EB2, target, test_size=0.1, random_state=42 )
y_pred = grid.predict(X_test)
 y_proba = grid.predict_proba(X_test)
 y_proba = y_proba[:, 1]<compute_test_metric>
%%time
lr = LogisticRegression(C=0.015, max_iter=10000)
 lr.fit(X_train, y_train )
confusion_matrix(y_test, y_pred )<compute_test_metric>
val_preds = lr.predict_proba(X_val)[:,1]
precision_score(y_test, y_pred )<compute_test_metric>
roc_auc_score(y_val, val_preds )
recall_score(y_test, y_pred )<compute_test_metric>
log_loss(y_val, val_preds )
f1_score(y_test, y_pred )<load_from_csv>
test_preds = lr.predict_proba(test_EB2)[:,1]
<save_to_csv><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()