Kaggle competition: Freesound Audio Tagging 2019
start = time.time()
print('gpu training begins...')
 model = XGBRegressor(
 max_depth=8,
n_estimators=1000,
min_child_weight=300,
colsample_bytree=0.8,
subsample=0.8,
eta=0.3,
seed=42,
tree_method='gpu_hist' 
)
 model.fit(
 X_train,
Y_train,
eval_metric='rmse',
eval_set=[(X_train, Y_train),(X_valid, Y_valid)],
verbose=True,
early_stopping_rounds = 10)
 print('GPU Xgb costs {:.2f} seconds'.format(time.time() -start))<train_model>
CSV_TRN_CURATED = DATA/'train_curated.csv'
CSV_TRN_NOISY = PREPROCESSED/'trn_noisy_best50s.csv'
CSV_SUBMISSION = DATA/'sample_submission.csv'
MELS_TRN_CURATED = PREPROCESSED/'mels_train_curated.pkl'
MELS_TRN_NOISY = '.. /input/fat2019_prep_mels1/mels_trn_noisy_best50s.pkl'
MELS_TEST = PREPROCESSED/'mels_test.pkl'
trn_curated_df = pd.read_csv(CSV_TRN_CURATED)
 trn_noisy_df = pd.read_csv(CSV_TRN_NOISY)
 test_df = pd.read_csv(CSV_SUBMISSION)
 df = pd.concat([trn_curated_df, trn_noisy_df], ignore_index=True)
 test_df = pd.read_csv(CSV_SUBMISSION)
 X_train = pickle.load(open(MELS_TRN_CURATED, 'rb'))
with open(".. /input/fat2019_prep_mels1/mels_trn_noisy_best50s.pkl", 'rb')as f:
X_train.append(pickle.load(f))
X_test = pickle.load(open(MELS_TEST, 'rb'))
start = time.time()
print('cpu training begins...')
 model = CatBoostRegressor(eval_metric='RMSE',
iterations=1000,
max_ctr_complexity=4,
random_seed=42,
od_type='Iter',
od_wait=100,
verbose=50,
depth=4,
metric_period = 50 
)
 Y_train = np.array(Y_train ).astype('float32')
 Y_valid = np.array(Y_valid ).astype('float32')
 model.fit(X_train,
Y_train,
eval_set=[(X_train, Y_train),(X_valid, Y_valid)],
verbose=True,
use_best_model=True)
 print('CPU Cat costs {:.2f} seconds'.format(time.time() -start))<save_to_csv>
list_model = [ models.vgg16_bn, models.vgg19_bn]
predicts = None
i = 0
print('learning rate:',model.learning_rate_)
 Y_pred = model.predict(X_valid ).clip(0, 20)
 Y_test = model.predict(X_test ).clip(0, 20)
 submission = pd.DataFrame({ 'ID': test.index, 'item_cnt_month': Y_test})
 submission.to_csv('submission.csv', index=False )<train_model>
print(list_model[i])
 CUR_X_FILES, CUR_X = list(df.fname.values), X_train
f_score = partial(fbeta, thresh=0.2)
 learn = cnn_learner(data, list_model[i], pretrained=False, metrics=[f_score])
 learn.unfreeze()
learn.lr_find()
learn.fit_one_cycle(5, slice(1e-6, 1e-1))
learn.lr_find()
learn.fit_one_cycle(100, slice(1e-6, 1e-2))
learn.export()
CUR_X_FILES, CUR_X = list(test_df.fname.values), X_test
test = ImageList.from_csv(WORK, Path('.. ')/CSV_SUBMISSION, folder='test')
 learn = load_learner(WORK, test=test)
 preds, _ = learn.get_preds(ds_type=DatasetType.Test)
 if predicts is None:
predicts = preds
else:
predicts += preds
i+=1
start = time.time()
print('gpu training begins...')
 model = CatBoostRegressor(eval_metric='RMSE',
iterations=1000,
max_ctr_complexity=4,
random_seed=42,
od_type='Iter',
od_wait=100,
verbose=50,
depth=8,
metric_period = 50,
task_type='GPU' 
)
 Y_train = np.array(Y_train ).astype('float32')
 Y_valid = np.array(Y_valid ).astype('float32')
 model.fit(X_train,
Y_train,
eval_set=[(X_valid, Y_valid)],
verbose=True,
use_best_model=True)
 print('GPU Cat costs {:.2f} seconds'.format(time.time() -start))<load_from_csv>
print(list_model[i])
 CUR_X_FILES, CUR_X = list(df.fname.values), X_train
f_score = partial(fbeta, thresh=0.2)
 learn = cnn_learner(data, list_model[i], pretrained=False, metrics=[f_score])
 learn.unfreeze()
learn.lr_find()
learn.fit_one_cycle(5, slice(1e-6, 1e-1))
learn.lr_find()
learn.fit_one_cycle(100, slice(1e-6, 1e-2))
learn.export()
CUR_X_FILES, CUR_X = list(test_df.fname.values), X_test
test = ImageList.from_csv(WORK, Path('.. ')/CSV_SUBMISSION, folder='test')
 learn = load_learner(WORK, test=test)
 preds, _ = learn.get_preds(ds_type=DatasetType.Test)
 if predicts is None:
predicts = preds
else:
predicts += preds
i+=1
items=pd.read_csv("/kaggle/input/competitive-data-science-predict-future-sales/items.csv")
 shops=pd.read_csv("/kaggle/input/competitive-data-science-predict-future-sales/shops.csv")
 cats=pd.read_csv("/kaggle/input/competitive-data-science-predict-future-sales/item_categories.csv")
 train=pd.read_csv("/kaggle/input/competitive-data-science-predict-future-sales/sales_train.csv")
 test=pd.read_csv("/kaggle/input/competitive-data-science-predict-future-sales/test.csv" )<filter>
predicts = predicts/i
train = train[(train.item_price < 300000)&(train.item_cnt_day < 1000)]<feature_engineering>
test_df[learn.data.classes] = predicts
test_df.to_csv('submission.csv', index=False)
 test_df.head()