{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.model_selection import train_test_split\n\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Flatten, Dropout, Conv2D, MaxPooling2D, BatchNormalization\nfrom tensorflow.keras.losses import SparseCategoricalCrossentropy as SCC\n\nimport tensorflow as tf\nimport math\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"eresim = pd.read_csv(\"../input/digit-recognizer/train.csv\")\nkresim= pd.read_csv(\"../input/digit-recognizer/test.csv\")\n\neresim.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"A_eresim = eresim.iloc[:,1:]\nB_eresim = eresim.iloc[:,0]\n\nA_kresim = kresim.iloc[:,1:]\nB_kresim = kresim.iloc[:,0]\n\nA_eresim.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# normalizing\nA_eresim = A_eresim.astype('float32')\nA_kresim = A_kresim.astype('float32')\n\nA_eresim /= 255\nA_kresim /= 255\n\nkresim = kresim / 255\n\nresim_yks = 28\nresim_yty = 28\nveri=10","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"A_eresim.shape, kresim.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"A_eresim = A_eresim.values.reshape(A_eresim.shape[0],resim_yks,resim_yty,1)\nkresim = kresim.values.reshape(kresim.shape[0],resim_yks,resim_yty,1)\n\nA_eresim.shape, kresim.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"A_eresim, A_kresim, B_eresim, B_kresim = train_test_split(A_eresim, B_eresim, test_size = 0.2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(3,3,figsize=(10,10))\n\nnums, x = range(10), 0\nfor i in range(3):\n    for j in range(3):\n        label = nums[x]\n        numbers_pixels = eresim[eresim['label']==label]\n        img = numbers_pixels.iloc[0,1:].values\n        img = img.reshape((28,28))\n        ax[i][j].imshow(img, cmap=plt.cm.binary)\n        ax[i][j].set_title(\"Number: \" + str(label))\n        x += 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nmodel = Sequential()\nmodel.add(Conv2D(32, kernel_size=(3, 3),\n                 activation='relu',\n                 input_shape=(resim_yks, resim_yty, 1)))\n\nmodel.add(Conv2D(64, (3, 3), activation='relu'))\n\nmodel.add(Dropout(0.25))\nmodel.add(Flatten())\nmodel.add(Dense(128, activation='relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(veri, activation='softmax')) # 10 labels\n\n\nteksefer_veri=128\nysa=5\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.compile(optimizer='adam', loss=SCC(), metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.fit(A_eresim, B_eresim, batch_size=teksefer_veri, epochs=ysa, validation_data=(A_kresim, B_kresim))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"initial_submission = model.predict(kresim)\ninitial_submission_labels = np.argmax(initial_submission, axis=1)\nsubmission1 = pd.DataFrame({'ImageId': np.arange(1, 28001), 'Label': initial_submission_labels})\nsubmission1.to_csv(\"sonuccc.csv\", index=False)","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}