Kaggle competition: Sberbank Russian Housing Market
<load_from_zip>
import zipfile
<init_hyperparams>
train = zipfile.ZipFile('.. /input/sberbank-russian-housing-market/train.csv.zip', 'r')
 test = zipfile.ZipFile('.. /input/sberbank-russian-housing-market/test.csv.zip', 'r')
 macro = zipfile.ZipFile('.. /input/sberbank-russian-housing-market/macro.csv.zip', 'r' )
cfg_content = f<categorify>
train.extract('train.csv')
 test.extract('test.csv')
 macro.extract('macro.csv' )
<load_pretrained>
train = pd.read_csv('./train.csv')
 test = pd.read_csv('./test.csv')
 macro = pd.read_csv('./macro.csv' )
def predict_new_test(batch_size=1, prob_threhold=0.5):
image_names = os.listdir(test_image_folder)
 image_pred_results = collections.defaultdict(list)
 cfg = b"./yolov4-mish-416-wheat-v3-pseudo.cfg"
weights = b"./backup/yolov4-mish-416-wheat-v3-pseudo_best.weights"
resize = 618
print(f"Generating inference for model cfg file {cfg}...... ")
 net = dn.load_net_custom(cfg, weights, 0, batch_size)
 meta = dn.load_meta(meta_file)
 darknet_image = dn.make_image(resize, resize, 3)
 for name in image_names:
image_id = name.split('.')[0]
image = cv2.imread(f'{test_image_folder}/{image_id}.jpg')
 image = cv2.resize(image,(resize, resize))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
 infer_start = time.time()
for tta in tta_transforms:
tta_image = tta.augment(image)
 preds = detect(net, meta, darknet_image, tta_image)
 scores, preds = process_detection_result(
 preds, resize, prob_threhold)
 preds = tta.deaugment_boxes(preds)
 preds = preds.clip(min=0, max=image_width - 1)
 image_pred_results[name].append({
'boxes': preds,
'scores': scores,
})
 print(
 f"Time spent on augmented inference for {name}: {time.time() - infer_start:2f} seconds" 
)
 del image, preds
gc.collect()
dn.free_network_ptr(net)
 del net, meta
gc.collect()
return image_pred_results<predict_on_test>
train_mean_life_sq = train['life_sq'].mean()
train = train.fillna(value={'life_sq':train_mean_life_sq})
 train = train.fillna(value={'floor':3})
 train_mean_max_floor = train['max_floor'].mean()
train = train.fillna(value={'max_floor':train_mean_max_floor})
 train = train.fillna(value={'material':1})
 del train['timestamp'], train['id'], train['sub_area']
pred_start = time.time()
new_test_preds = predict_new_test(batch_size=1, prob_threhold=prob_threhold)
 print(
 f"Time spent on generating submission predictions: {time.time() - pred_start:2f} seconds"
)<train_model>
x_train = train.iloc[:, 0:5].copy()
y_train = train['price_doc'].copy()
pred_start = time.time()
new_ensemble_results = ensemble(new_test_preds,
iou_thr=iou_thr,
skip_box_thr=skip_box_thr)
 print(f"Time spent on ensemble: {time.time() - pred_start:2f} seconds" )<define_variables>
del test['id'], test['timestamp'], test['sub_area']
test_mean_life_sq = test['life_sq'].mean()
test = test.fillna(value={'life_sq':test_mean_life_sq} )
pred_start = time.time()
final_results = generate_submit(new_ensemble_results)
 final_results[:2]<save_to_csv>
x_test = test.iloc[:, 0:5].copy()
test_df = pd.DataFrame(final_results, columns=['image_id', 'PredictionString'])
 test_df.head()
test_df.to_csv('submission.csv', index=False )<install_modules>
model = BaggingRegressor(xgb.XGBRegressor(colsample_bytree=0.4,
learning_rate=0.03,
max_depth=6,
min_child_weight=1.5,
n_estimators=390,
reg_alpha=0.75,
reg_lambda=0.45,
subsample=0.6,
seed=42,
tree_method='gpu_hist', gpu_id=0 
), n_estimators=50 )
!rm -rf __pycache__ darknet* data libdarknet.so yolov4-* *.jpg<install_modules>
k = model.fit(x_train, y_train )
!pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext"./<install_modules>
preds = model.predict(x_test )
<define_variables><EOS> 
submission = pd.DataFrame({'id':test1['id'],'price_doc':preds})
 submission.to_csv('./submission.csv', index=False )