Kaggle competition: Bike Sharing Demand
<SOS> metric: RMSLE Kaggle data source: bike-sharing-demand<choose_model_class>
train_df=pd.read_csv('/kaggle/input/bike-sharing-demand/train.csv')
 train_df.head(6 )
model = Model([left_input, right_input], output )<choose_model_class>
new_df=train_df.copy(deep=True)
 new_df['day']=new_df['datetime'].apply(lambda dateString : calendar.day_name[datetime.strptime(dateString,"%Y-%m-%d %H:%M:%S" ).weekday() ])
 new_df['datetime'] = pd.to_datetime(new_df['datetime'], format='%Y-%m-%d %H:%M:%S')
 new_df['month']=new_df['datetime'].apply(lambda x:x.month)
 new_df['hour']=new_df['datetime'].apply(lambda x:x.hour)
 new_df['year']=new_df['datetime'].apply(lambda x:x.year)
 final_df=new_df.copy(deep=True)
 final_df=new_df.drop(['datetime','temp','casual','registered'], axis=1)
 final_df.head()
optimizer = optimizers.RMSprop(lr=0.001, rho=0.9, epsilon=1e-06, decay=0.0 )<choose_model_class>
weather_df=pd.get_dummies(final_df['weather'],prefix='w',drop_first=True)
 yr_df=pd.get_dummies(final_df['year'],prefix='y',drop_first=True)
 month_df=pd.get_dummies(final_df['month'],prefix='m',drop_first=True)
 hour_df=pd.get_dummies(final_df['hour'],prefix='h',drop_first=True)
 season_df=pd.get_dummies(final_df['season'],prefix='s',drop_first=True)
 day_df=pd.get_dummies(final_df['day'],prefix='d',drop_first=True)
 final_df=final_df.drop(['weather','year','month','hour','season','day'], axis=1)
 final_df=final_df.join(weather_df)
 final_df=final_df.join(yr_df)
 final_df=final_df.join(month_df)
 final_df=final_df.join(hour_df)
 final_df=final_df.join(season_df)
 final_df=final_df.join(day_df )
model.compile(
 optimizer=optimizer,
loss="categorical_crossentropy",
metrics=["categorical_accuracy"]
)<split>
print(final_df.columns.to_series().groupby(final_df.dtypes ).groups)
 final_df.head(5 )
X_train, X_val, y_train, y_val = train_test_split(train, target, test_size=0.20, random_state=123456789 )<define_variables>
X=final_df.iloc[:,final_df.columns!='count'].values
Y=final_df.iloc[:,5].values
generator = image.ImageDataGenerator(
 featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=10,
zoom_range=0.1,
width_shift_range=0.1,
height_shift_range=0.1,
vertical_flip=False,
horizontal_flip=False )<train_model>
model = Ridge()
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
 grid = dict()
grid['alpha'] = arange(0, 1, 0.01)
 search = GridSearchCV(model, grid, scoring='neg_mean_squared_error', cv=cv, n_jobs=-1)
 results = search.fit(X, Y)
 print('MSE(NEGATIVE): %.3f' % results.best_score_)
 print('Config: %s' % results.best_params_ )
num_train_sequences = len(X_train)
 num_val_sequences = len(X_val)
 print("
print("<train_model>
model = Lasso()
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
 grid = dict()
grid['alpha'] = arange(0, 1, 0.01)
 search = GridSearchCV(model, grid, scoring='neg_mean_squared_error', cv=cv, n_jobs=-1)
 results = search.fit(X, Y)
 print('MSE(NEGATIVE): %.3f' % results.best_score_)
 print('Config: %s' % results.best_params_ )
if(num_train_sequences % BATCH_SIZE)== 0:
steps_per_epoch = int(num_train_sequences / BATCH_SIZE)
 else:
steps_per_epoch = int(num_train_sequences / BATCH_SIZE)+ 1
if(num_val_sequences % BATCH_SIZE)== 0:
validation_steps = int(num_val_sequences / BATCH_SIZE)
 else:
validation_steps = int(num_val_sequences / BATCH_SIZE)+ 1
print("
print("<choose_model_class>
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
 dtm = DecisionTreeRegressor(random_state=42)
 param_grid = {"criterion": ["mse", "mae"],
}
search = GridSearchCV(dtm,param_grid, scoring='neg_mean_squared_error', cv=cv)
 results = search.fit(X, Y)
 print('MSE(NEGATIVE): %.3f' % results.best_score_)
 print('Config: %s' % results.best_params_ )
LR = ReduceLROnPlateau(monitor="val_loss", factor=0.2, patience=2, min_lr=0.000001, verbose=1, cooldown=1 )<normalization>
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
 dtm = DecisionTreeRegressor(random_state=42)
 param_grid = {"criterion": ["mse", "mae"],
"max_depth": [2, 6, 8],
}
search = GridSearchCV(dtm,param_grid, scoring='neg_mean_squared_error', cv=cv)
 results = search.fit(X, Y)
 print('MSE(NEGATIVE): %.3f' % results.best_score_)
 print('Config: %s' % results.best_params_ )
def exponential_decay_fn(epoch):
return 0.01 * 0.1**(epoch / 20 )<normalization>
grid = dict()
grid['n_estimators'] = [1000]
grid['max_depth'] = [125,150,175]
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
 model = RandomForestRegressor()
search = GridSearchCV(model,param_grid=grid, scoring='neg_mean_squared_error', cv=cv)
 results = search.fit(X, Y)
 print('MSE(NEGATIVE): %.3f' % results.best_score_)
 print('Config: %s' % results.best_params_ )
def exponential_decay(lr, s):
def exponential_decay_fn(epoch):
return lr * 0.1**(epoch / s)
 return exponential_decay_fn
exponential_decay_fn = exponential_decay(lr=0.001, s=20 )<choose_model_class>
def grid_search() :
print('lets go')
 model = GradientBoostingRegressor()
grid = dict()
grid['n_estimators'] = [4000]
grid['learning_rate'] = [ 0.001, 0.01, 0.1]
grid['max_depth'] = [4]
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
 grid_search = GridSearchCV(estimator=model, param_grid=grid, n_jobs=-1, cv=cv, scoring='neg_mean_squared_error')
 grid_search=grid_search.fit(X,Y)
 best_accuracy=grid_search.best_score_
best_parameters=grid_search.best_params_
print(best_accuracy)
 print(best_parameters)
 grid_search()
lr_scheduler = keras.callbacks.LearningRateScheduler(exponential_decay_fn )<define_variables>
rgr=GradientBoostingRegressor(learning_rate=0.1,n_estimators=4000, max_depth=4)
 rgr.fit(X,Y )
callbacks = [
checkpoint,
LR,
lr_scheduler]<train_model>
test_df=pd.read_csv('/kaggle/input/bike-sharing-demand/test.csv')
 test_df['day']=test_df['datetime'].apply(lambda dateString : calendar.day_name[datetime.strptime(dateString,"%Y-%m-%d %H:%M:%S" ).weekday() ])
 test_df['datetime']=pd.to_datetime(test_df['datetime'], format='%Y-%m-%d %H:%M:%S')
 test_df['month']=test_df['datetime'].apply(lambda x:x.month)
 test_df['hour']=test_df['datetime'].apply(lambda x:x.hour)
 test_df['year']=test_df['datetime'].apply(lambda x:x.year)
 test_df=test_df.drop(['datetime','temp'], axis=1)
 weather_df=pd.get_dummies(test_df['weather'],prefix='w',drop_first=True)
 yr_df=pd.get_dummies(test_df['year'],prefix='y',drop_first=True)
 month_df=pd.get_dummies(test_df['month'],prefix='m',drop_first=True)
 hour_df=pd.get_dummies(test_df['hour'],prefix='h',drop_first=True)
 season_df=pd.get_dummies(test_df['season'],prefix='s',drop_first=True)
 day_df=pd.get_dummies(test_df['day'],prefix='d',drop_first=True)
 test_df=test_df.drop(['weather','year','month','hour','season','day'], axis=1)
 test_df=test_df.join(weather_df)
 test_df=test_df.join(yr_df)
 test_df=test_df.join(month_df)
 test_df=test_df.join(hour_df)
 test_df=test_df.join(season_df)
 test_df=test_df.join(day_df )
VERBOSE = 1
history = model.fit_generator(generator.flow([X_train, X_train], y_train, batch_size=BATCH_SIZE),
validation_data=generator.flow([X_val, X_val], y_val, batch_size=BATCH_SIZE),
epochs=NP_EPOCHS,
verbose=VERBOSE,
steps_per_epoch=steps_per_epoch,
validation_steps=validation_steps,
class_weight=None,
initial_epoch=0,
callbacks=callbacks )<find_best_params>
temp=pd.read_csv('.. /input/bike-sharing-demand/sampleSubmission.csv')
 X_test=test_df.iloc[:,:].values
y_output=rgr.predict(X_test)
 y_output
op=pd.DataFrame({'count':np.exp(y_output)})
 op['datetime']=temp['datetime']
op.to_csv('finalSubmission.csv', index=False )