Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<choose_model_class>
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
classifier = Sequential()
classifier.add(Convolution2D(filters = 128, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 classifier.add(MaxPooling2D(pool_size=(2,2)))
 classifier.add(BatchNormalization())
 classifier.add(Convolution2D(filters = 128, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
classifier.add(BatchNormalization())
 classifier.add(MaxPooling2D(pool_size=(2,2)))
 classifier.add(Dropout(0.25))<choose_model_class>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
classifier.add(Convolution2D(filters =256, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
classifier.add(BatchNormalization())
 classifier.add(MaxPooling2D(pool_size=(2,2)))
 classifier.add(Convolution2D(filters = 256, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
classifier.add(BatchNormalization())
 classifier.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
 classifier.add(Dropout(0.25))<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
classifier.add(Flatten())
 classifier.add(Dense(256, activation = "relu"))
classifier.add(Dropout(0.3))
classifier.add(Dense(10, activation = "softmax"))<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' )
classifier.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['accuracy'] )<train_model>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
classifier.fit(target,label_cat,epochs=50 )<save_to_csv>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
results=classifier.predict_classes(df_test)
 print(results)
 results = pd.Series(results,name="Label")
 submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("submission.csv",index=False,header=True )<train_model>
train_EB4_ns = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_4/cats_and_dogs_4/train_EB4_ns.npy')
 test_EB4_ns = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_4/cats_and_dogs_4/test_EB4_ns.npy' )
( X_train,y_train),(X_test,y_test)=mnist.load_data()
print(X_train.shape)
 print(X_test.shape)
 print(type(X_train))
img=X_train[0]
plt.imshow(img,cmap='gray')
 print(type(img))<categorify>
X_train, X_val, y_train, y_val = train_test_split(train_EB4_ns, target, test_size=0.1, random_state=42 )
X_train=X_train.reshape(60000,28,28,1)
 X_test=X_test.reshape(10000,28,28,1)
 y_cat_train=to_categorical(y_train,10)
 y_cat_test=to_categorical(y_test,10 )<train_model>
%%time
lr = LogisticRegression(C=0.019, max_iter=10000)
 lr.fit(X_train, y_train )
classifier.fit(X_train,y_cat_train,epochs=25 )<save_to_csv>
val_preds = lr.predict_proba(X_val)[:,1]
results=classifier.predict_classes(df_test)
 print(results)
 results = pd.Series(results,name="Label")
 submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("submission1.csv",index=False,header=True )<train_model>
roc_auc_score(y_val, val_preds )
classifier.fit(X_test,y_cat_test,epochs=25 )<save_to_csv>
log_loss(y_val, val_preds )
results=classifier.predict_classes(df_test)
 print(results)
 results = pd.Series(results,name="Label")
 submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("submission2.csv",index=False,header=True )<train_model>
test_preds = lr.predict_proba(test_EB4_ns)[:,1]
<load_from_csv><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()