{"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":"markdown","source":"Imma be a copycat\n\n> REF. \"A Simple CNN Model Beginner Guide !!!!!!\" by Pavan Sanagapati","metadata":{}},{"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-09T09:47:45.049340Z","iopub.execute_input":"2024-05-09T09:47:45.049790Z","iopub.status.idle":"2024-05-09T09:47:45.058127Z","shell.execute_reply.started":"2024-05-09T09:47:45.049761Z","shell.execute_reply":"2024-05-09T09:47:45.057193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport keras","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:45.061267Z","iopub.execute_input":"2024-05-09T09:47:45.061954Z","iopub.status.idle":"2024-05-09T09:47:45.075151Z","shell.execute_reply.started":"2024-05-09T09:47:45.061920Z","shell.execute_reply":"2024-05-09T09:47:45.073750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dec. train_df, test_df\ntrain_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-09T09:47:45.078521Z","iopub.execute_input":"2024-05-09T09:47:45.079154Z","iopub.status.idle":"2024-05-09T09:47:50.445947Z","shell.execute_reply.started":"2024-05-09T09:47:45.079105Z","shell.execute_reply":"2024-05-09T09:47:50.444589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:50.447755Z","iopub.execute_input":"2024-05-09T09:47:50.448140Z","iopub.status.idle":"2024-05-09T09:47:50.515296Z","shell.execute_reply.started":"2024-05-09T09:47:50.448111Z","shell.execute_reply":"2024-05-09T09:47:50.514157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#take a look at train_df, test_df\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:50.517063Z","iopub.execute_input":"2024-05-09T09:47:50.517403Z","iopub.status.idle":"2024-05-09T09:47:50.537763Z","shell.execute_reply.started":"2024-05-09T09:47:50.517378Z","shell.execute_reply":"2024-05-09T09:47:50.536353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:50.540914Z","iopub.execute_input":"2024-05-09T09:47:50.542102Z","iopub.status.idle":"2024-05-09T09:47:50.561096Z","shell.execute_reply.started":"2024-05-09T09:47:50.542068Z","shell.execute_reply":"2024-05-09T09:47:50.559924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"label  \ntrain_df -> exists  \ntest_df -> not exists (???)  \n\nIdk why,, whatever","metadata":{}},{"cell_type":"code","source":"# convert dataframes into numpy arrays fo float32 type\n# float32 => acceptable form for TF and KERAS\n\ntrain_data = np.array(train_df, dtype = 'float32')\ntest_data = np.array(test_df, dtype = 'float32')","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:50.562755Z","iopub.execute_input":"2024-05-09T09:47:50.563480Z","iopub.status.idle":"2024-05-09T09:47:50.813455Z","shell.execute_reply.started":"2024-05-09T09:47:50.563449Z","shell.execute_reply":"2024-05-09T09:47:50.811974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# present image data => 0 ~ 255\n# rescale image data to a range of 0 ~ 1\n\n# so, divide x_train & x_test by 255\n\nx_train = train_data[:, 1:] / 255\ny_train = train_data[:, 0]\n\nx_test = test_data[:,:] / 255","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:50.815044Z","iopub.execute_input":"2024-05-09T09:47:50.816112Z","iopub.status.idle":"2024-05-09T09:47:50.908844Z","shell.execute_reply.started":"2024-05-09T09:47:50.816065Z","shell.execute_reply":"2024-05-09T09:47:50.907678Z"},"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']\nplt.figure(figsize = (10,10)) # size : 10x10 square\n\nfor i in range(36): # print only 36 images\n    plt.subplot(6, 6, i+1) # set position of image in the present sequence\n    plt.xticks([]) # hide x-axis \n    plt.yticks([]) # hide y-axis\n    plt.grid(False) # hide grid\n    plt.imshow(x_train[i].reshape((28, 28))) # reshape 28x28 pixels\n    label_index = int(y_train[i]) # dec label index\n    plt.title(class_names[label_index]) # set class name of each image\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:50.910444Z","iopub.execute_input":"2024-05-09T09:47:50.910769Z","iopub.status.idle":"2024-05-09T09:47:52.573821Z","shell.execute_reply.started":"2024-05-09T09:47:50.910743Z","shell.execute_reply":"2024-05-09T09:47:52.572938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# NOT YET\nW_grid = 15\nL_grid = 15\n\nfig, axes = plt.subplots(L_grid, W_grid, figsize = (16,16))\naxes = axes.ravel() # flaten the 15 x 15 matrix into 225 array\nn_train = len(train_data) # 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_data[index,1:].reshape((28,28)) )\n    labelindex = int(train_data[index,0])\n    axes[i].set_title(class_names[labelindex], fontsize = 9)\n    axes[i].axis('off')\n\nplt.subplots_adjust(hspace=0.3)","metadata":{"execution":{"iopub.status.busy":"2024-05-09T09:47:52.575087Z","iopub.execute_input":"2024-05-09T09:47:52.576157Z"},"trusted":true},"execution_count":null,"outputs":[]}]}