Kaggle competition: Bike Sharing Demand
predictions = []
for pred in preds:
result = max(pred)
 if result > 0.5:
result = 1
else:
result = 0
predictions.append(result )<save_to_csv>
train=data=pd.read_csv('/kaggle/input/bike-sharing-demand/train.csv')
 test=pd.read_csv('/kaggle/input/bike-sharing-demand/test.csv')
 train.info()
Y1train=train['casual']
Y2train=train['registered']
Ytrain=train['count']
output = pd.DataFrame({'PassengerId': test_df.PassengerId, 'Survived': predictions})
 output.to_csv('my_submission.csv', index=False )<load_from_csv>
feature_names=list(test)
 train=train[feature_names]
all_data=pd.concat(( train, test))
print(train.shape, test.shape, all_data.shape)
 print(Ytrain)
 all_data['datetime']=pd.to_datetime(all_data['datetime'])
 all_data['year']=all_data['datetime'].dt.year
all_data['month']=all_data['datetime'].dt.month
all_data['day']=all_data['datetime'].dt.day
all_data['hour']=all_data['datetime'].dt.hour
all_data['dayofweek']=all_data['datetime'].dt.dayofweek
all_data=all_data.drop(columns='datetime')
 all_data.loc[all_data['windspeed']==0, 'windspeed']=all_data['windspeed'].mean()
print(train.shape, test.shape, all_data.shape )
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
 train_data.head()<load_from_csv>
Xtrain=all_data[:len(train)]
Xtest=all_data[len(train):]
Xtrain.info()
tmpXtrain = copy.deepcopy(Xtrain)
 tmpXtest = copy.deepcopy(Xtest)
 for cmb in itertools.combinations_with_replacement(list(Xtrain.keys()), 2):
tmpXtrain["-".join(cmb)] = Xtrain[cmb[0]] * Xtrain[cmb[1]]
tmpXtest["-".join(cmb)] = Xtest[cmb[0]] * Xtest[cmb[1]]
test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 test_data.head()<groupby>
!pip install optuna
train_data.groupby('Sex' ).Survived.mean()<groupby>
X_train, X_test, y_train, y_test = train_test_split(tmpXtrain, np.log1p(Y1train), test_size=0.1)
 lgb_train = lgb.Dataset(X_train, y_train)
 lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
 lgbm_params = {
'objective': 'regression',
'metric': 'rmse',
}
best_params, tuning_history = dict() , list()
booster_casual = lgb.train(lgbm_params, lgb_train, valid_sets=lgb_eval,
verbose_eval=0,
best_params=best_params,
tuning_history=tuning_history)
 print("Best Params:", best_params)
 print("Tuning history:", tuning_history)
train_data.groupby('Pclass' ).Survived.mean()<feature_engineering>
X_train, X_test, y_train, y_test = train_test_split(tmpXtrain, np.log1p(Y2train), test_size=0.1)
 lgb_train = lgb.Dataset(X_train, y_train)
 lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
 lgbm_params = {
'objective': 'regression',
'metric': 'rmse',
}
best_params, tuning_history = dict() , list()
booster_registered = lgb.train(lgbm_params, lgb_train, valid_sets=lgb_eval,
verbose_eval=0,
best_params=best_params,
tuning_history=tuning_history)
 print("Best Params:", best_params)
 print("Tuning history:", tuning_history )
<categorify><EOS> 
pred_casual = booster_casual.predict(tmpXtest, num_iteration=booster_casual.best_iteration)
 pred_casual = np.expm1(pred_casual)
 pred_registered = booster_registered.predict(tmpXtest, num_iteration=booster_registered.best_iteration)
 pred_registered = np.expm1(pred_registered)
 pred = pred_casual + pred_registered
pred[pred<0] = 0
submission = pd.DataFrame({'datetime': test.datetime, 'count': pred},
columns=['datetime', 'count'])
 submission.to_csv("submission.csv", index=False )