{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":16017,"databundleVersionId":708189,"sourceType":"competition"}],"dockerImageVersionId":30627,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Veri setini yükle\n#test_data = pd.read_csv(\"/kaggle/input/Kannada-MNIST/test.csv\")\ntrain_data = pd.read_csv(\"/kaggle/input/Kannada-MNIST/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:34.180236Z","iopub.execute_input":"2023-12-24T11:33:34.180536Z","iopub.status.idle":"2023-12-24T11:33:39.352267Z","shell.execute_reply.started":"2023-12-24T11:33:34.180480Z","shell.execute_reply":"2023-12-24T11:33:39.351296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_data.info()","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:39.354175Z","iopub.execute_input":"2023-12-24T11:33:39.354478Z","iopub.status.idle":"2023-12-24T11:33:39.359185Z","shell.execute_reply.started":"2023-12-24T11:33:39.354450Z","shell.execute_reply":"2023-12-24T11:33:39.358037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:39.360549Z","iopub.execute_input":"2023-12-24T11:33:39.360828Z","iopub.status.idle":"2023-12-24T11:33:39.443546Z","shell.execute_reply.started":"2023-12-24T11:33:39.360806Z","shell.execute_reply":"2023-12-24T11:33:39.442559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = train_data.iloc[:, 1:].values\ntrain_labels = train_data.iloc[:, 0].values\n#test_images = test_data.iloc[:, 1:].values\n#test_labels = test_data.iloc[:, 0].values","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:39.445571Z","iopub.execute_input":"2023-12-24T11:33:39.445864Z","iopub.status.idle":"2023-12-24T11:33:39.451311Z","shell.execute_reply.started":"2023-12-24T11:33:39.445833Z","shell.execute_reply":"2023-12-24T11:33:39.450312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = train_images.astype('float32')\n#test_images = test_images.astype('float32')","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:41.665179Z","iopub.execute_input":"2023-12-24T11:33:41.666072Z","iopub.status.idle":"2023-12-24T11:33:41.748228Z","shell.execute_reply.started":"2023-12-24T11:33:41.666034Z","shell.execute_reply":"2023-12-24T11:33:41.747453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:42.954242Z","iopub.execute_input":"2023-12-24T11:33:42.954979Z","iopub.status.idle":"2023-12-24T11:33:42.961610Z","shell.execute_reply.started":"2023-12-24T11:33:42.954943Z","shell.execute_reply":"2023-12-24T11:33:42.960641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Görüntüleri 28x28 piksel boyutuna yeniden şekillendir\ntrain_images = train_images.reshape(60000,28,28)#train_labels = np.reshape(train_labels, (60000,))\n#test_images = np.reshape(test_images, (5000,28,28))\n#test_labels = np.reshape(test_labels, (5000,))","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:45.381064Z","iopub.execute_input":"2023-12-24T11:33:45.381406Z","iopub.status.idle":"2023-12-24T11:33:45.385737Z","shell.execute_reply.started":"2023-12-24T11:33:45.381370Z","shell.execute_reply":"2023-12-24T11:33:45.384791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_labels","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:46.704870Z","iopub.execute_input":"2023-12-24T11:33:46.705622Z","iopub.status.idle":"2023-12-24T11:33:46.709458Z","shell.execute_reply.started":"2023-12-24T11:33:46.705592Z","shell.execute_reply":"2023-12-24T11:33:46.708517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels ","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:47.783880Z","iopub.execute_input":"2023-12-24T11:33:47.784208Z","iopub.status.idle":"2023-12-24T11:33:47.790373Z","shell.execute_reply.started":"2023-12-24T11:33:47.784180Z","shell.execute_reply":"2023-12-24T11:33:47.789540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(train_images[0]) #images icine kacinci resim yazarsan print ","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:48.637164Z","iopub.execute_input":"2023-12-24T11:33:48.637527Z","iopub.status.idle":"2023-12-24T11:33:48.933805Z","shell.execute_reply.started":"2023-12-24T11:33:48.637475Z","shell.execute_reply":"2023-12-24T11:33:48.932822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images[0].shape","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:51.088985Z","iopub.execute_input":"2023-12-24T11:33:51.089334Z","iopub.status.idle":"2023-12-24T11:33:51.095649Z","shell.execute_reply.started":"2023-12-24T11:33:51.089304Z","shell.execute_reply":"2023-12-24T11:33:51.094676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels[5000]","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:52.859928Z","iopub.execute_input":"2023-12-24T11:33:52.860780Z","iopub.status.idle":"2023-12-24T11:33:52.866538Z","shell.execute_reply.started":"2023-12-24T11:33:52.860745Z","shell.execute_reply":"2023-12-24T11:33:52.865596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(train_images[70],cmap='gray') #images icine kacinci resim yazarsan print ","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:54.552894Z","iopub.execute_input":"2023-12-24T11:33:54.553224Z","iopub.status.idle":"2023-12-24T11:33:54.807940Z","shell.execute_reply.started":"2023-12-24T11:33:54.553197Z","shell.execute_reply":"2023-12-24T11:33:54.807050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plt.imshow(test_images[0],cmap='gray') ","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:55.757883Z","iopub.execute_input":"2023-12-24T11:33:55.758236Z","iopub.status.idle":"2023-12-24T11:33:55.762658Z","shell.execute_reply.started":"2023-12-24T11:33:55.758207Z","shell.execute_reply":"2023-12-24T11:33:55.761534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_images[0].shape","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:56.530807Z","iopub.execute_input":"2023-12-24T11:33:56.531139Z","iopub.status.idle":"2023-12-24T11:33:56.534885Z","shell.execute_reply.started":"2023-12-24T11:33:56.531109Z","shell.execute_reply":"2023-12-24T11:33:56.533989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Normalize/ Standardize\ntrain_images=train_images/255.0\n#test_images=test_images/255.0","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:57.065438Z","iopub.execute_input":"2023-12-24T11:33:57.065818Z","iopub.status.idle":"2023-12-24T11:33:57.125061Z","shell.execute_reply.started":"2023-12-24T11:33:57.065790Z","shell.execute_reply":"2023-12-24T11:33:57.124204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\ntrain_images, test_images, train_labels, test_labels = train_test_split(train_images, train_labels, test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:33:57.962229Z","iopub.execute_input":"2023-12-24T11:33:57.962938Z","iopub.status.idle":"2023-12-24T11:33:59.062291Z","shell.execute_reply.started":"2023-12-24T11:33:57.962906Z","shell.execute_reply":"2023-12-24T11:33:59.061255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense,Conv2D,MaxPooling2D,Flatten,InputLayer,Reshape\nfrom tensorflow.keras.layers import BatchNormalization","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:34:00.272577Z","iopub.execute_input":"2023-12-24T11:34:00.273287Z","iopub.status.idle":"2023-12-24T11:34:17.179677Z","shell.execute_reply.started":"2023-12-24T11:34:00.273257Z","shell.execute_reply":"2023-12-24T11:34:17.178809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Conv2D(32,(3,3),activation='relu',input_shape=(28,28,1)))#hidden layers (orta layerlar)shape \nmodel.add(Conv2D(64,(3,3),activation='relu')) \nmodel.add(MaxPooling2D(pool_size=(2,2)))#Maxpool CNN\nmodel.add(Flatten())\nmodel.add(Dense(100,activation='relu'))\nmodel.add(Dense(10,activation='softmax'))#birden fazla somnuc oldugu icin softmax eklendi\nmodel.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),optimizer='adam',metrics='accuracy')#classification ","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:34:17.181529Z","iopub.execute_input":"2023-12-24T11:34:17.182523Z","iopub.status.idle":"2023-12-24T11:34:22.646323Z","shell.execute_reply.started":"2023-12-24T11:34:17.182466Z","shell.execute_reply":"2023-12-24T11:34:22.645335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit(train_images,train_labels,batch_size = 32,epochs=5,verbose= 1,validation_data=(test_images,test_labels))","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:34:22.647379Z","iopub.execute_input":"2023-12-24T11:34:22.647666Z","iopub.status.idle":"2023-12-24T11:35:02.944295Z","shell.execute_reply.started":"2023-12-24T11:34:22.647641Z","shell.execute_reply":"2023-12-24T11:35:02.943441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_,accuracy=model.evaluate(test_images,test_labels)\nprint('Accuracy=%2f'%(accuracy*100))","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:35:02.946261Z","iopub.execute_input":"2023-12-24T11:35:02.946565Z","iopub.status.idle":"2023-12-24T11:35:03.847332Z","shell.execute_reply.started":"2023-12-24T11:35:02.946539Z","shell.execute_reply":"2023-12-24T11:35:03.846442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.title('Model Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend(['Train','Test'],loc='upper left')\nplt.show()\n\nplt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('Model Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend(['Train','Test'],loc='upper left')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:35:03.848646Z","iopub.execute_input":"2023-12-24T11:35:03.849032Z","iopub.status.idle":"2023-12-24T11:35:04.465337Z","shell.execute_reply.started":"2023-12-24T11:35:03.848996Z","shell.execute_reply":"2023-12-24T11:35:04.464306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Xsubmission_df = pd.read_csv('/kaggle/input/Kannada-MNIST/test.csv')\n\n# id sütununu ve pixel sütununu içeren test.csv dosyasını yükle\n\n# Öznitelikleri çıkarın ve numpy dizisine dönüştürün\nX_submission_test = Xsubmission_df.drop(columns=['id']).values\n\n# Veriyi 28x28 boyutunda yeniden şekillendirin\nX_submission_test_reshaped = X_submission_test.reshape(-1, 28, 28, 1)\n\n# Tahminleri elde edin\npredictions = model.predict(X_submission_test_reshaped)\n\n# submission.csv dosyasını oluşturmak için gerekli veri çerçevesini oluşturun\nsubmission_df = pd.DataFrame(data={\n    \"id\": Xsubmission_df['id'],\n    \"label\": np.argmax(predictions, axis=1)\n})\n\n# submission.csv olarak kaydedin\nsubmission_df.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-12-24T11:49:14.001997Z","iopub.execute_input":"2023-12-24T11:49:14.002821Z","iopub.status.idle":"2023-12-24T11:49:14.741781Z","shell.execute_reply.started":"2023-12-24T11:49:14.002787Z","shell.execute_reply":"2023-12-24T11:49:14.740987Z"},"trusted":true},"execution_count":null,"outputs":[]}]}