Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<prepare_x_and_y>
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.experimental import enable_hist_gradient_boosting
from sklearn.ensemble import HistGradientBoostingClassifier
import os
X = all_df.loc[~(all_df.Fare.isna())]
y = X['Fare'].values
X = X[features]
X_test = all_df.loc[all_df.Fare.isna() ]
X_test = X_test[features]
print(f'X: {X.shape} y: {y.shape}, X_text: {X_test.shape}' )<train_model>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
clf = DecisionTreeRegressor()
clf.fit(X, y)
 y_test = clf.predict(X_test )<train_model>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
print(f'Fare: {y_test}' )<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' )
all_df.loc[all_df.Fare.isna() , 'Fare'] = y_test<count_missing_values>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
all_df.loc[all_df.Fare.isna() ].shape<define_variables>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
all_df = [train_df, test_df]<feature_engineering>
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' )
for dataset in all_df:
dataset['Title'] = dataset.Name.str.extract('([A-Za-z]+)\.', expand=False )<feature_engineering>
X_train, X_val, y_train, y_val = train_test_split(train_InceptionResNetV2, target, test_size=0.1, random_state=42 )
for dataset in all_df:
dataset['Title'] = dataset['Title'].replace('Mlle', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Ms', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Mme', 'Mrs' )<filter>
%%time
clf = HistGradientBoostingClassifier(validation_fraction=None, random_state=137, max_iter=200, learning_rate=0.025)
 clf.fit(X_train, y_train )
train_df[(train_df['Title'] == 'Dr')&(train_df['Sex'] == 'female')]<filter>
val_preds = clf.predict_proba(X_val)[:,1]
train_df[train_df['Cabin']=='D17']<feature_engineering>
roc_auc_score(y_val, val_preds )
train_df.loc[train_df.PassengerId == 797, 'Title'] = 'Mrs'<filter>
log_loss(y_val, val_preds )
train_df[train_df['Cabin']=='D17']<feature_engineering>
test_preds = clf.predict_proba(test_InceptionResNetV2)[:,1]
<groupby><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()