Kaggle competition: Aerial Cactus Identification
param_grid = {
'learning_rate' : [0.1, 0.2],
'max_depth': [3, 5, 7],
}
xgBoost_CV = GridSearchCV(estimator = XGBClassifier() , param_grid = param_grid, cv = 3)
 xgBoost_CV.fit(X_train, y_train)
 print(xgBoost_CV.best_score_)
 learning = xgBoost_CV.best_params_.get('learning_rate')
 depth = xgBoost_CV.best_params_.get('max_depth')
 bestXGB = XGBClassifier(learning_rate=learning, max_depth=depth)
 print(bestXGB)
 bestXGB.fit(X_train, y_train)
 testPredictionsXGB = bestXGB.predict(X_test)
 outputGB = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': testPredictionsXGB})
 outputGB.to_csv('my_submissionXGB.csv', index=False )<init_hyperparams>
from pathlib import Path
from fastai import *
from fastai.vision import *
import torch
finish_data = 2014
lgb_num_leaves_max = 200
lgb_in_leaf = 10
lgb_lr = 0.001
lgb_bagging = 7
xgb_max_depth = 7
xgb_min_child_weight = 75
xgb_lr = 0.0004
xgb_num_boost_round_max = 3000
w_lgb = 0.4
w_xgb = 0.5
w_logreg = 1 - w_lgb - w_xgb
w_logreg<set_options>
data_folder = Path(".. /input" )
warnings.filterwarnings("ignore" )<load_from_csv>
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/sample_submission.csv" )
tourney_result = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WNCAATourneyCompactResults.csv')
 if finish_data == 2014:
tourney_result = tourney_result[tourney_result['Season'] < 2015]
tourney_seed = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WNCAATourneySeeds.csv')
 if finish_data == 2014:
tourney_seed = tourney_seed[tourney_seed['Season'] < 2015]
tourney_result = tourney_result.drop(['DayNum', 'WScore', 'LScore', 'WLoc', 'NumOT'], axis=1)
 tourney_result = pd.merge(tourney_result, tourney_seed, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Seed':'WSeed'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1)
 tourney_result = pd.merge(tourney_result, tourney_seed, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Seed':'LSeed'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1 )<feature_engineering>
train_img.show_batch(rows=3, figsize=(7,6))
def get_seed(x):
return int(x[1:3])
 tourney_result['WSeed'] = tourney_result['WSeed'].map(lambda x: get_seed(x))
tourney_result['LSeed'] = tourney_result['LSeed'].map(lambda x: get_seed(x))<load_from_csv>
learn = cnn_learner(train_img, models.densenet161, metrics=[error_rate, accuracy] )
season_result = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WRegularSeasonCompactResults.csv')
 if finish_data == 2014:
season_result = season_result[season_result['Season'] < 2015]
season_win_result = season_result[['Season', 'WTeamID', 'WScore']]
season_lose_result = season_result[['Season', 'LTeamID', 'LScore']]
season_win_result.rename(columns={'WTeamID':'TeamID', 'WScore':'Score'}, inplace=True)
 season_lose_result.rename(columns={'LTeamID':'TeamID', 'LScore':'Score'}, inplace=True)
 season_result = pd.concat(( season_win_result, season_lose_result)).reset_index(drop=True)
 season_score = season_result.groupby(['Season', 'TeamID'])['Score'].sum().reset_index()<merge>
lr = 3e-02
learn.fit_one_cycle(6, slice(lr))
tourney_result = pd.merge(tourney_result, season_score, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Score':'WScoreT'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1)
 tourney_result = pd.merge(tourney_result, season_score, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Score':'LScoreT'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1 )<drop_column>
preds,_ = learn.get_preds(ds_type=DatasetType.Test )
tourney_win_result = tourney_result.drop(['Season', 'WTeamID', 'LTeamID'], axis=1)
 tourney_win_result.rename(columns={'WSeed':'Seed1', 'LSeed':'Seed2', 'WScoreT':'ScoreT1', 'LScoreT':'ScoreT2'}, inplace=True )<prepare_output>
test_df.has_cactus = preds.numpy() [:, 0]
<feature_engineering><EOS> 
test_df.to_csv('submission.csv', index=False )