Kaggle competition: Digit Recognizer
__model = CatBoostClassifier()
__model.fit(__feature_train, __target_train)
 __y_pred = __model.predict_proba(__feature_test )<create_dataframe>
df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 df2 = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')
 print(df.shape)
 print(df2.shape )
submission = pd.DataFrame(columns=['Id'], data=__test_dataset_submission_columns)
 submission = pd.concat([submission, pd.DataFrame(__y_pred, columns=["ARSON", "ASSAULT", "BAD CHECKS", "BRIBERY", "BURGLARY", "DISORDERLY CONDUCT",
"DRIVING UNDER THE INFLUENCE", "DRUG/NARCOTIC", "DRUNKENNESS", "EMBEZZLEMENT", "EXTORTION",
"FAMILY OFFENSES", "FORGERY/COUNTERFEITING", "FRAUD", "GAMBLING", "KIDNAPPING", "LARCENY/THEFT",
"LIQUOR LAWS", "LOITERING", "MISSING PERSON", "NON-CRIMINAL", "OTHER OFFENSES", "PORNOGRAPHY/OBSCENE MAT",
"PROSTITUTION", "RECOVERED VEHICLE", "ROBBERY", "RUNAWAY", "SECONDARY CODES", "SEX OFFENSES FORCIBLE",
"SEX OFFENSES NON FORCIBLE", "STOLEN PROPERTY", "SUICIDE", "SUSPICIOUS OCC", "TREA", "TRESPASS",
"VANDALISM", "VEHICLE THEFT", "WARRANTS", "WEAPON LAWS"])], axis=1)
 submission.head()<save_to_csv>
x = np.array(df.drop('label',axis=1)) /255
y = np.array(df.label)
 test = np.array(df2)/255
enc = OneHotEncoder(sparse=False)
 y= y.reshape(( -1,1))
y = enc.fit_transform(y)
 print(x.shape)
 print(y.shape)
 print(test.shape )
submission.to_csv("kaggle_submission.csv", index=False )<set_options>
x_train,x_test,y_train,y_test = tts(x_2d,y,test_size = 0.15, random_state=42)
 print(x_train.shape)
 print(y_train.shape)
 print(x_test.shape)
 print(y_test.shape )
%matplotlib inline<load_from_csv>
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from keras import applications
from keras.utils.np_utils import to_categorical
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D, BatchNormalization
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import LearningRateScheduler
from keras.callbacks import ReduceLROnPlateau
train = pd.read_csv('/kaggle/input/sf-crime/train.csv.zip', parse_dates= ['Dates'])
 test = pd.read_csv('/kaggle/input/sf-crime/test.csv.zip', parse_dates= ['Dates'], index_col = 'Id' )<concatenate>
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.5))
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.5))
model.add(Conv2D(128, kernel_size = 4, activation='relu'))
model.add(BatchNormalization())
 model.add(Flatten())
 model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
model.summary()
x = list(test)
 t_data= train[x]
join = pd.concat([t_data, test])
 merge = join.copy() 
<count_missing_values>
callbacks = [
keras.callbacks.EarlyStopping(
 monitor='val_loss',
min_delta=1e-5,
patience=15,
verbose=1)
 ]
t= train['Category']
merge.isnull().sum()<categorify>
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
 history = model.fit(x_2d,y,batch_size=64,epochs=600,validation_data=(x_test,y_test))
LB = LabelEncoder()
tar = LB.fit_transform(t)
 print(LB.classes_ )<feature_engineering>
scores = model.evaluate(x_test, y_test, verbose = 10)
 print(scores )
date = pd.to_datetime(join['Dates'])
 merge['Date'] = date.dt.date
merge['Year'] = date.dt.year
merge['Month'] = date.dt.month
merge['Day'] = date.dt.day
merge['Hour'] = date.dt.hour
merge.drop('Dates', axis = 1, inplace = True )<groupby>
predictions=model.predict(test_2d)
 pre=predictions.argmax(axis=-1 )
<categorify><EOS> 
submission = pd.Series(pre,name="Label")
 submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),submission],axis = 1)
 submission.to_csv("final_submission_lenet5.csv",index=False)
 submission.head()