{"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":"none","dataSources":[{"sourceId":16017,"databundleVersionId":708189,"sourceType":"competition"},{"sourceId":10889573,"sourceType":"datasetVersion","datasetId":6766927}],"dockerImageVersionId":30918,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:15.221358Z","iopub.execute_input":"2025-03-01T19:32:15.221722Z","iopub.status.idle":"2025-03-01T19:32:15.230171Z","shell.execute_reply.started":"2025-03-01T19:32:15.221693Z","shell.execute_reply":"2025-03-01T19:32:15.228879Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nprint(os.listdir(\"/kaggle/working/\"))  # List all files in /kaggle/working/","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:15.238661Z","iopub.execute_input":"2025-03-01T19:32:15.239057Z","iopub.status.idle":"2025-03-01T19:32:15.255351Z","shell.execute_reply.started":"2025-03-01T19:32:15.239004Z","shell.execute_reply":"2025-03-01T19:32:15.254172Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    print(dirname)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:15.256803Z","iopub.execute_input":"2025-03-01T19:32:15.257248Z","iopub.status.idle":"2025-03-01T19:32:15.276780Z","shell.execute_reply.started":"2025-03-01T19:32:15.257205Z","shell.execute_reply":"2025-03-01T19:32:15.275396Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\n# Check all available datasets in /kaggle/input/\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))  # Print full file paths","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:15.278510Z","iopub.execute_input":"2025-03-01T19:32:15.278803Z","iopub.status.idle":"2025-03-01T19:32:15.296115Z","shell.execute_reply.started":"2025-03-01T19:32:15.278778Z","shell.execute_reply":"2025-03-01T19:32:15.294852Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:15.297969Z","iopub.execute_input":"2025-03-01T19:32:15.298319Z","iopub.status.idle":"2025-03-01T19:32:15.315468Z","shell.execute_reply.started":"2025-03-01T19:32:15.298290Z","shell.execute_reply":"2025-03-01T19:32:15.314159Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Import necessary libraries\nimport pandas as pd\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow import keras\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom keras.utils import to_categorical\n\n# Load dataset (Make sure the file is uploaded in Kaggle dataset section)\nfile_path = \"/kaggle/input/Kannada-MNIST/Dig-MNIST.csv\"  # Update path if needed\ndf = pd.read_csv(file_path)\n\n# Inspect the dataset\nprint(df.head())\n\n# Separate labels and features\ny = df.iloc[:, 0].values  # First column is the label\nX = df.iloc[:, 1:].values  # The rest are pixel values\n\n# Normalize pixel values to [0, 1]\nX = X / 255.0\n\n# Convert labels to categorical (one-hot encoding)\ny = to_categorical(y, num_classes=10)\n\n# Split into training and test sets\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Define the model (Fully Connected Neural Network)\nmodel = keras.Sequential([\n    keras.layers.Dense(512, activation='relu', input_shape=(X_train.shape[1],)),  # Input layer\n    keras.layers.Dense(256, activation='relu'),  # Hidden layer 1\n    keras.layers.Dense(128, activation='relu'),  # Hidden layer 2\n    keras.layers.Dense(10, activation='softmax')  # Output layer\n])\n\n# Compile the model\nmodel.compile(optimizer='adam',\n              loss='categorical_crossentropy',\n              metrics=['accuracy'])\n\n# Train the model\nhistory = model.fit(X_train, y_train, validation_data=(X_test, y_test),\n                    epochs=20, batch_size=64, verbose=1)\n\n# Evaluate on test data\ntest_loss, test_accuracy = model.evaluate(X_test, y_test)\nprint(f\"Test Accuracy: {test_accuracy:.4f}\")\n\n# Plot accuracy and loss curves\nplt.figure(figsize=(12, 5))\nplt.subplot(1, 2, 1)\nplt.plot(history.history['accuracy'], label='Train Accuracy')\nplt.plot(history.history['val_accuracy'], label='Validation Accuracy')\nplt.legend()\nplt.title('Accuracy Over Epochs')\n\nplt.subplot(1, 2, 2)\nplt.plot(history.history['loss'], label='Train Loss')\nplt.plot(history.history['val_loss'], label='Validation Loss')\nplt.legend()\nplt.title('Loss Over Epochs')\nplt.show()\n\n# Prepare predictions for Kaggle submission\npredictions = model.predict(X_test)\npredicted_labels = np.argmax(predictions, axis=1)\n\n# Create submission DataFrame\nsubmission_df = pd.DataFrame({'Id': np.arange(len(predicted_labels)), 'Label': predicted_labels})\n\n# Save submission file (ensure the correct Kaggle output path)\nsubmission_filename = \"/kaggle/working/submission.csv\"\nsubmission_df.to_csv(submission_filename, index=False)\nprint(f\"Submission file saved as: {submission_filename}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:15.316491Z","iopub.execute_input":"2025-03-01T19:32:15.316836Z","iopub.status.idle":"2025-03-01T19:32:40.355480Z","shell.execute_reply.started":"2025-03-01T19:32:15.316808Z","shell.execute_reply":"2025-03-01T19:32:40.354354Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission_filename = \"/kaggle/working/submission.csv\"\nsubmission_df.to_csv(submission_filename, index=False)\nprint(f\"✅ Submission file saved as: {submission_filename}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.357609Z","iopub.execute_input":"2025-03-01T19:32:40.358028Z","iopub.status.idle":"2025-03-01T19:32:40.367163Z","shell.execute_reply.started":"2025-03-01T19:32:40.357997Z","shell.execute_reply":"2025-03-01T19:32:40.366036Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Ensure predictions are generated correctly\nsubmission_filename = \"/kaggle/working/submission.csv\"\nsubmission_df.to_csv(submission_filename, index=False)\n\n# Confirm file creation\nprint(f\"✅ Submission file saved as: {submission_filename}\")\nprint(os.listdir(\"/kaggle/working/\"))  # Verify file exists","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.368698Z","iopub.execute_input":"2025-03-01T19:32:40.369057Z","iopub.status.idle":"2025-03-01T19:32:40.389823Z","shell.execute_reply.started":"2025-03-01T19:32:40.369027Z","shell.execute_reply":"2025-03-01T19:32:40.388530Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Ensure predictions are generated correctly\nsubmission_filename = \"/kaggle/working/submission.csv\"\nsubmission_df.to_csv(submission_filename, index=False)\n\n# Confirm file creation\nprint(f\"✅ Submission file saved as: {submission_filename}\")\nprint(os.listdir(\"/kaggle/working/\"))  # Verify file exists","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.390994Z","iopub.execute_input":"2025-03-01T19:32:40.391448Z","iopub.status.idle":"2025-03-01T19:32:40.410199Z","shell.execute_reply.started":"2025-03-01T19:32:40.391406Z","shell.execute_reply":"2025-03-01T19:32:40.408987Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.display import FileLink\nFileLink(\"/kaggle/working/submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.411256Z","iopub.execute_input":"2025-03-01T19:32:40.411548Z","iopub.status.idle":"2025-03-01T19:32:40.428990Z","shell.execute_reply.started":"2025-03-01T19:32:40.411514Z","shell.execute_reply":"2025-03-01T19:32:40.427871Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"FileLink(\"/kaggle/working/submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.429962Z","iopub.execute_input":"2025-03-01T19:32:40.430274Z","iopub.status.idle":"2025-03-01T19:32:40.451534Z","shell.execute_reply.started":"2025-03-01T19:32:40.430248Z","shell.execute_reply":"2025-03-01T19:32:40.450263Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\n\nnew_path = \"/kaggle/working/submission.csv\"\nshutil.copy(file_path, new_path)\n\nprint(f\"✅ File copied to: {new_path}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.452596Z","iopub.execute_input":"2025-03-01T19:32:40.453010Z","iopub.status.idle":"2025-03-01T19:32:40.504168Z","shell.execute_reply.started":"2025-03-01T19:32:40.452974Z","shell.execute_reply":"2025-03-01T19:32:40.503019Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.display import FileLink\nFileLink(\"/kaggle/working/submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-01T19:32:40.506249Z","iopub.execute_input":"2025-03-01T19:32:40.506596Z","iopub.status.idle":"2025-03-01T19:32:40.513029Z","shell.execute_reply.started":"2025-03-01T19:32:40.506565Z","shell.execute_reply":"2025-03-01T19:32:40.511978Z"}},"outputs":[],"execution_count":null}]}