{"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_minor":4,"nbformat":4,"cells":[{"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 20GB 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\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom tensorflow.keras.layers import Dense\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.utils import to_categorical","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-12T07:23:12.481118Z","iopub.execute_input":"2023-03-12T07:23:12.481539Z","iopub.status.idle":"2023-03-12T07:23:12.493236Z","shell.execute_reply.started":"2023-03-12T07:23:12.481500Z","shell.execute_reply":"2023-03-12T07:23:12.491527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest  = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\n#train.head()\n#train.info()\n#test.info()\n#null_percent = (train.isnull().sum()/train.isnull().count()).sort_values(ascending=False)\n#null_percent.head(10)\n\n# Drop 'label' column\ntrain_X = train.drop(labels = [\"label\"],axis = 1)\ntrain_y = to_categorical(train[\"label\"])","metadata":{"execution":{"iopub.status.busy":"2023-03-12T07:23:12.495414Z","iopub.execute_input":"2023-03-12T07:23:12.495777Z","iopub.status.idle":"2023-03-12T07:23:15.198287Z","shell.execute_reply.started":"2023-03-12T07:23:12.495719Z","shell.execute_reply":"2023-03-12T07:23:15.196689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(9):\n    plt.subplot(3,3,i+1)\n    img_1d = train.iloc[i,:-1].values\n    img = img_1d.reshape(28,28)\n    plt.imshow(img,cmap='gray')","metadata":{"execution":{"iopub.status.busy":"2023-03-12T07:23:15.199975Z","iopub.execute_input":"2023-03-12T07:23:15.200356Z","iopub.status.idle":"2023-03-12T07:23:15.893039Z","shell.execute_reply.started":"2023-03-12T07:23:15.200311Z","shell.execute_reply":"2023-03-12T07:23:15.891599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"deep learning model","metadata":{}},{"cell_type":"code","source":"# Create the model: model\nmodel = Sequential()\n\n# Add the first hidden layer\nmodel.add(Dense(1000, activation='relu', input_shape=(784,)))\n\n# Add the second hidden layer\nmodel.add(Dense(1000, activation='relu'))\n\n# Add the output layer\nmodel.add(Dense(10, activation='softmax'))\n\n# Compile the model\nmodel.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])\n\n# Fit the model\nmodel.fit(x=train_X,y=train_y,validation_split=0.2,epochs=10)\n\n#predict results\npredictions = model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2023-03-12T07:23:15.895787Z","iopub.execute_input":"2023-03-12T07:23:15.896544Z","iopub.status.idle":"2023-03-12T07:26:42.395482Z","shell.execute_reply.started":"2023-03-12T07:23:15.896494Z","shell.execute_reply":"2023-03-12T07:26:42.394239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = np.argmax(predictions,axis = 1)\npredictions = pd.Series(predictions,name=\"Label\")\nsubmission  = pd.concat([pd.Series(range(1,28001),name = \"ImageId\"),predictions],axis = 1)\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-03-12T07:26:42.397087Z","iopub.execute_input":"2023-03-12T07:26:42.397470Z","iopub.status.idle":"2023-03-12T07:26:42.431288Z","shell.execute_reply.started":"2023-03-12T07:26:42.397433Z","shell.execute_reply":"2023-03-12T07:26:42.429683Z"},"trusted":true},"execution_count":null,"outputs":[]}]}