Kaggle competition: Bike Sharing Demand
test_df = pd.DataFrame(results, columns=['image_id', 'PredictionString'])
 test_df.to_csv('submission.csv', index=False)
 test_df.head()<install_modules>
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
!pip install --no-deps '.. /input/timm-package/timm-0.1.26-py3-none-any.whl' > /dev/null
!pip install --no-deps '.. /input/pycocotools/pycocotools-2.0-cp37-cp37m-linux_x86_64.whl' > /dev/null<define_variables>
train = pd.read_csv('/kaggle/input/bike-sharing-demand/train.csv', parse_dates=['datetime'])
 test = pd.read_csv('/kaggle/input/bike-sharing-demand/test.csv', parse_dates=['datetime'])
 sub = pd.read_csv('/kaggle/input/bike-sharing-demand/sampleSubmission.csv' )
USE_OPTIMIZE = len(glob(f'.. /input/global-wheat-detection/test/*.jpg')) == 10
USE_OPTIMIZE<load_from_csv>
new_tr = train.copy()
new_test = test.copy()
marking = pd.read_csv('.. /input/global-wheat-detection/train.csv')
 bboxs = np.stack(marking['bbox'].apply(lambda x: np.fromstring(x[1:-1], sep=',')))
 for i, column in enumerate(['x', 'y', 'w', 'h']):
marking[column] = bboxs[:,i]
marking.drop(columns=['bbox'], inplace=True )<feature_engineering>
new_tr['year'] = new_tr['datetime'].dt.year
new_tr['month'] = new_tr['datetime'].dt.month
new_tr['day'] = new_tr['datetime'].dt.day
new_tr['hour'] = new_tr['datetime'].dt.hour
new_tr['minute'] = new_tr['datetime'].dt.minute
new_tr['second'] = new_tr['datetime'].dt.second
new_tr['dayofweek'] = new_tr['datetime'].dt.dayofweek
%%time
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
 df_folds = marking[['image_id']]
df_folds['bbox_count'] = 1
df_folds = df_folds.groupby('image_id' ).count()
df_folds['source'] = marking[['image_id', 'source']].groupby('image_id' ).min() ['source']
df_folds['stratify_group'] = np.char.add(
 df_folds['source'].values.astype(str),
df_folds['bbox_count'].apply(lambda x: f'_{x // 15}' ).values.astype(str)
)
 train_index, holdout_index = next(skf.split(X=df_folds.index, y=df_folds['stratify_group']))
df_holdout = df_folds.iloc[holdout_index].copy()
df_folds = df_folds.iloc[train_index].copy()
df_folds['fold'] = 0
for fold_number,(train_index, val_index)in enumerate(skf.split(X=df_folds.index, y=df_folds['stratify_group'])) :
df_folds.loc[df_folds.iloc[val_index].index, 'fold'] = fold_number<load_pretrained>
new_test['year'] = new_test['datetime'].dt.year
new_test['month'] = new_test['datetime'].dt.month
new_test['day'] = new_test['datetime'].dt.day
new_test['hour'] = new_test['datetime'].dt.hour
new_test['minute'] = new_test['datetime'].dt.minute
new_test['second'] = new_test['datetime'].dt.second
new_test['dayofweek'] = new_test['datetime'].dt.dayofweek
holdout_dataset = DatasetRetriever(
 image_ids=df_holdout.index.values,
marking=marking,
transforms=get_valid_transforms() ,
test=True, 
)
 holdout_loader = DataLoader(
 holdout_dataset,
batch_size=4,
shuffle=False,
num_workers=2,
drop_last=False,
collate_fn=collate_fn
)<load_pretrained>
feature_names = [ 'season', 'holiday', 'workingday', 'weather',
'temp', 'atemp', 'humidity', 'windspeed',
"year", "hour", "dayofweek"]
def load_net(checkpoint_path):
config = get_efficientdet_config('tf_efficientdet_d5')
 net = EfficientDet(config, pretrained_backbone=False)
 config.num_classes = 1
config.image_size = 512
net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01))
checkpoint = torch.load(checkpoint_path)
 net.load_state_dict(checkpoint)
 del checkpoint
gc.collect()
net = DetBenchEval(net, config)
 net.eval() ;
return net.cuda()
if USE_OPTIMIZE:
models = [
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
]<categorify>
from lightgbm import LGBMRegressor
from sklearn.model_selection import train_test_split
def process_det(index, det, score_threshold=0.25):
boxes = det[index].detach().cpu().numpy() [:,:4]
scores = det[index].detach().cpu().numpy() [:,4]
boxes[:, 2] = boxes[:, 2] + boxes[:, 0]
boxes[:, 3] = boxes[:, 3] + boxes[:, 1]
boxes =(boxes*2 ).clip(min=0, max=1023 ).astype(int)
 indexes = np.where(scores>score_threshold)
 boxes = boxes[indexes]
scores = scores[indexes]
return boxes, scores
if USE_OPTIMIZE:
all_predictions = []
for images, targets, image_ids in tqdm(holdout_loader, total=len(holdout_loader)) :
with torch.no_grad() :
images = torch.stack(images)
 images = images.cuda().float()
fold_predictions = {}
for fold_number in range(5):
fold_predictions[fold_number] = models[fold_number](images, torch.tensor([1]*images.shape[0] ).float().cuda())
 for i in range(images.shape[0]):
image_predictions = {
'image_id': image_ids[i],
'gt_boxes':(targets[i]['boxes'].cpu().numpy() *2 ).clip(min=0, max=1023 ).astype(int),
}
for fold_number in range(5):
boxes, scores = process_det(i, fold_predictions[fold_number])
 image_predictions[f'pred_boxes_fold{fold_number}'] = boxes
image_predictions[f'scores_fold{fold_number}'] = scores
all_predictions.append(image_predictions )<normalization>
new_tr['log_count'] = np.log1p(new_tr['count'] )
@jit(nopython=True)
 def calculate_iou(gt, pr, form='pascal_voc')-> float:

 if form == 'coco':
gt = gt.copy()
pr = pr.copy()
gt[2] = gt[0] + gt[2]
gt[3] = gt[1] + gt[3]
pr[2] = pr[0] + pr[2]
pr[3] = pr[1] + pr[3]
dx = min(gt[2], pr[2])- max(gt[0], pr[0])+ 1
if dx < 0:
return 0.0
dy = min(gt[3], pr[3])- max(gt[1], pr[1])+ 1
if dy < 0:
return 0.0
overlap_area = dx * dy
union_area =(
(gt[2] - gt[0] + 1)*(gt[3] - gt[1] + 1)+ 
(pr[2] - pr[0] + 1)*(pr[3] - pr[1] + 1)-
overlap_area 
)
 return overlap_area / union_area
@jit(nopython=True)
 def find_best_match(gts, pred, pred_idx, threshold = 0.5, form = 'pascal_voc', ious=None)-> int:

 best_match_iou = -np.inf
best_match_idx = -1
for gt_idx in range(len(gts)) :
if gts[gt_idx][0] < 0:
continue
iou = -1 if ious is None else ious[gt_idx][pred_idx]
if iou < 0:
iou = calculate_iou(gts[gt_idx], pred, form=form)
 if ious is not None:
ious[gt_idx][pred_idx] = iou
if iou < threshold:
continue
if iou > best_match_iou:
best_match_iou = iou
best_match_idx = gt_idx
return best_match_idx
@jit(nopython=True)
 def calculate_precision(gts, preds, threshold = 0.5, form = 'coco', ious=None)-> float:

 n = len(preds)
 tp = 0
fp = 0
for pred_idx in range(n):
best_match_gt_idx = find_best_match(gts, preds[pred_idx], pred_idx,
threshold=threshold, form=form, ious=ious)
 if best_match_gt_idx >= 0:
tp += 1
gts[best_match_gt_idx] = -1
else:
fp += 1
fn =(gts.sum(axis=1)> 0 ).sum()
return tp /(tp + fp + fn)
 @jit(nopython=True)
 def calculate_image_precision(gts, preds, thresholds =(0.5,), form = 'coco')-> float:

 n_threshold = len(thresholds)
 image_precision = 0.0
ious = np.ones(( len(gts), len(preds)))* -1
for threshold in thresholds:
precision_at_threshold = calculate_precision(gts.copy() , preds, threshold=threshold,
form=form, ious=ious)
 image_precision += precision_at_threshold / n_threshold
return image_precision
def show_result(sample_id, preds, gt_boxes):
sample = cv2.imread(f'{TRAIN_ROOT_PATH}/{sample_id}.jpg', cv2.IMREAD_COLOR)
 sample = cv2.cvtColor(sample, cv2.COLOR_BGR2RGB)
 fig, ax = plt.subplots(1, 1, figsize=(16, 8))
for pred_box in preds:
cv2.rectangle(
 sample, 
(pred_box[0], pred_box[1]), 
(pred_box[2], pred_box[3]), 
(220, 0, 0), 2 
)
 for gt_box in gt_boxes:
cv2.rectangle(
 sample, 
(gt_box[0], gt_box[1]), 
(gt_box[2], gt_box[3]), 
(0, 0, 220), 2 
)
 ax.set_axis_off()
ax.imshow(sample)
 ax.set_title("RED: Predicted | BLUE - Ground-truth")
 iou_thresholds = numba.typed.List()
for x in [0.5, 0.55, 0.6, 0.65, 0.7, 0.75]:
iou_thresholds.append(x )<define_variables>
X = new_tr[feature_names]
y = new_tr['log_count']
X_test_last = new_test[feature_names]
X_train, X_test, y_train, y_test = train_test_split(X, y )
def calculate_final_score(
 all_predictions,
iou_thr,
skip_box_thr,
method,
sigma=0.5, 
):
final_scores = []
for i in range(len(all_predictions)) :
gt_boxes = all_predictions[i]['gt_boxes'].copy()
image_id = all_predictions[i]['image_id']
folds_boxes, folds_scores, folds_labels = [], [], []
for fold_number in range(5):
pred_boxes = all_predictions[i][f'pred_boxes_fold{fold_number}'].copy()
scores = all_predictions[i][f'scores_fold{fold_number}'].copy()
folds_boxes.append(pred_boxes)
 folds_scores.append(scores)
 folds_labels.append(np.ones(pred_boxes.shape[0]))
if method == 'weighted_boxes_fusion':
boxes, scores, labels = weighted_boxes_fusion(folds_boxes, folds_scores, folds_labels, weights=None, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
 elif method == 'nms':
boxes, scores, labels = nms(folds_boxes, folds_scores, folds_labels, weights=None, iou_thr=iou_thr)
 elif method == 'soft_nms':
boxes, scores, labels = soft_nms(folds_boxes, folds_scores, folds_labels, weights=None, iou_thr=iou_thr, thresh=skip_box_thr, sigma=sigma)
 elif method == 'non_maximum_weighted':
boxes, scores, labels = non_maximum_weighted(folds_boxes, folds_scores, folds_labels, weights=None, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
 else:
raise
image_precision = calculate_image_precision(gt_boxes, boxes, thresholds=iou_thresholds, form='pascal_voc')
 final_scores.append(image_precision)
 return np.mean(final_scores )<compute_train_metric>
model_lgbm = LGBMRegressor()
%%time
if USE_OPTIMIZE:
print('[WBF]: ', calculate_final_score(
 all_predictions,
iou_thr=0.55,
skip_box_thr=0.0001,
method='weighted_boxes_fusion', 
))
print('[NMS]: ', calculate_final_score(
 all_predictions,
iou_thr=0.55,
skip_box_thr=0.0001,
method='nms', 
))
print('[SOFT NMS]: ', calculate_final_score(
 all_predictions,
iou_thr=0.55,
skip_box_thr=0.0001,
sigma=0.1,
method='soft_nms', 
))
print('[NMW]: ', calculate_final_score(
 all_predictions,
iou_thr=0.55,
skip_box_thr=0.0001,
method='non_maximum_weighted', 
))<find_best_params>
model_lgbm.fit(X_train, y_train )
def log(text):
with open('opt.log', 'a+')as logger:
logger.write(f'{text}
')
 def optimize(space, all_predictions, method, n_calls=10):
@use_named_args(space)
 def score(**params):
log('-'*5 + f'{method}' + '-'*5)
 log(params)
 final_score = calculate_final_score(all_predictions, method=method, **params)
 log(f'final_score = {final_score}')
 log('-'*10)
 return -final_score
return gp_minimize(func=score, dimensions=space, n_calls=n_calls )<normalization>
model_lgbm.score(X_test, y_test )
%%time
space = [
Real(0, 1, name='iou_thr'),
Real(0.0, 1, name='skip_box_thr'),
]
if USE_OPTIMIZE:
opt_result = optimize(
 space,
all_predictions,
method='nms',
n_calls=50,
)<find_best_params>
model_random = RandomForestRegressor()
if USE_OPTIMIZE:
best_final_score = -opt_result.fun
best_iou_thr = opt_result.x[0]
best_skip_box_thr = opt_result.x[1]
print('-'*13 + 'NMS' + '-'*14)
 print(f'[Best Iou Thr]: {best_iou_thr:.3f}')
 print(f'[Best Skip Box Thr]: {best_skip_box_thr:.3f}')
 print(f'[Best Score]: {best_final_score:.4f}')
 print('-'*30 )<find_best_params>
model_random.fit(X_train, y_train )
%%time
space = [
Real(0, 1, name='iou_thr'),
Real(0.0, 1, name='skip_box_thr'),
Real(0.0, 1, name='sigma'),
]
if USE_OPTIMIZE:
opt_result = optimize(
 space,
all_predictions,
method='soft_nms',
n_calls=50,
)<find_best_params>
model_random.score(X_test, y_test )
if USE_OPTIMIZE:
best_final_score = -opt_result.fun
best_iou_thr = opt_result.x[0]
best_skip_box_thr = opt_result.x[1]
best_sigma = opt_result.x[2]
print('-'*11 + 'SOFT NMS' + '-'*11)
 print(f'[Best Iou Thr]: {best_iou_thr:.3f}')
 print(f'[Best Skip Box Thr]: {best_skip_box_thr:.3f}')
 print(f'[Best Sigma]: {best_sigma:.3f}')
 print(f'[Best Score]: {best_final_score:.4f}')
 print('-'*30 )<define_search_space>
scores = cross_val_score(model_random, X_test, y_test)
 print("{} 교차 검증 점수 : {}".format(model_random,scores))
%%time
space = [
Real(0, 1, name='iou_thr'),
Real(0.0, 1, name='skip_box_thr'),
]
if USE_OPTIMIZE:
opt_result = optimize(
 space,
all_predictions,
method='non_maximum_weighted',
n_calls=50,
)<find_best_params>
from sklearn.model_selection import LeaveOneOut, cross_val_score, KFold
if USE_OPTIMIZE:
best_final_score = -opt_result.fun
best_iou_thr = opt_result.x[0]
best_skip_box_thr = opt_result.x[1]
print('-'*13 + 'NMW' + '-'*14)
 print(f'[Best Iou Thr]: {best_iou_thr:.3f}')
 print(f'[Best Skip Box Thr]: {best_skip_box_thr:.3f}')
 print(f'[Best Score]: {best_final_score:.4f}')
 print('-'*30 )<find_best_params>
loo = LeaveOneOut()
%%time
space = [
Real(0, 1, name='iou_thr'),
Real(0.25, 1, name='skip_box_thr'),
]
if USE_OPTIMIZE:
opt_result = optimize(
 space,
all_predictions,
method='weighted_boxes_fusion',
n_calls=50,
)<find_best_params>
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestRegressor
import xgboost as xgb
import lightgbm as lgb
import time
if USE_OPTIMIZE:
best_final_score = -opt_result.fun
best_iou_thr = opt_result.x[0]
best_skip_box_thr = opt_result.x[1]
else:
best_final_score = 0.6953
best_iou_thr = 0.44
best_skip_box_thr = 0.43
print('-'*13 + 'WBF' + '-'*14)
 print(f'[Best Iou Thr]: {best_iou_thr:.3f}')
 print(f'[Best Skip Box Thr]: {best_skip_box_thr:.3f}')
 print(f'[Best Score]: {best_final_score:.4f}')
 print('-'*30 )<load_pretrained>
def model_val(model_name, model_obj):
now_time = time.time()
model_obj.fit(X_train, y_train)
 scores = cross_val_score(model_obj, X_test, y_test, cv=5,
scoring='neg_mean_squared_error')
 avg_score = np.abs(scores.mean())
 print("MSE 평균 : ", avg_score)
 pro_time = time.time() - now_time
print("수행 시간 : {0:.3f}".format(pro_time))
print("{} Score : {}".format(model_name, avg_score))
return avg_score, pro_time
models = [
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
load_net('.. /input/wheat-effdet5-fold0-best-checkpoint/fold0-best.bin'),
]<data_type_conversions>
model_list = ["RandomForestRegressor", "xgb_basic",
"lightgbm-model1", "lightgbm-model2"]
exe_model = []
model_score = []
model_time = []
DATA_ROOT_PATH = '.. /input/global-wheat-detection/test'
class TestDatasetRetriever(Dataset):
def __init__(self, image_ids, transforms=None):
super().__init__()
self.image_ids = image_ids
self.transforms = transforms
def __getitem__(self, index: int):
image_id = self.image_ids[index]
image = cv2.imread(f'{DATA_ROOT_PATH}/{image_id}.jpg', cv2.IMREAD_COLOR)
 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB ).astype(np.float32)
 image /= 255.0
if self.transforms:
sample = {'image': image}
sample = self.transforms(**sample)
 image = sample['image']
return image, image_id
def __len__(self)-> int:
return self.image_ids.shape[0]
def get_valid_transforms() :
return A.Compose(
 [
A.Resize(height=512, width=512, p=1.0),
ToTensorV2(p=1.0),
],
p=1.0, 
)
 dataset = TestDatasetRetriever(
 image_ids=np.array([path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]),
transforms=get_valid_transforms() 
)
 def collate_fn(batch):
return tuple(zip(*batch))
data_loader = DataLoader(
 dataset,
batch_size=2,
shuffle=False,
num_workers=4,
drop_last=False,
collate_fn=collate_fn 
)
 def make_predictions(
 images,
score_threshold=0.25, 
):
images = torch.stack(images ).cuda().float()
predictions = []
for fold_number, net in enumerate(models):
with torch.no_grad() :
det = net(images, torch.tensor([1]*images.shape[0] ).float().cuda())
 result = []
for i in range(images.shape[0]):
boxes = det[i].detach().cpu().numpy() [:,:4]
scores = det[i].detach().cpu().numpy() [:,4]
indexes = np.where(scores > score_threshold)[0]
boxes = boxes[indexes]
boxes[:, 2] = boxes[:, 2] + boxes[:, 0]
boxes[:, 3] = boxes[:, 3] + boxes[:, 1]
result.append({
'boxes': boxes[indexes],
'scores': scores[indexes],
})
 predictions.append(result)
 return predictions
def run_wbf(predictions, image_index, image_size=512, iou_thr=best_iou_thr, skip_box_thr=best_skip_box_thr, weights=None):
boxes = [(prediction[image_index]['boxes']/(image_size-1)).tolist() for prediction in predictions]
scores = [prediction[image_index]['scores'].tolist() for prediction in predictions]
labels = [np.ones(prediction[image_index]['scores'].shape[0] ).tolist() for prediction in predictions]
boxes, scores, labels = weighted_boxes_fusion(boxes, scores, labels, weights=None, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
 boxes = boxes*(image_size-1)
 return boxes, scores, labels
def format_prediction_string(boxes, scores):
pred_strings = []
for j in zip(scores, boxes):
pred_strings.append("{0:.4f} {1} {2} {3} {4}".format(j[0], j[1][0], j[1][1], j[1][2], j[1][3]))
return " ".join(pred_strings)
 results = []
for images, image_ids in data_loader:
predictions = make_predictions(images)
 for i, image in enumerate(images):
boxes, scores, labels = run_wbf(predictions, image_index=i)
 boxes =(boxes*2 ).astype(np.int32 ).clip(min=0, max=1023)
 image_id = image_ids[i]
boxes[:, 2] = boxes[:, 2] - boxes[:, 0]
boxes[:, 3] = boxes[:, 3] - boxes[:, 1]
result = {
'image_id': image_id,
'PredictionString': format_prediction_string(boxes, scores)
 }
results.append(result)
 test_df = pd.DataFrame(results, columns=['image_id', 'PredictionString'])
 test_df.to_csv('submission.csv', index=False )<set_options>
m_name = model_list[0]
if m_name not in exe_model:
model = RandomForestRegressor(random_state=30)
 mse_score, p_time = model_val(m_name, model)
 exe_model.append(m_name)
 model_score.append(mse_score)
 model_time.append(p_time)
 else:
print(f"{m_name} 이미 실행 완료" )
logging.basicConfig(format='[%(asctime)s %(levelname)8s] %(message)s', level=logging.INFO, datefmt='%m-%d %H:%M:%S')
<categorify>
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import AdaBoostRegressor
def transfrom(text_train, text_test):
large_use = 'https://tfhub.dev/google/universal-sentence-encoder-large/5'
embed = hub.load(large_use)
 vector_train = [tf.reshape(embed([line]), [-1] ).numpy() for line in tqdm(text_train)]
vector_test = [tf.reshape(embed([line]), [-1] ).numpy() for line in tqdm(text_test)]
return vector_train, vector_test 
<load_from_csv>
xg_reg = xgb.XGBRegressor(objective ='reg:linear',
colsample_bytree = 0.3,
learning_rate = 0.1,
max_depth = 3,
alpha = 0.1,
n_estimators = 1000)
 mse_score, p_time = model_val('xgb_basic', xg_reg)
 exe_model.append('xgb_basic')
 model_score.append(mse_score)
 model_time.append(p_time )
train = pd.read_csv('.. /input/nlp-getting-started/train.csv')
 test = pd.read_csv('.. /input/nlp-getting-started/test.csv')
 vector_train, vector_test = transfrom(train.text, test.text)
<train_model>
m_lgbm1 = lgb.LGBMRegressor()
mse_score, p_time = model_val('lightgbm-model1', m_lgbm1)
 exe_model.append('lightgbm-model1')
 model_score.append(mse_score)
 model_time.append(p_time )
model = svm.SVC()
X_train, X_val, y_train, y_val = train_test_split(vector_train, train.target, test_size=0.2, random_state=2020)
 model.fit(X_train, y_train)
 preds = model.predict(X_val)
 print('Accuracy score', accuracy_score(y_val, preds))
print('f1_score', f1_score(y_val, preds)) 
<save_to_csv>
hyperparameters = {'boosting_type': 'gbdt',
'colsample_bytree': 0.7250136792694301,
'is_unbalance': False,
'learning_rate': 0.013227664889528229,
'min_child_samples': 20,
'num_leaves': 56,
'reg_alpha': 0.7543896477745794,
'reg_lambda': 0.07152751159655985,
'subsample_for_bin': 240000,
'subsample': 0.5233384321711397,
'n_estimators': 2000}
m_lgbm2 = lgb.LGBMRegressor(**hyperparameters)
 mse_score, p_time = model_val('lightgbm-model2', m_lgbm2)
 exe_model.append('lightgbm-model2')
 model_score.append(mse_score)
 model_time.append(p_time )
final_preds = model.predict(vector_test)
 sub = pd.read_csv(f".. /input/nlp-getting-started/sample_submission.csv")
 sub['target'] = final_preds
sub.to_csv('submission.csv', index=False)
<import_modules>
print(exe_model)
 print(model_score)
 print(model_time )
import torch
import pandas as pd
import random
import time
import datetime
from sklearn.model_selection import train_test_split, StratifiedKFold, KFold
from sklearn.metrics import f1_score
import numpy as np
from torch.utils.data import TensorDataset,Subset
from transformers import BertTokenizer
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
from torch.nn import functional as F<set_options>
exe_model = ['rf', 'xgb', 'lgb_1', 'lgb_2']
<load_pretrained><EOS> 
hyperparameters = {'boosting_type': 'gbdt',
'colsample_bytree': 0.7250136792694301,
'is_unbalance': False,
'learning_rate': 0.013227664889528229,
'min_child_samples': 20,
'num_leaves': 56,
'reg_alpha': 0.7543896477745794,
'reg_lambda': 0.07152751159655985,
'subsample_for_bin': 240000,
'subsample': 0.5233384321711397,
'n_estimators': 2000}
m_lgbm2 = lgb.LGBMRegressor(**hyperparameters)
 m_lgbm2.fit(X_train, y_train)
 pred = m_lgbm2.predict(X_test_last)
 sub['count'] = np.expm1(pred)
 sub.to_csv("submission.csv", index=False )