Kaggle competition: Aerial Cactus Identification
<SOS> metric: AUC Kaggle data source: aerial-cactus-identification<categorify>
import numpy as np
import pandas as pd
def one_hot_encoding(df):
df = pd.get_dummies(df)
 return df<categorify>
from pathlib import Path
from fastai import *
from fastai.vision import *
import torch
def label_encoding(train):
obj = [var for var in train.columns if train[var].dtype == 'object']
for c in obj:
le = LabelEncoder()
train[c] = le.fit_transform(train[c])
 return train<prepare_x_and_y>
data_folder = Path(".. /input")
s = df_train.shape[0]
y = df_train['SalePrice']
y_log = np.log1p(y)
 df_train = df_train.drop(columns = 'SalePrice')
 outliers=find_outliers(df_train)
 y_log.drop(outliers, inplace = True)
 X = pd.concat([df_train, df_test] )<create_dataframe>
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/sample_submission.csv" )
score = pd.DataFrame(columns = ['model', 'score'] )<categorify>
learn = cnn_learner(train_img, models.densenet201, metrics=[error_rate, accuracy] )
cleaned_X = clean_data(X)
 remove_columns(cleaned_X)
 label_encoding(cleaned_X)
 X_train_TM = cleaned_X.iloc[:s, :]
X_test_TM = cleaned_X.iloc[s:, :]
X_train_TM.drop(outliers, inplace = True)
 print('Missing values in the cleaned training set:', X_train_TM.isnull().sum().sum())
 print('Missing values in the cleaned testing set:', X_test_TM.isnull().sum().sum() )<choose_model_class>
lr = 3e-02
learn.fit_one_cycle(5, slice(lr))
xgb_model = xgb.XGBRegressor(learning_rate = 0.01, n_estimators = 5800,
max_depth = 2, min_child_weight = 1,
gamma = 0, subsample = 0.5,
colsample_bytree = 0.5,
objective = 'reg:linear', nthread = -1,
scale_pos_weight = 1, seed = 27,
reg_alpha = 0.2, random_state = 42)
 sc = cross_val_score(xgb_model, X_train_TM, y_log, scoring = "neg_mean_squared_error", cv = 10)
 np.sqrt(-sc.mean())
 score = score.append({'model': 'XGBoost', 'score': np.sqrt(-sc.mean())}, ignore_index = True)
 print('The score of the XGBoost model:', np.sqrt(-sc.mean()))<compute_train_metric>
preds,_ = learn.get_preds(ds_type=DatasetType.Test )
rforest_model = RandomForestRegressor(criterion = 'mse', max_depth = 18,
max_features = 0.4, min_samples_leaf = 1, min_samples_split = 2,
min_weight_fraction_leaf = 0, n_estimators = 5500, random_state = 0)
 sc = cross_val_score(rforest_model, X_train_TM, y_log, scoring = "neg_mean_squared_error", cv = 10)
 np.sqrt(-sc.mean())
 score = score.append({'model': 'RandomForest', 'score': np.sqrt(-sc.mean())}, ignore_index = True)
 print('The score of the RandomForest model:', np.sqrt(-sc.mean()))<choose_model_class>
test_df.has_cactus = preds.numpy() [:, 0]
gbr_model = GradientBoostingRegressor(loss = 'lad', learning_rate = 0.025, n_estimators = 5500,
subsample = 0.5, criterion = 'friedman_mse',
min_samples_split = 7, min_samples_leaf = 1, min_weight_fraction_leaf = 0.0,
max_depth = 2, min_impurity_decrease = 0.0, min_impurity_split = None, init = None,
random_state = 42, max_features = 'sqrt', alpha = 0.9, verbose = 0,
max_leaf_nodes = None, warm_start = False, presort = 'auto', validation_fraction = 0.3,
n_iter_no_change = None, tol = 0.0001)
 sc = cross_val_score(gbr_model, X_train_TM, y_log, scoring = "neg_mean_squared_error", cv = 10)
 np.sqrt(-sc.mean())
 score = score.append({'model': 'GradientBoosting', 'score': np.sqrt(-sc.mean())}, ignore_index = True)
 print('The score of the GradientBoosting model:', np.sqrt(-sc.mean()))<choose_model_class>
test_df.to_csv('submission.csv', index=False )