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.linear_model import LogisticRegression
import os
X = train.drop(columns=['Survived'])
 y = train['Survived']<split>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42 )<choose_model_class>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
model = LGBMClassifier(learning_rate=0.01, n_estimators=1000 )<train_model>
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' )
model.fit(X_train, y_train )<train_model>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
model.fit(X_train, y_train )<predict_on_test>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
pred = model.predict(X_test )<compute_test_metric>
train_EB1_ns = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_4/cats_and_dogs_4/train_EB1_ns.npy')
 test_EB1_ns = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_4/cats_and_dogs_4/test_EB1_ns.npy' )
print("R2-score: ",r2_score(pred, y_test))
print("Accuracy score: ",accuracy_score(pred, y_test))
print("F1-score: ",f1_score(pred, y_test))<predict_on_test>
X_train, X_val, y_train, y_val = train_test_split(train_EB1_ns, target, test_size=0.1, random_state=42 )
actual_pred = model.predict(test )<create_dataframe>
%%time
lr = LogisticRegression(C=0.02, max_iter=10000)
 lr.fit(X_train, y_train )
result = pd.DataFrame({'PassengerId':test['PassengerId'], 'Survived':actual_pred} )<save_to_csv>
val_preds = lr.predict_proba(X_val)[:,1]
result.to_csv("submission.csv", index=False )<load_from_csv>
roc_auc_score(y_val, val_preds )
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )<string_transform>
log_loss(y_val, val_preds )
def extract_title(name):
name = name.split()
for w in name:
if '.' in w:
return w
return None
all_titles = pd.concat([train, test], sort=False ).Name.apply(lambda name: extract_title(name))
all_titles.unique()<feature_engineering>
test_preds = lr.predict_proba(test_EB1_ns)[:,1]
<groupby><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()