Kaggle competition: Bike Sharing Demand
model = Sequential()
model.add(Conv2D(32,kernel_size=3,activation='relu',input_shape=(28,28,1)))
 model.add(BatchNormalization())
 model.add(Conv2D(32,kernel_size=3,activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(32,kernel_size=5,strides=2,padding='same',activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.4))
model.add(Conv2D(64,kernel_size=3,activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(64,kernel_size=3,activation='relu'))
model.add(BatchNormalization())
 model.add(Conv2D(64,kernel_size=5,strides=2,padding='same',activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.4))
model.add(Flatten())
 model.add(Dense(128, activation='relu'))
model.add(BatchNormalization())
 model.add(Dropout(0.4))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer=Adam(lr=0.001), loss="categorical_crossentropy", metrics=["accuracy"] )<train_model>
pd.options.mode.chained_assignment = None
warnings.filterwarnings("ignore", category = DeprecationWarning)
 %matplotlib inline
history = model.fit_generator(datagen.flow(X_train,Y_train, batch_size=BATCH_SIZE),
epochs = EPOCHS,
validation_data =(X_test,Y_test),
verbose = 1,
steps_per_epoch=X_train.shape[0] // BATCH_SIZE,
callbacks=callbacks )<predict_on_test>
dataTrain = pd.read_csv(".. /input/bike-sharing-demand/train.csv")
 dataTest = pd.read_csv(".. /input/bike-sharing-demand/test.csv" )
%%time
pred = model.predict(X_test)
 pred = np.argmax(pred,axis=1)
 target = np.argmax(Y_test,axis=1 )<compute_test_metric>
data = dataTrain.append(dataTest)
 data.reset_index(inplace = True)
 data.drop('index', inplace = True, axis = 1 )
cm = confusion_matrix(target, pred)
 print(cm )<compute_test_metric>
data["date"] = data.datetime.apply(lambda x : x.split() [0])
 data["hour"] = data.datetime.apply(lambda x : x.split() [1].split(":")[0] ).astype("int")
 data["year"] = data.datetime.apply(lambda x : x.split() [0].split("-")[0])
 data["weekday"] = data.date.apply(lambda dateString : datetime.strptime(dateString,"%Y-%m-%d" ).weekday())
 data["month"] = data.date.apply(lambda dateString : datetime.strptime(dateString,"%Y-%m-%d" ).month)
 dataWindspeedOriginal = data["windspeed"]
accuracy_score(target, pred )<compute_test_metric>
wCol= ["season","weather","humidity","month","temp","year","atemp"]
dataWind0 = data[data["windspeed"] == 0]
dataWindNot0 = data[data["windspeed"] != 0]
dataWindNot0["windspeed"] = dataWindNot0["windspeed"].astype("str")
 rfModel_wind = RandomForestClassifier()
rfModel_wind.fit(dataWindNot0[wCol], dataWindNot0["windspeed"])
 Wind0Values = rfModel_wind.predict(X = dataWind0[wCol])
 dataWind0["windspeed"] = Wind0Values
data = dataWindNot0.append(dataWind0)
 data["windspeed"] = data["windspeed"].astype("float")
 data.reset_index(inplace=True)
 data.drop('index',inplace=True,axis=1)
print(classification_report(target, pred))<predict_on_test>
categoricalFeatureNames = ["season","holiday","workingday","weather","weekday","month","year","hour"]
numericalFeatureNames = ["temp","humidity","windspeed","atemp"]
dropFeatures = ['casual',"count","datetime","date","registered"]
submission_pred = model.predict(x_test )<prepare_output>
for var in categoricalFeatureNames:
data[var] = data[var].astype("category" )
submission_pred = np.argmax(submission_pred, axis=1 )<create_dataframe>
dataTrain = data[pd.notnull(data['count'])].sort_values(by=["datetime"])
 dataTest = data[~pd.notnull(data['count'])].sort_values(by = ["datetime"])
 datetimecol = dataTest["datetime"]
yLabels = dataTrain["count"]
yLabelsRegistered = dataTrain["registered"]
yLabelsCasual = dataTrain["casual"]
df_submission = pd.DataFrame({'id': np.arange(0,submission_pred.shape[0]),
'label':submission_pred} )<save_to_csv>
X_train, X_validate, y_train, y_validate = train_test_split(dataTrain, yLabels, test_size=0.3, random_state=42)
 dateTimeColValidate = X_validate["datetime"]
df_submission.to_csv('submission.csv',index=False )<set_options>
dataTrain = dataTrain.drop(dropFeatures,axis=1)
 dataTest = dataTest.drop(dropFeatures,axis=1)
 X_train = X_train.drop(dropFeatures,axis=1)
 X_validate = X_validate.drop(dropFeatures,axis=1 )
plt.style.use('ggplot')
 %matplotlib inline 
<define_variables>
def rmsle(y, y_,convertExp=True):
if convertExp:
y = np.exp(y),
y_ = np.exp(y_)
 log1 = np.nan_to_num(np.array([np.log(v + 1)for v in y]))
log2 = np.nan_to_num(np.array([np.log(v + 1)for v in y_]))
calc =(log1 - log2)** 2
return np.sqrt(np.mean(calc))
seed = 33
np.random.RandomState(seed)
 valid_size = 0.1
to_augment = False<define_variables>
pd.options.mode.chained_assignment = None
warnings.filterwarnings("ignore", category=DeprecationWarning )
data_path = '.. /input/Kannada-MNIST/'
train_path = data_path + 'train.csv'
test_path = data_path + 'test.csv'
dig_path = data_path + 'Dig-MNIST.csv'
sample_path = data_path + 'sample_submission.csv'
save_path = ''
load_path = '.. /input/kennada-mnist-pretrained-model/'<load_from_csv>
gbm = GradientBoostingRegressor(n_estimators=4000,alpha=0.01);
yLabelsLog = np.log1p(yLabels)
 gbm.fit(dataTrain,yLabelsLog)
 preds = gbm.predict(X= dataTrain)
 print("RMSLE Value For Gradient Boost: ",rmsle(np.exp(yLabelsLog),np.exp(preds),False))
<categorify><EOS> 
submission = pd.DataFrame({
"datetime": datetimecol,
"count": [max(0, x)for x in np.exp(predsTest)]
})
 submission.to_csv('bike_predictions_gbm_separate_without_fe.csv', index=False )