Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<compute_train_metric>
import numpy as np
import pandas as pd
import torch
from fastai import *
from fastai.vision import *
knn = KNeighborsClassifier(n_neighbors = 11)
 Estimator.append(( 'knn',KNeighborsClassifier(n_neighbors = 13)))
 cv = cross_val_score(knn,x_train1,x_test,cv=10)
 Accuracy9 = cv.mean()
Accuracy.append(Accuracy9)
 print(cv)
 print(cv.mean() )<train_model>
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/sample_submission.csv" )
knn.fit(x_train1,x_test)
 knn.score(y_train1,y_test )<save_to_csv>
test_img = ImageList.from_df(test_df, path='.. /input/test', folder='test' )
model19pred = knn.predict(y_train)
 submission19 = pd.DataFrame(columns = ['PassengerId','Survived'])
 submission19['PassengerId'] = result['PassengerId']
submission19['Survived'] = model19pred
submission19.to_csv('KNN(StdScaler ).csv',index = False )<create_dataframe>
trfm2 = get_transforms(do_flip=True, flip_vert=True, max_rotate=0, max_zoom=0, max_lighting=0.2, max_warp=0.2, p_affine=0.5, p_lighting=0.5 )
models = ['Logistic Regression','SVM Linear Classifier','SVM Polynomial Classifier','Decision Tree','Multinomial NB','Random Forest Classifier','Gradient Boost Classifier','XG Boosting','K-Nearest Neighbors(StdScaler)']
total = list(zip(models,Accuracy))
output2 = pd.DataFrame(total, columns = ['Models after Hyperparameter Tuning','Accuracy after HT'] )<save_to_csv>
train_img2 =(ImageList.from_df(train_df, path='.. /input/train', folder='train')
.split_by_rand_pct(0.01)
.label_from_df() 
.add_test(test_img)
.transform(trfm2, size=128)
.databunch(path='.', bs=64, device= torch.device('cuda:0')) 
.normalize(imagenet_stats)
 )
vot_soft1 = VotingClassifier(estimators = Estimator, voting ='soft')
 vot_soft1.fit(x_train, x_test)
 y_pred = vot_soft1.predict(y_train)
 vot_soft1.score(y_train,y_test)
 modelpred3 = vot_soft1.predict(y_train)
 sub3 = pd.DataFrame(columns = ['PassengerId','Survived'])
 sub3['PassengerId'] = result['PassengerId']
sub3['Survived'] = modelpred3
sub3.to_csv('SoftVoting(HT ).csv',index = False )<train_on_grid>
learn2 = cnn_learner(train_img2, models.densenet161, metrics=[error_rate, accuracy] )
vot_soft1.fit(x_train, x_test)
 vot_soft1.score(y_train,y_test )<save_to_csv>
learn2.fit_one_cycle(5, slice(3e-02))
vot_hard1 = VotingClassifier(estimators = Estimator, voting ='hard')
 vot_hard1.fit(x_train, x_test)
 y_pred = vot_hard1.predict(y_train)
 vot_hard1.score(y_train,y_test)
 modelpred4 = vot_hard1.predict(y_train)
 sub4 = pd.DataFrame(columns = ['PassengerId','Survived'])
 sub4['PassengerId'] = result['PassengerId']
sub4['Survived'] = modelpred4
sub4.to_csv('HardVoting(HT ).csv',index = False )<train_on_grid>
preds,_ = learn2.get_preds(ds_type=DatasetType.Test )
vot_hard1.fit(x_train, x_test)
 vot_hard1.score(y_train,y_test )<concatenate>
test_df.has_cactus = preds.numpy() [:, 0]
<load_from_csv><EOS> 
test_df.to_csv('submission.csv', index=False)