Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<import_modules>
import numpy as np
import pandas as pd
from pathlib import Path
from fastai import *
from fastai.vision import *
import torch
from sklearn.pipeline import make_pipeline
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble.gradient_boosting import GradientBoostingClassifier
from sklearn.feature_selection import SelectKBest
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import cross_val_score
from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import LogisticRegression, LogisticRegressionCV
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
import xgboost as xgb<choose_model_class>
data_folder = Path(".. /input")
logreg = LogisticRegression()
Gauss = GaussianNB()
rf = RandomForestClassifier()
gboost = GradientBoostingClassifier()
DTC = DecisionTreeClassifier()
RF = RandomForestClassifier(n_estimators=200)
 SVectorMachine = SVC()
xgb = xgb.XGBClassifier(max_depth=3, n_estimators=10, learning_rate=0.01)
 models = [logreg,Gauss, gboost,DTC,RF,SVectorMachine,xgb]<compute_train_metric>
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/sample_submission.csv" )
def compute_score(clf, X, y, scoring='accuracy'):
xval = cross_val_score(clf, X, y, cv = 10, scoring=scoring)
 return np.mean(xval )<compute_train_metric>
train_img.show_batch(rows=3, figsize=(7,6))
for model in models:
print('Cross-validation of : {0}'.format(model.__class__))
score = compute_score(clf=model, X=X_train2, y=y, scoring='accuracy')
 print('CV score = {0}'.format(score))
print('----->>>>>>' )<data_type_conversions>
learn = cnn_learner(train_img, models.densenet161, metrics=[error_rate, accuracy] )
X = np.asarray(X_train2 ).astype(np.float32)
 Y = np.asarray(y ).astype(np.float32 )<train_model>
lr = 3e-02
learn.fit_one_cycle(5, slice(lr))
classifier = Sequential()
classifier.add(Dense(units = 35,activation = "relu",kernel_initializer="uniform",input_dim=33))
classifier.add(Dropout(rate=0.1))
classifier.add(Dense(units = 20,activation = "relu",kernel_initializer="uniform"))
classifier.add(Dense(units = 15,activation = "relu",kernel_initializer="uniform"))
classifier.add(Dense(units = 1,activation = "sigmoid",kernel_initializer="uniform"))
classifier.compile(optimizer="rmsprop",loss="binary_crossentropy",metrics=['acc'])
 classifier.fit(X,Y,batch_size=50,epochs=110 )<save_to_csv>
preds,_ = learn.get_preds(ds_type=DatasetType.Test )
result = []
Y_pred = classifier.predict(np.asarray(X_test2 ).astype(np.float32))
Y_pred =(Y_pred>0.55)
 for i in range(len(Y_pred)) :
if Y_pred[i][0] == True :
result.append(1)
 else :
result.append(0)
 PassengerId = df_test["PassengerId"]
SurvivedResult = pd.DataFrame({'Survived': result})
 results = pd.concat([PassengerId,SurvivedResult],axis=1)
 results.to_csv("gender_submission.csv",sep = ',',index=False )<import_modules>
test_df.has_cactus = preds.numpy() [:, 0]
<load_from_csv><EOS> 
test_df.to_csv('submission.csv', index=False )