Kaggle competition: Bike Sharing Demand
def predict_on_video_set(videos, num_workers):
def process_file(i):
filename = videos[i]
y_pred = predict_on_video(os.path.join(test_dir, filename), batch_size=frames_per_video)
 return y_pred
with ThreadPoolExecutor(max_workers=num_workers)as ex:
predictions = ex.map(process_file, range(len(videos)))
 return list(predictions )<define_variables>
train = pd.read_csv(".. /input/train.csv", parse_dates = ["datetime"])
 test = pd.read_csv(".. /input/test.csv", parse_dates = ["datetime"])
 train["year"] = train["datetime"].dt.year
train["hour"] = train["datetime"].dt.hour
train["dayofweek"] = train["datetime"].dt.dayofweek
test["year"] = test["datetime"].dt.year
test["hour"] = test["datetime"].dt.hour
test["dayofweek"] = test["datetime"].dt.dayofweek
speed_test = False<predict_on_test>
train['temp'].value_counts().sort_index()
if speed_test:
start_time = time.time()
speedtest_videos = test_videos[:5]
predictions = predict_on_video_set(speedtest_videos, num_workers=4)
 elapsed = time.time() - start_time
print("Elapsed %f sec.Average per video: %f sec." %(elapsed, elapsed / len(speedtest_videos)) )<predict_on_test>
y_casual = np.log1p(train.casual)
 y_registered = np.log1p(train.registered)
 train.drop(["datetime", "windspeed", "casual", "registered", "count"], 1, inplace=True)
 test.drop(["datetime", "windspeed", ], 1, inplace=True )
%%time
model.eval()
predictions = predict_on_video_set(test_videos, num_workers=4 )<save_to_csv>
hyperparameters = { 'colsample_bytree': 0.725, 'learning_rate': 0.013,
'num_leaves': 56, 'reg_alpha': 0.754, 'reg_lambda': 0.071,
'subsample': 0.523, 'n_estimators': 1093}
model = lgb.LGBMRegressor(**hyperparameters)
 model.fit(train, y_casual)
 preds1 = model.predict(test)
 hyperparameters = { 'colsample_bytree': 0.639, 'learning_rate': 0.011,
'num_leaves': 30, 'reg_alpha': 0.351, 'reg_lambda': 0.587,
'subsample': 0.916, 'n_estimators': 2166}
model = lgb.LGBMRegressor(**hyperparameters,)
 model.fit(train, y_registered)
 preds2 = model.predict(test)
 submission=pd.read_csv(".. /input/sampleSubmission.csv")
 submission["count"] = np.expm1(preds1)+ np.expm1(preds2)
submission_df_xception = pd.DataFrame({"filename": test_videos, "label": predictions})
 submission_df_xception.to_csv("submission_xception.csv", index=False )<create_dataframe>
submission.iloc[1258:1269, 1]= submission.iloc[1258:1269, 1]*0.5
submission.iloc[4492:4515, 1]= submission.iloc[4492:4515, 1]*0.5
submission.iloc[6308:6330, 1]= submission.iloc[6308:6330, 1]*0.5
submission.iloc[3041:3063, 1]= submission.iloc[3041:3063, 1]*0.5
submission.iloc[6332:6354, 1]= submission.iloc[6332:6354, 1]*0.5
submission.iloc[3065:3087, 1]= submission.iloc[3065:3087, 1]*0.5
submission.iloc[5992:6015, 1]= submission.iloc[5992:6015, 1]*0.5
submission.iloc[2771:2794, 1]= submission.iloc[2771:2794, 1]*0.5
submission_df = pd.DataFrame({"filename": test_videos})
 submission_df["label"] = 0.5*submission_df_resnext["label"] + 0.5*submission_df_xception["label"]<save_to_csv>
submission.iloc[6332:6354]
<define_variables><EOS> 
submission.to_csv("lgb.csv", index=False )