Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<feature_engineering>
%matplotlib inline
c=[]
for i in test['hour']:
if i>= 6 or i<= 1 :
c.append("Day")
 else:
c.append("Night")
 test['DayorNight']=c
test['DayorNight']=pd.factorize(test['DayorNight'])[0].reshape(-1, 1)
 c=[]
test = test.drop('datetime' , axis =1)
 test<feature_engineering>
train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv' )
c=[]
for i in train['hour']:
if i>= 6 or i<= 1 :
c.append("Day")
 else:
c.append("Night")
 train['DayorNight']=c
train['DayorNight']=pd.factorize(train['DayorNight'])[0].reshape(-1, 1)
 c=[]
train.head(2 )<drop_column>
X_train = train.iloc[:,1:].values.astype('float32')
 y_train = train['label'].values.astype('int32')
 test = test.values.astype('float32')
 del train
x = train
x =x.drop('count',axis=1)
 x<split>
X_train = X_train / 255.0
test = test / 255.0
x_train, x_val, y_train, y_val = train_test_split(x , y, train_size=0.8, test_size=0.2, random_state = 0 )<import_modules>
y_train = to_categorical(y_train)
 y_train
import xgboost as xgb
from sklearn.model_selection import cross_val_score, KFold
from sklearn.metrics import accuracy_score
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_log_error 
<import_modules>
np.random.seed(2 )
<compute_train_metric>
X_train, X_test, y_train, y_test = train_test_split(X_train, y_train, test_size = 0.0001, random_state = 2 )
xgbr = xgb.XGBRegressor(verbosity=0)
 xgbr.fit(x_train, y_train)
 score_xgbr = xgbr.score(x_train, y_train)
 print("Training score: ", score_xgbr)
 scores_xgbr = cross_val_score(xgbr, x_train, y_train,cv=10)
 print("Mean cross-validation score: %.2f" % scores_xgbr.mean())
 y_pred_xgbr = xgbr.predict(x_val)
 print('Validation score' , xgbr.score(x_val , y_val))
rmsle_xgbr = mean_squared_log_error(y_pred_xgbr ,y_val)
 print("RMSLE: %.2f" % rmsle_xgbr)
<compute_train_metric>
model = Sequential()
model.add(Conv2D(filters = 64, kernel_size =(5,5), padding = 'Same', activation = 'relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 64, kernel_size =(5,5), padding = 'Same', activation = 'relu'))
model.add(MaxPool2D(pool_size=(2,2)))
 model.add(Dropout(0.2))
model.add(Conv2D(filters = 128, kernel_size =(3,3), padding = 'Same', activation = 'relu'))
model.add(Conv2D(filters = 128, kernel_size =(3,3), padding = 'Same', activation = 'relu'))
model.add(MaxPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.2))
model.add(Flatten())
 model.add(Dense(512, activation = 'relu'))
model.add(Dropout(0.2))
model.add(Dense(10, activation = 'softmax'))
<predict_on_test>
model.compile(optimizer="adam", loss='categorical_crossentropy', metrics=['accuracy'] )
pred =np.round(np.expm1(xgbr.predict(test)) ).astype(int)
 pred = pd.DataFrame({"datetime": test_df["datetime"],"count": np.fix(pred)})
 pred.shape<set_options>
epochs = 38
batch_size = 64
plt.style.use('bmh')
 %matplotlib inline 
<load_from_csv>
datagen = ImageDataGenerator(featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=10,
zoom_range=0.1,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=False,
vertical_flip=False)
 datagen.fit(X_train )
train_df=pd.read_csv('.. /input/bike-sharing-demand/train.csv')
 test_df=pd.read_csv('.. /input/bike-sharing-demand/test.csv')
 display(train_df.head() )<count_duplicates>
history = model.fit_generator(datagen.flow(X_train,y_train, batch_size=batch_size),
epochs = epochs, validation_data =(X_test,y_test),
verbose = 2, steps_per_epoch=X_train.shape[0] // batch_size )
train_df.duplicated().sum() 
<count_missing_values>
results = model.predict(test)
print(train_df.isnull().sum())
 print(test_df.isnull().sum() )<feature_engineering>
output = pd.concat([pd.Series(range(1,28001), name = 'ImageId'), results], axis = 1)
 output
<feature_engineering><EOS> 
output.to_csv('submission.csv', index=False )