Kaggle competition: Dogs vs. Cats Redux: Kernels Edition
<SOS> metric: LogLoss Kaggle data source: dogs-vs.-cats-redux:-kernels-edition<define_variables>
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
features=["Age","Embarked","Fare","Parch","Pclass","Sex","SibSp","Title","FamilySize","FamilySizeBand"]
target="Survived"
full[features].head()<find_best_model_class>
sample_submission = pd.read_csv('/kaggle/input/dogs-vs-cats-redux-kernels-edition/sample_submission.csv')
 sample_submission.tail()
clf = RandomForestClassifier(n_jobs=2, random_state=0)
 clf = clf.fit(train_features, train_target)
 train_preds=clf.predict(train_features)
 print(clf)
 for i in range(0,10):
print(features[i]," ",clf.feature_importances_[i] )<compute_test_metric>
TRAIN_FOLDER = '.. /input/cats-and-dogs-embedded-data/train/train/'
TEST_FOLDER = '.. /input/cats-and-dogs-embedded-data/test/test/'
IMG_SIZE = 224
pd.crosstab(train_target, train_preds, rownames=['Actual Outcome'], colnames=['Predicted Outcome'] )<prepare_output>
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' )
test_preds=clf.predict(test_features ).astype(int)
 test_ids=full[891:]["PassengerId"]
final = pd.DataFrame({
"PassengerId": test_ids,
"Survived": test_preds
})
 final.info()<save_to_csv>
ids = [int(x.split('.')[0])for x in test_image_list]
ids[:20]
final.to_csv('submission2.csv', index=False )<install_modules>
target = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_1/target.npy' )
!pip install seaborn==0.11.0<load_from_csv>
train_EB6 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/train_EB6.npy')
 test_EB6 = np.load('.. /input/cats-and-dogs-embedded-data/cats_and_dogs_3/cats_and_dogs_3/test_EB6.npy' )
titanic = pd.read_csv('/kaggle/input/titanic/train.csv' )<count_missing_values>
X_train, X_val, y_train, y_val = train_test_split(train_EB6, target, test_size=0.1, random_state=42 )
titanic.isnull().sum()<drop_column>
%%time
lr = LogisticRegression(C=0.02, max_iter=10000)
 lr.fit(X_train, y_train )
titanic = titanic.drop({'Name', 'Ticket', 'Cabin'}, axis=1 )<count_values>
val_preds = lr.predict_proba(X_val)[:,1]
titanic['Embarked']= titanic['Embarked'].fillna(titanic['Embarked'].value_counts().index[0] )<create_dataframe>
roc_auc_score(y_val, val_preds )
pd.pivot_table(titanic, values='Age', index=['Sex'], columns=['Pclass'], aggfunc=np.mean )<feature_engineering>
log_loss(y_val, val_preds )
for Pclass in titanic.Pclass.unique() :
for Sex in titanic.Sex.unique() :
titanic[(titanic['Pclass'] == Pclass)&(titanic['Sex'] == Sex)] = \
titanic[(titanic['Pclass'] == Pclass)&(titanic['Sex'] == Sex)] \ 
.fillna(np.rint(titanic[(titanic['Pclass'] == Pclass)&(titanic['Sex'] == Sex)].Age.mean()))<count_missing_values>
test_preds = lr.predict_proba(test_EB6)[:,1]
<categorify><EOS> 
sample_submission['id'] = ids
sample_submission['label'] = test_preds
sample_submission.to_csv('submission.csv', index=False)
 sample_submission.head()