Kaggle competition: Digit Recognizer
test_data['color'].value_counts()<categorify>
sns.set()
train_data=pd.concat([train_data,pd.get_dummies(train_data['color'])],axis=1)
 train_data.drop('color',axis=1,inplace=True)
 train_data.head()<categorify>
train_data = pd.read_csv(".. /input/train.csv")
 test_data = pd.read_csv(".. /input/test.csv")
 sample_submission = pd.read_csv(".. /input/sample_submission.csv" )
test_data=pd.concat([test_data,pd.get_dummies(test_data['color'])],axis=1)
 test_data.drop('color',axis=1,inplace=True)
 test_data.head()<prepare_x_and_y>
X_train = train_data.drop("label", axis=1)
 y_train = train_data[["label"]]
X_test = test_data.copy()
X=train_data.drop(['id','type'],axis=1)
 y=pd.get_dummies(train_data['type'] )<split>
X_train = X_train.astype("float32")/ 255
X_test = X_test.astype("float32")/ 255
X_train = X_train.values.reshape(( len(X_train), 28, 28, 1))
X_test = X_test.values.reshape(( len(X_test), 28, 28, 1))
y_train = pd.get_dummies(y_train, columns=["label"] )
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.1,random_state=42)
 print(X_train.shape,y_train.shape)
 print(X_test.shape,y_test.shape )<import_modules>
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), padding="valid", input_shape=X_train.shape[1:]))
model.add(Activation("relu"))
model.add(Conv2D(64, kernel_size=(3, 3), padding="valid"))
model.add(Activation("relu"))
model.add(MaxPool2D(pool_size=(2, 2)))
 model.add(Dropout(0.2))
model.add(Conv2D(64, kernel_size=(3, 3), padding="valid"))
model.add(Activation("relu"))
model.add(Conv2D(128, kernel_size=(3, 3), padding="valid"))
model.add(Activation("relu"))
model.add(MaxPool2D(pool_size=(2, 2)))
 model.add(Dropout(0.2))
model.add(Flatten())
 model.add(Dense(128))
model.add(Activation("relu"))
model.add(Dropout(0.4))
model.add(Dense(10))
model.add(Activation("softmax"))
model.compile(optimizer="adadelta", loss="categorical_crossentropy", metrics=["accuracy"])
 model.summary()
from tensorflow import keras
from keras.layers import Dense,Dropout
from keras.models import Sequential<choose_model_class>
epochs = 50
batch_size = 256
model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_split=0.2 )
model=Sequential()
model.add(Dense(100,input_shape=(X.shape[1],)))
 model.add(Dense(100,activation='relu'))
model.add(Dense(100,activation='relu'))
model.add(Dense(3,activation='softmax'))
model.summary()<choose_model_class>
y_pred = np.argmax(model.predict(X_test), axis=1 )
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'] )<train_model>
result = pd.Series(y_pred, name="Label" ).to_frame().reset_index().rename(columns={"index": "ImageId"})
 result["ImageId"] += 1
result.head()
<import_modules><EOS> 
result.to_csv("out.csv", index=False )