Kaggle competition: Shelter Animal Outcomes
learn = cnn_learner(data, models.resnet101, metrics = accuracy, model_dir='/tmp/model/' )<load_pretrained>
data_all = pd.concat([train,test])
 data_all = data_all.drop('AnimalID',axis=1)
 data_all = data_all.drop('ID',axis=1 )
learn.load('resnet-101-1');<predict_on_test>
X = []
X_t = []
for c in data_all.columns:
le = LabelEncoder()
le.fit(data_all[c].values)
 X.append(le.transform(train[c].values))
X_t.append(le.transform(test[c].values))
X = np.vstack(X ).T
X_t = np.vstack(X_t ).T
preds, _ = learn.get_preds(ds_type=DatasetType.Test )<feature_engineering>
def make_mf_classifier(X ,y, clf, X_test,n_folds=2, n_round=5):
n = X.shape[0]
len_y = len(np.unique(y))
mf_tr = np.zeros(( X.shape[0],len_y))
mf_te = np.zeros(( X_test.shape[0],len_y))
for i in range(n_round):
skf = StratifiedKFold(y, n_folds=n_folds, shuffle=True, random_state=42+i*1000)
 for ind_tr, ind_te in skf:
X_tr = X[ind_tr]
X_te = X[ind_te]
y_tr = y[ind_tr]
y_te = y[ind_te]
clf.fit(X_tr, y_tr)
 mf_tr[ind_te] += clf.predict_proba(X_te)
 mf_te += clf.predict_proba(X_test)*0.5
y_pred = clf.predict_proba(X_te)
 score = log_loss(y_te, y_pred)
 print('pred[{}],score[{}]'.format(i,score))
return(mf_tr / n_round, mf_te / n_round)
 skf = StratifiedKFold(y, n_folds=5, shuffle=True, random_state=seed)
 for ind_tr, ind_te in skf:
X_train = X[ind_tr]
X_test = X[ind_te]
y_train = y[ind_tr]
y_test = y[ind_te]
break
print(X_train.shape,X_test.shape)
<save_to_csv><EOS> 
xgboost = xgb.XGBClassifier(
 n_estimators=1000,
learning_rate = 0.03,
max_depth=6,
subsample=0.7,
colsample_bytree = 0.7,
reg_lambda = 4,
seed = seed, 
)
 xgboost.fit(
 X_train,
y_train,
eval_metric='mlogloss',
eval_set=[(X_train,y_train),(X_test,y_test)],
early_stopping_rounds=100, 
)
 y_preds = xgboost.predict_proba(X_test)
 res = xgboost.predict_proba(X_t)
 submission = pd.DataFrame()
submission["ID"] = np.arange(res.shape[0])+1
submission["Adoption"]= res[:,0]
submission["Died"]= res[:,1]
submission["Euthanasia"]= res[:,2]
submission["Return_to_owner"]= res[:,3]
submission["Transfer"]= res[:,4]
submission.to_csv("sub10.csv",index=False )