Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<save_to_csv>
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
gnb = GaussianNB()
y_pred = gnb.fit(train[features1].as_matrix() , train[target].as_matrix().flatten() ).predict(valid[features1].as_matrix())
 print_acc(float(np.array(y_pred == valid[target].as_matrix().flatten() , dtype=np.int ).sum() * 100)/ len(valid), "Naive Bayes")
 result = pd.DataFrame(data={'PassengerId': test_csv['PassengerId'], 'Survived': gnb.predict(test_data[features1].as_matrix())})
 result.to_csv(path_or_buf='naive_bayes_submittion.csv', index = False, header = True )<train_on_grid>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
clf1 = LogisticRegression(random_state=1)
 clf2 = RandomForestClassifier(n_estimators=25,random_state=1)
 clf3 = GaussianNB(var_smoothing=True)
 clf4 = LinearSVC(random_state=5)
 gbm = xgb.XGBClassifier(max_depth=5, n_estimators=300, learning_rate=0.05)
 eclf1 = VotingClassifier(estimators=[('lr', clf1),('rf', clf2),('gnb', clf3),('xgb', gbm)], voting='soft')
 eclf1 = eclf1.fit(train[features1].as_matrix() , train[target].as_matrix().flatten())
 print_acc(float(np.array(eclf1.predict(valid[features1].as_matrix())== valid[target].as_matrix().flatten() , dtype=np.int ).sum() * 100)/ len(valid), "Voting")
 result = pd.DataFrame(data={'PassengerId': test_csv['PassengerId'], 'Survived': eclf1.predict(test_data[features1].as_matrix())})
 result.to_csv(path_or_buf='soft_voting_submittion.csv', index = False, header = True )<save_to_csv>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
gbm = xgb.XGBClassifier(max_depth=3, n_estimators=600, learning_rate=0.05)
 y_pred = gbm.fit(train[features1].as_matrix() , train[target].as_matrix().flatten() ).predict(valid[features1].as_matrix())
 print_acc(float(np.array(y_pred == valid[target].as_matrix().flatten() , dtype=np.int ).sum() * 100)/ len(valid), "XGB")
 result = pd.DataFrame(data={'PassengerId': test_csv['PassengerId'], 'Survived': gbm.predict(test_data[features1].as_matrix())})
 result.to_csv(path_or_buf='gbm_submittion.csv', index = False, header = True )<import_modules>
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' )
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestClassifier<feature_engineering>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
train=pd.read_csv(".. /input/train.csv")
 test=pd.read_csv(".. /input/test.csv")
 def append_train_test(train,test):
train["IsTrain"]=1
test["IsTrain"]=0
df=train.append(test)
 return df;
full=append_train_test(train,test)
 train.info()
print("------------------------")
 test.info()
print("------------------------")
 full.info() 
<filter>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
full.loc[(full["Title"].isin(["Rev","Dr","Col","Capt","Major"])) &(full["Sex"]!="male")]<feature_engineering>
train_EB3 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/train_EB3.npy')
 test_EB3 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/test_EB3.npy' )
full.loc[(full["Title"].isin(["Rev","Capt","Major","Col","Jonkheer","Don","Sir","Dr"])) &(full["Sex"]=="male"),"Title"] = "Mr"
full.loc[(full["Title"].isin(["Countess","Lady","Dona","Mme"])) ,"Title"]="Mrs"
full.loc[(full["Title"].isin(["Mlle","Ms","Dr"])) &(full["Sex"]=="female"),"Title"]="Miss"
full["Title"].value_counts(normalize=True )<count_missing_values>
X_train, X_val, y_train, y_val = train_test_split(train_EB3, target, test_size=0.1, random_state=42 )
full.isnull().sum()<filter>
%%time
lr = LogisticRegression(C=0.008, max_iter=10000)
 lr.fit(X_train, y_train )
full[full.Fare.isnull() ]<feature_engineering>
val_preds = lr.predict_proba(X_val)[:,1]
full.loc[(full.Fare.isnull()),"Fare"]=8.05<filter>
roc_auc_score(y_val, val_preds )
full[full.Embarked.isnull() ]<feature_engineering>
log_loss(y_val, val_preds )
full.loc[(full.Embarked.isnull()),"Embarked"]="C"<prepare_output>
test_preds = lr.predict_proba(test_EB3)[:,1]
<feature_engineering><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()