{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":77476,"databundleVersionId":8462666,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"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","execution":{"iopub.status.busy":"2024-05-16T05:47:40.448255Z","iopub.execute_input":"2024-05-16T05:47:40.448668Z","iopub.status.idle":"2024-05-16T05:47:40.460428Z","shell.execute_reply.started":"2024-05-16T05:47:40.448640Z","shell.execute_reply":"2024-05-16T05:47:40.458993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import libraries \nimport pandas as pd # Import Pandas for data manipulation using dataframes\nimport numpy as np # Import Numpy for data statistical analysis \nimport matplotlib.pyplot as plt # Import matplotlib for data visualisation\nimport seaborn as sns\nimport random\n\n%matplotlib inline\nsns.set_style(\"whitegrid\")","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:40.463421Z","iopub.execute_input":"2024-05-16T05:47:40.464170Z","iopub.status.idle":"2024-05-16T05:47:40.474930Z","shell.execute_reply.started":"2024-05-16T05:47:40.464128Z","shell.execute_reply":"2024-05-16T05:47:40.473328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/2024-smarcle-ks-3-fashion-mnist2/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/2024-smarcle-ks-3-fashion-mnist2/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:40.476569Z","iopub.execute_input":"2024-05-16T05:47:40.477502Z","iopub.status.idle":"2024-05-16T05:47:47.307054Z","shell.execute_reply.started":"2024-05-16T05:47:40.477464Z","shell.execute_reply":"2024-05-16T05:47:47.305912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.308462Z","iopub.execute_input":"2024-05-16T05:47:47.308772Z","iopub.status.idle":"2024-05-16T05:47:47.329689Z","shell.execute_reply.started":"2024-05-16T05:47:47.308743Z","shell.execute_reply":"2024-05-16T05:47:47.328487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.tail()","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.332704Z","iopub.execute_input":"2024-05-16T05:47:47.333109Z","iopub.status.idle":"2024-05-16T05:47:47.356598Z","shell.execute_reply.started":"2024-05-16T05:47:47.333079Z","shell.execute_reply":"2024-05-16T05:47:47.355308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.358567Z","iopub.execute_input":"2024-05-16T05:47:47.359012Z","iopub.status.idle":"2024-05-16T05:47:47.381017Z","shell.execute_reply.started":"2024-05-16T05:47:47.358981Z","shell.execute_reply":"2024-05-16T05:47:47.379962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.tail()","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.382371Z","iopub.execute_input":"2024-05-16T05:47:47.382691Z","iopub.status.idle":"2024-05-16T05:47:47.405470Z","shell.execute_reply.started":"2024-05-16T05:47:47.382664Z","shell.execute_reply":"2024-05-16T05:47:47.403919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.407776Z","iopub.execute_input":"2024-05-16T05:47:47.408514Z","iopub.status.idle":"2024-05-16T05:47:47.416316Z","shell.execute_reply.started":"2024-05-16T05:47:47.408473Z","shell.execute_reply":"2024-05-16T05:47:47.414973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.417657Z","iopub.execute_input":"2024-05-16T05:47:47.418098Z","iopub.status.idle":"2024-05-16T05:47:47.429286Z","shell.execute_reply.started":"2024-05-16T05:47:47.418060Z","shell.execute_reply":"2024-05-16T05:47:47.428093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.431397Z","iopub.execute_input":"2024-05-16T05:47:47.431824Z","iopub.status.idle":"2024-05-16T05:47:47.458245Z","shell.execute_reply.started":"2024-05-16T05:47:47.431784Z","shell.execute_reply":"2024-05-16T05:47:47.457188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create training and testing arrays\ntrain = np.array(train_df, dtype='float32')\ntest = np.array(test_df, dtype='float32')","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.459979Z","iopub.execute_input":"2024-05-16T05:47:47.460296Z","iopub.status.idle":"2024-05-16T05:47:47.700645Z","shell.execute_reply.started":"2024-05-16T05:47:47.460268Z","shell.execute_reply":"2024-05-16T05:47:47.699259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.702218Z","iopub.execute_input":"2024-05-16T05:47:47.702573Z","iopub.status.idle":"2024-05-16T05:47:47.710702Z","shell.execute_reply.started":"2024-05-16T05:47:47.702543Z","shell.execute_reply":"2024-05-16T05:47:47.709398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.712492Z","iopub.execute_input":"2024-05-16T05:47:47.713967Z","iopub.status.idle":"2024-05-16T05:47:47.723422Z","shell.execute_reply.started":"2024-05-16T05:47:47.713922Z","shell.execute_reply":"2024-05-16T05:47:47.722134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.728610Z","iopub.execute_input":"2024-05-16T05:47:47.729172Z","iopub.status.idle":"2024-05-16T05:47:47.737821Z","shell.execute_reply.started":"2024-05-16T05:47:47.729126Z","shell.execute_reply":"2024-05-16T05:47:47.736737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = ['T_shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', \n               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']\n\n# Let's view some images!\ni = random.randint(1,60000) # select any random index from 1 to 60,000\nplt.imshow(train[i,1:].reshape((28,28))) # reshape and plot the image\n\nplt.imshow(train[i,1:].reshape((28,28)) , cmap = 'gray') # reshape and plot the image\nlabel_index = train_df[\"label\"][i]\nplt.title(f\"{class_names[label_index]}\")","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:47.740020Z","iopub.execute_input":"2024-05-16T05:47:47.740482Z","iopub.status.idle":"2024-05-16T05:47:48.194081Z","shell.execute_reply.started":"2024-05-16T05:47:47.740439Z","shell.execute_reply":"2024-05-16T05:47:48.192950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Remember the 10 classes decoding is as follows:   \n0 => T-shirt/top   \n1 => Trouser   \n2 => Pullover   \n3 => Dress   \n4 => Coat   \n5 => Sandal   \n6 => Shirt   \n7 => Sneaker   \n8 => Bag   \n9 => Ankle boot   ","metadata":{}},{"cell_type":"code","source":"label = train[i,0]\nlabel","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:48.195537Z","iopub.execute_input":"2024-05-16T05:47:48.195853Z","iopub.status.idle":"2024-05-16T05:47:48.204761Z","shell.execute_reply.started":"2024-05-16T05:47:48.195825Z","shell.execute_reply":"2024-05-16T05:47:48.203237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let's view more images in a grid format\n# Define the dimensions of the plot grid \nW_grid = 15\nL_grid = 15\n\n# fig, axes = plt.subplots(L_grid, W_grid)\n# subplot return the figure object and axes object\n# we can use the axes object to plot specific figures at various locations\n\nfig, axes = plt.subplots(L_grid, W_grid, figsize=(17,17))\n\naxes = axes.ravel() # flaten the 15 x 15 matrix into 225 array\n\nn_train = len(train) # get the length of the train dataset\n\n# Select a random number from 0 to n_train\nfor i in np.arange(0, W_grid * L_grid): # create evenly spaces variables \n\n    # Select a random number\n    index = np.random.randint(0, n_train)\n    # read and display an image with the selected index    \n    axes[i].imshow( train[index,1:].reshape((28,28)) )\n    label_index = int(train[index,0])\n    axes[i].set_title(class_names[label_index], fontsize=8)\n    axes[i].axis('off')\n\nplt.subplots_adjust(hspace=0.4)","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:47:48.206917Z","iopub.execute_input":"2024-05-16T05:47:48.207383Z","iopub.status.idle":"2024-05-16T05:48:22.747769Z","shell.execute_reply.started":"2024-05-16T05:47:48.207339Z","shell.execute_reply":"2024-05-16T05:48:22.744734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = train_df.drop(columns=[\"label\"])\ny_train = train_df[\"label\"]\nx_test = test_df\nprint(x_train.shape)\nprint(y_train.shape)\nprint(x_test.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:48:22.749229Z","iopub.execute_input":"2024-05-16T05:48:22.749960Z","iopub.status.idle":"2024-05-16T05:48:22.906778Z","shell.execute_reply.started":"2024-05-16T05:48:22.749897Z","shell.execute_reply":"2024-05-16T05:48:22.905256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_value_columns_indices = np.where(np.isnan(x_train).any(axis=0))[0]\n\nprint(\"NULL in columns indices:\", missing_value_columns_indices)","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:48:22.908234Z","iopub.execute_input":"2024-05-16T05:48:22.908552Z","iopub.status.idle":"2024-05-16T05:48:22.929118Z","shell.execute_reply.started":"2024-05-16T05:48:22.908524Z","shell.execute_reply":"2024-05-16T05:48:22.927705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train.to_numpy()\ny_train = y_train.to_numpy()\nx_test = x_test.to_numpy()\nprint(x_train[2])","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:48:22.931245Z","iopub.execute_input":"2024-05-16T05:48:22.931687Z","iopub.status.idle":"2024-05-16T05:48:22.941703Z","shell.execute_reply.started":"2024-05-16T05:48:22.931648Z","shell.execute_reply":"2024-05-16T05:48:22.940441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Create a new figure\nfig = plt.figure(figsize=(6, 6))\n\n# Loop over the first 30 samples in x_train\nfor i in range(30): \n    # Reshape the image data from flattened (784,) to (28, 28)\n    image = x_train[i].reshape(28, 28)\n    \n    # Add a subplot to the figure\n    ax = fig.add_subplot(6, 5, i + 1, xticks=[], yticks=[])\n    \n    # Display the image\n    ax.imshow(image, cmap=plt.cm.binary, interpolation='nearest')\n    \n    # Add text annotation with the label (y_train) for each image\n    ax.text(0, 7, str(y_train[i]))\n\n# Show the plot\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-05-16T05:55:20.770321Z","iopub.execute_input":"2024-05-16T05:55:20.770800Z","iopub.status.idle":"2024-05-16T05:55:24.566580Z","shell.execute_reply.started":"2024-05-16T05:55:20.770765Z","shell.execute_reply":"2024-05-16T05:55:24.564982Z"},"trusted":true},"execution_count":null,"outputs":[]}]}