{"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":"gpu","dataSources":[{"sourceId":77476,"databundleVersionId":8462666,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nprint(\"setup complete\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-15T13:35:34.598972Z","iopub.execute_input":"2024-05-15T13:35:34.599346Z","iopub.status.idle":"2024-05-15T13:35:36.768475Z","shell.execute_reply.started":"2024-05-15T13:35:34.599315Z","shell.execute_reply":"2024-05-15T13:35:36.767226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 0. Problem Analysis\n\nThe above problem is to produce a model that determines the type of clothing through photo data.\nThe types of clothing given in the question are as follows.\n\n\n| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n| T-shirt/top | Trouser | Pullover | Dress | Coat | Sandal | Shirt | Sneaker | Bag | Ankle Boot |\n\n\nThe data should be processed so that 10,000 test data can be divided into 10 types of clothing through 60,000 training data.","metadata":{}},{"cell_type":"markdown","source":"# 1. Data Analysis","metadata":{}},{"cell_type":"code","source":"train_data_filepath = \"/kaggle/input/2024-smarcle-ks-3-fashion-mnist2/train.csv\"\ntest_data_filepath = \"/kaggle/input/2024-smarcle-ks-3-fashion-mnist2/test.csv\"\n\ntrain_data = pd.read_csv(train_data_filepath)\ntest_data = pd.read_csv(test_data_filepath)\n\nprint(\"data setup complete\")","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:35:47.442844Z","iopub.execute_input":"2024-05-15T13:35:47.443609Z","iopub.status.idle":"2024-05-15T13:35:55.293670Z","shell.execute_reply.started":"2024-05-15T13:35:47.443573Z","shell.execute_reply":"2024-05-15T13:35:55.292528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_data.info())\nprint(test_data.info(),'\\n')\n\nprint(\"train_data_shape :\", train_data.shape)\nprint(\"test_data_shape :\", test_data.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:35:58.908585Z","iopub.execute_input":"2024-05-15T13:35:58.909744Z","iopub.status.idle":"2024-05-15T13:35:59.075781Z","shell.execute_reply.started":"2024-05-15T13:35:58.909698Z","shell.execute_reply":"2024-05-15T13:35:59.074590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:00.101152Z","iopub.execute_input":"2024-05-15T13:36:00.101481Z","iopub.status.idle":"2024-05-15T13:36:00.125615Z","shell.execute_reply.started":"2024-05-15T13:36:00.101455Z","shell.execute_reply":"2024-05-15T13:36:00.124757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:01.062028Z","iopub.execute_input":"2024-05-15T13:36:01.062398Z","iopub.status.idle":"2024-05-15T13:36:01.081858Z","shell.execute_reply.started":"2024-05-15T13:36:01.062365Z","shell.execute_reply":"2024-05-15T13:36:01.080841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's determine if there are any missing values in the data like the original data.","metadata":{}},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:02.348860Z","iopub.execute_input":"2024-05-15T13:36:02.349225Z","iopub.status.idle":"2024-05-15T13:36:02.392205Z","shell.execute_reply.started":"2024-05-15T13:36:02.349197Z","shell.execute_reply":"2024-05-15T13:36:02.391220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:03.190866Z","iopub.execute_input":"2024-05-15T13:36:03.191754Z","iopub.status.idle":"2024-05-15T13:36:03.206745Z","shell.execute_reply.started":"2024-05-15T13:36:03.191720Z","shell.execute_reply":"2024-05-15T13:36:03.205553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It shows that we don't have to deal with missing values.","metadata":{}},{"cell_type":"markdown","source":"# 2. Preprocessing\n\nTo handle a lot of data at once, the values of the data frames are stored in the form of individually manageable arrangements.\nIn machine learning, it is converted to a numpy array because it must be analyzed as numpy to speed up the operation.","metadata":{}},{"cell_type":"code","source":"train_data_np = np.array(train_data)\nx_train = train_data_np[:, 1:]\ny_train = train_data_np[:, 0]\n\ntest_data_np = np.array(test_data)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:04.736036Z","iopub.execute_input":"2024-05-15T13:36:04.736397Z","iopub.status.idle":"2024-05-15T13:36:04.893866Z","shell.execute_reply.started":"2024-05-15T13:36:04.736366Z","shell.execute_reply":"2024-05-15T13:36:04.892971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_data_np.shape)\nprint(x_train.shape)\nprint(y_train.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:06.233331Z","iopub.execute_input":"2024-05-15T13:36:06.233708Z","iopub.status.idle":"2024-05-15T13:36:06.239372Z","shell.execute_reply.started":"2024-05-15T13:36:06.233678Z","shell.execute_reply":"2024-05-15T13:36:06.238285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_data_np.shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:07.128938Z","iopub.execute_input":"2024-05-15T13:36:07.129307Z","iopub.status.idle":"2024-05-15T13:36:07.134880Z","shell.execute_reply.started":"2024-05-15T13:36:07.129278Z","shell.execute_reply":"2024-05-15T13:36:07.133901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3. Visualization\n\nSince it is difficult to analyze an image with data expressed in numbers, the data is converted into an image and confirmed.","metadata":{}},{"cell_type":"code","source":"label_dictionary = {0: 'T-shirt/top', 1:'Trouser',\n                    2: 'Pullover', 3: 'Dress', \n                    4: 'Coat', 5: 'Sandal', \n                    6: 'Shirt', 7: 'Sneaker', \n                    8: 'Bag', 9: 'Ankle Boot'}","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:08.420548Z","iopub.execute_input":"2024-05-15T13:36:08.420947Z","iopub.status.idle":"2024-05-15T13:36:08.426358Z","shell.execute_reply.started":"2024-05-15T13:36:08.420918Z","shell.execute_reply":"2024-05-15T13:36:08.425127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i = 109\nj = 338\nk = 5043","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:08.992494Z","iopub.execute_input":"2024-05-15T13:36:08.993020Z","iopub.status.idle":"2024-05-15T13:36:08.997849Z","shell.execute_reply.started":"2024-05-15T13:36:08.992980Z","shell.execute_reply":"2024-05-15T13:36:08.996854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Out of 60,000 data, let's output image data corresponding to indexes 109, 338, and 5043, respectively.","metadata":{}},{"cell_type":"code","source":"plt.imshow(x_train[i].reshape(28,28),cmap ='gray')\nplt.colorbar()\nplt.title('Label {}, {}'.format(y_train[i], label_dictionary[y_train[i]]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:10.800725Z","iopub.execute_input":"2024-05-15T13:36:10.801132Z","iopub.status.idle":"2024-05-15T13:36:11.132060Z","shell.execute_reply.started":"2024-05-15T13:36:10.801099Z","shell.execute_reply":"2024-05-15T13:36:11.131067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_train[j].reshape(28,28),cmap = 'gray')\nplt.colorbar()\nplt.title('Label {}, {}'.format(y_train[j], label_dictionary[y_train[j]]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:12.054776Z","iopub.execute_input":"2024-05-15T13:36:12.055626Z","iopub.status.idle":"2024-05-15T13:36:12.361341Z","shell.execute_reply.started":"2024-05-15T13:36:12.055594Z","shell.execute_reply":"2024-05-15T13:36:12.360363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_train[k].reshape(28,28), cmap='gray')\nplt.colorbar()\nplt.title('Label {}, {}'.format(y_train[k], label_dictionary[y_train[k]]))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:13.223180Z","iopub.execute_input":"2024-05-15T13:36:13.223563Z","iopub.status.idle":"2024-05-15T13:36:13.530071Z","shell.execute_reply.started":"2024-05-15T13:36:13.223531Z","shell.execute_reply":"2024-05-15T13:36:13.529129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In addition, nine images are output at once to check the corresponding image data.","metadata":{}},{"cell_type":"code","source":"for i in range(9):\n    plt.subplot(3, 3, i + 1)\n    plt.imshow(x_train[i].reshape(28,28))\n    plt.colorbar()\n    plt.title('Label {}, {}'.format(y_train[i], label_dictionary[y_train[i]]))\n    \nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:16.867872Z","iopub.execute_input":"2024-05-15T13:36:16.868235Z","iopub.status.idle":"2024-05-15T13:36:19.204998Z","shell.execute_reply.started":"2024-05-15T13:36:16.868205Z","shell.execute_reply":"2024-05-15T13:36:19.203945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. Data Scaling\n\nIn order to utilize CNN, data from 0 to 255 must be made from 0 to 1 to be used. Therefore, each data is divided by 255 to make it from 0 to 1.","metadata":{}},{"cell_type":"code","source":"# 특성 데이터 (X_train)와 레이블 데이터 (y_train) 분리\nX_train = train_data.drop('label', axis=1)  # 'label' 열 제외\nY_train = train_data['label']\n\nX_train = X_train.astype('float32') / 255.0\ntest_data = test_data.astype('float32') / 255.0\n\nprint(X_train)\nprint(test_data)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:21.055046Z","iopub.execute_input":"2024-05-15T13:36:21.055695Z","iopub.status.idle":"2024-05-15T13:36:21.405993Z","shell.execute_reply.started":"2024-05-15T13:36:21.055659Z","shell.execute_reply":"2024-05-15T13:36:21.404865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\n\npca = PCA(n_components=0.9)\npca.fit(X_train)\n\nX_train_transformed = pca.transform(X_train)\ntest_transformed = pca.transform(test_data)\n\nvar = np.var(X_train_transformed, axis=0)\ntotal_var = np.sum(var)\ncum_var = np.cumsum(var)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:22.264128Z","iopub.execute_input":"2024-05-15T13:36:22.265206Z","iopub.status.idle":"2024-05-15T13:36:30.741811Z","shell.execute_reply.started":"2024-05-15T13:36:22.265165Z","shell.execute_reply":"2024-05-15T13:36:30.740170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"누적 분산:\")\nfor i, v in enumerate(cum_var):\n    print(f\"{i + 1}번째 주성분: {v / total_var:.2f}\")","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:30.743883Z","iopub.execute_input":"2024-05-15T13:36:30.747693Z","iopub.status.idle":"2024-05-15T13:36:30.755723Z","shell.execute_reply.started":"2024-05-15T13:36:30.747632Z","shell.execute_reply":"2024-05-15T13:36:30.754561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 누적 분산 계산\nvar = np.var(X_train_transformed, axis=0)\ntotal_var = np.sum(var)\ncum_var = np.cumsum(var)\n\n# 스크립트 플롯 생성\nplt.plot(cum_var / total_var)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:36:46.091232Z","iopub.execute_input":"2024-05-15T13:36:46.091843Z","iopub.status.idle":"2024-05-15T13:36:46.305757Z","shell.execute_reply.started":"2024-05-15T13:36:46.091811Z","shell.execute_reply":"2024-05-15T13:36:46.304734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"x축 : 주성분 / y축 : 누적 분산 비율","metadata":{}},{"cell_type":"markdown","source":"# 5. Modeling","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.utils import to_categorical\nfrom sklearn.model_selection import train_test_split\n\n\nX_train_np, X_val_np, Y_train_np, Y_val_np = train_test_split(x_train, y_train, test_size=0.2, random_state=42)\n\nprint(X_train_np.shape)\nprint(Y_train_np.shape)\n\n\n# 데이터 정규화\nX_train_np = X_train_np.astype('float32') / 255.0\nX_val_np = X_val_np.astype('float32') / 255.0\nX_train_np = np.reshape(X_train_np, (-1, 28, 28, 1))\nX_val_np = np.reshape(X_val_np, (-1, 28, 28, 1))\n\n\n# 이미지 크기 조정 (VGG16 입력 크기: 32x32)\nX_train_np = tf.image.resize(X_train_np, [32, 32])\nX_val_np = tf.image.resize(X_val_np, [32, 32])\n\n# 채널 추가 (흑백 이미지 -> 3채널)\n#X_train_np = tf.expand_dims(X_train_np, -1)\nX_train_np = tf.repeat(X_train_np, 3, axis=-1)\n#X_val_np = tf.expand_dims(X_val_np, -1)\nX_val_np = tf.repeat(X_val_np, 3, axis=-1)\n\n# 레이블 원-핫 인코딩\nY_train_np = to_categorical(Y_train_np, 10)\nY_val_np = to_categorical(Y_val_np, 10)\n\nprint(X_train_np.shape)\nprint(Y_train_np.shape)\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-05-15T13:36:48.807419Z","iopub.execute_input":"2024-05-15T13:36:48.807849Z","iopub.status.idle":"2024-05-15T13:37:02.840420Z","shell.execute_reply.started":"2024-05-15T13:36:48.807808Z","shell.execute_reply":"2024-05-15T13:37:02.839357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import VGG16\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Flatten, Dense, Dropout\nfrom tensorflow.keras.callbacks import EarlyStopping\n\n# VGG16 모델 불러오기 (ImageNet 가중치 포함, 분류 레이어 제외)\nbase_model = VGG16(weights='imagenet', include_top=False, input_shape=(32, 32, 3))\n\n# VGG16 모델 고정 (가중치 업데이트 방지)\nbase_model.trainable = False\n\n# 모델 생성\nmodel = Sequential([\n    base_model,  # VGG16 모델\n    Flatten(),  # 1차원 벡터로 변환\n    Dense(512, activation='relu'),  # 은닉층\n    Dropout(0.5),  # 과적합 방지\n    Dense(10, activation='softmax')  # 출력층 (10개 클래스)\n])\n\n# 모델 컴파일\nmodel.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n\n# EarlyStopping 콜백 설정\nearly_stopping = EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True)\n\n# 모델 학습\nmodel.fit(X_train_np, Y_train_np, epochs=10, batch_size=32, validation_data=(X_val_np, Y_val_np), callbacks=[early_stopping])","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:37:04.570606Z","iopub.execute_input":"2024-05-15T13:37:04.571925Z","iopub.status.idle":"2024-05-15T13:38:54.075661Z","shell.execute_reply.started":"2024-05-15T13:37:04.571884Z","shell.execute_reply":"2024-05-15T13:38:54.074752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import ResNet50\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import GlobalAveragePooling2D, Dense\nfrom tensorflow.keras.optimizers import Adam\n\n# ResNet50 모델 로드 (ImageNet 가중치 사용, 완전 연결 레이어 제외)\nbase_model_ResNet = ResNet50(weights='imagenet', include_top=False, input_shape=(32, 32, 3))\n\n# 모델 동결 (사전 학습된 가중치 유지)\nbase_model_ResNet.trainable = False\n\n# 새로운 모델 생성\nmodel_ResNet = Sequential([\n    base_model_ResNet,\n    GlobalAveragePooling2D(),  # 특징 맵 평균화\n    Dense(128, activation='relu'),  # 추가적인 은닉층 (필요에 따라 조절)\n    Dense(10, activation='softmax')  # 출력층 (클래스 개수에 맞춰 수정)\n])\n\n# 모델 컴파일\nmodel_ResNet.compile(optimizer=Adam(learning_rate=0.001),  # 학습률 조절 가능\n              loss='categorical_crossentropy',\n              metrics=['accuracy'])\n\n# 모델 학습\nmodel_ResNet.fit(X_train_np, Y_train_np, epochs=10, validation_data=(X_val_np, Y_val_np))","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:38:59.600103Z","iopub.execute_input":"2024-05-15T13:38:59.601155Z","iopub.status.idle":"2024-05-15T13:41:59.070622Z","shell.execute_reply.started":"2024-05-15T13:38:59.601117Z","shell.execute_reply":"2024-05-15T13:41:59.069538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Select VGG16 Model!!","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.applications import VGG16\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Flatten, Dense, Dropout\nfrom tensorflow.keras.callbacks import EarlyStopping\nfrom kerastuner.tuners import RandomSearch\n\n# 모델 생성 함수 (Keras Tuner용)\ndef build_model(hp):\n    base_model = VGG16(weights='imagenet', include_top=False, input_shape=(32, 32, 3))\n    base_model.trainable = False\n\n    model = Sequential([\n        base_model,\n        Flatten(),\n        Dense(units=hp.Int('units', min_value=32, max_value=512, step=32), activation='relu'),\n        Dropout(rate=hp.Float('dropout', min_value=0.0, max_value=0.5, step=0.1)),\n        Dense(10, activation='softmax')\n    ])\n\n    model.compile(optimizer=tf.keras.optimizers.Adam(hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])),\n                  loss='categorical_crossentropy',\n                  metrics=['accuracy'])\n    \n    return model\n\n# Keras Tuner 설정 (RandomSearch)\ntuner = RandomSearch(\n    build_model,\n    objective='val_accuracy',\n    max_trials=5,  # 튜닝 횟수\n    directory='vgg16_tuning',\n    project_name='vgg16_hyperparameter_search'\n)\n\n# EarlyStopping 콜백 설정\nearly_stopping = EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True)\n\n# 하이퍼파라미터 탐색\ntuner.search(X_train_np, Y_train_np, epochs=10, validation_data=(X_val_np, Y_val_np), callbacks=[early_stopping])\n\n# 최적의 하이퍼파라미터 및 모델 가져오기\nbest_hps = tuner.get_best_hyperparameters(num_trials=1)[0]\nmodel = tuner.hypermodel.build(best_hps)\n\n# 모델 학습 (최적 하이퍼파라미터 사용)\nmodel.fit(X_train_np, Y_train_np, epochs=10, batch_size=32, validation_data=(X_val_np, Y_val_np), callbacks=[early_stopping])","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:42:14.962167Z","iopub.execute_input":"2024-05-15T13:42:14.963008Z","iopub.status.idle":"2024-05-15T13:53:02.229234Z","shell.execute_reply.started":"2024-05-15T13:42:14.962974Z","shell.execute_reply":"2024-05-15T13:53:02.228137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 데이터 정규화\ntest_data_np = test_data_np.astype('float32') / 255.0\ntest_data_np = np.reshape(test_data_np, (-1, 28, 28, 1))\n\n\n# 이미지 크기 조정 (VGG16 입력 크기: 32x32)\ntest_data_np = tf.image.resize(test_data_np, [32, 32])\n\n# 채널 추가 (흑백 이미지 -> 3채널)\ntest_data_np = tf.repeat(test_data_np, 3, axis=-1)\n\npredictions = model.predict(test_data_np)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:55:46.203128Z","iopub.execute_input":"2024-05-15T13:55:46.203545Z","iopub.status.idle":"2024-05-15T13:55:50.370041Z","shell.execute_reply.started":"2024-05-15T13:55:46.203513Z","shell.execute_reply":"2024-05-15T13:55:50.369041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:55:53.924474Z","iopub.execute_input":"2024-05-15T13:55:53.924867Z","iopub.status.idle":"2024-05-15T13:55:53.932980Z","shell.execute_reply.started":"2024-05-15T13:55:53.924837Z","shell.execute_reply":"2024-05-15T13:55:53.931981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = np.argmax(predictions, axis=1)\n\npredictions.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:56:31.605263Z","iopub.execute_input":"2024-05-15T13:56:31.605623Z","iopub.status.idle":"2024-05-15T13:56:31.613716Z","shell.execute_reply.started":"2024-05-15T13:56:31.605593Z","shell.execute_reply":"2024-05-15T13:56:31.612461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_to_output = pd.read_csv(\"/kaggle/input/2024-smarcle-ks-3-fashion-mnist2/sample_submission.csv\")\nsample_to_output[\"label\"] = predictions\nsample_to_output.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-15T13:57:51.391130Z","iopub.execute_input":"2024-05-15T13:57:51.391937Z","iopub.status.idle":"2024-05-15T13:57:51.427963Z","shell.execute_reply.started":"2024-05-15T13:57:51.391894Z","shell.execute_reply":"2024-05-15T13:57:51.426843Z"},"trusted":true},"execution_count":null,"outputs":[]}]}