{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"filenameTrain = \"/kaggle/input/digit-recognizer/train.csv\"\ndataframeTrain = pd.read_csv(filenameTrain)\n# print(dataframe.head)\nfilenameTest = \"/kaggle/input/digit-recognizer/test.csv\"\ndataframeTest = pd.read_csv(filenameTest)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_train = dataframeTrain.iloc[:,1:].values.astype('float32')\nX_train = X_train / 255.0\n# print(len(X_train))\nX_Train = X_train.reshape(len(X_train),784)\n\ny_train = dataframeTrain.iloc[:,0].values\n# y_Train = y_train.reshape(len(y_train), 1)\n\nX_test = dataframeTest.iloc[:,:].values.astype('float32')\nX_test = X_test / 255.0\n# print(len(X_test[0]))\nX_Test = X_test.reshape(len(X_test), 784)\n\n# y_test = dataframeTest.iloc[:,0].values\n# y_Test = y_test.reshape(len(y_test), 1)\n\n# X_train = X_train.reshape(len(X_train),784)\n# print(y_train.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.utils import to_categorical\ntrain_y = to_categorical(y_train)\n# test_y = to_categorical(y_Test, num_classes=10)\n# print(y_train[0])\n# print(y_train.shape)\n# y_train = y_train.reshape(len(y_train), 1)\n# print(y_train.shape)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense, Dropout\nmodel = Sequential()\nmodel.add(Dense(512, input_shape=(784,), activation='relu'))\nmodel.add(Dropout(0.25))\nmodel.add(Dense(512, activation='relu'))\nmodel.add(Dropout(0.25))\nmodel.add(Dense(10, activation='softmax'))\nmodel.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')\nhistory = model.fit(X_train, train_y,batch_size=128, epochs=10,verbose=2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"predictions = model.predict_classes(X_Test, verbose=2)\n# print(type(predictions))\n# print(predictions)\ndata = {'ImageId': list(range(1, len(X_Test) + 1)), 'Label': predictions}\nresult = pd.DataFrame(data)\n# result[\"ImageId\"] = list(range(1, len(X_Test) + 1))\n# result[\"Label\"] = predictions\nresult.to_csv(\"submission.csv\", index=False)\nprint(\"Amount of test points:\", len(X_Test))\nprint(\"Amount of predictions:\", len(predictions))\n\nresult.head()","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}