{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport keras\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"def load_train_mnist():\n    path = '/kaggle/input/digit-recognizer/train.csv'\n    raw_data = np.loadtxt(path, delimiter = ',', skiprows = 1)\n    raw_X = raw_data[:, 1:]\n    raw_Y = raw_data[:, 0]\n    return (raw_X, raw_Y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_X, train_Y = load_train_mnist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_model():\n    X_input = keras.layers.Input((784,))\n    #Yhat = keras.layers.Dense(512, activation = 'relu')(X_input)\n    Yhat = keras.layers.Dense(256, activation = 'relu')(X_input)\n    Yhat = keras.layers.Dense(64, activation = 'relu')(Yhat)\n    Yhat = keras.layers.Dense(10, activation = 'softmax')(Yhat)\n    \n    model = keras.models.Model(inputs = X_input, outputs = Yhat)\n    \n    return model","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learning_rate = 0.001\nbatch_size = 2048\nnum_epochs = 1000","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = get_model()\n\nmodel.compile(optimizer = keras.optimizers.Adam(learning_rate = learning_rate), loss = 'categorical_crossentropy', metrics = ['accuracy'])\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_Y_one_hotted = keras.utils.to_categorical(train_Y, 10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"hist = model.fit(x = train_X, y = train_Y_one_hotted, batch_size = batch_size, epochs = num_epochs, validation_split = 0.5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.plot(hist.history['loss'])\nplt.plot(hist.history['accuracy'])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}