{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","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":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Digit Recognizer\nhttps://www.kaggle.com/c/digit-recognizer","metadata":{}},{"cell_type":"code","source":"%matplotlib inline\nimport cv2\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:10:59.812785Z","iopub.execute_input":"2024-05-04T14:10:59.813223Z","iopub.status.idle":"2024-05-04T14:11:00.053337Z","shell.execute_reply.started":"2024-05-04T14:10:59.813189Z","shell.execute_reply":"2024-05-04T14:11:00.052363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Загружаем исходные данные","metadata":{}},{"cell_type":"code","source":"train = np.loadtxt('/kaggle/input/digit-recognizer/train.csv', delimiter=',', skiprows=1)\ntest = np.loadtxt('/kaggle/input/digit-recognizer/test.csv', delimiter=',', skiprows=1)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:02.888723Z","iopub.execute_input":"2024-05-04T14:11:02.889121Z","iopub.status.idle":"2024-05-04T14:11:09.351641Z","shell.execute_reply.started":"2024-05-04T14:11:02.889090Z","shell.execute_reply":"2024-05-04T14:11:09.350558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# сохраняем разметку в отдельную переменную\ntrain_label = train[:, 0]\ntest_label  = test[:,0]\n# приводим размерность к удобному для обаботки виду\ntrain_img = np.resize(train[:, 1:], (train.shape[0], 28, 28))\ntest_img = np.resize(test, (test.shape[0], 28, 28))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:36:50.182618Z","iopub.execute_input":"2024-05-04T14:36:50.183045Z","iopub.status.idle":"2024-05-04T14:36:50.510908Z","shell.execute_reply.started":"2024-05-04T14:36:50.183011Z","shell.execute_reply":"2024-05-04T14:36:50.509718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_img.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:09.685768Z","iopub.execute_input":"2024-05-04T14:11:09.686120Z","iopub.status.idle":"2024-05-04T14:11:09.694621Z","shell.execute_reply.started":"2024-05-04T14:11:09.686089Z","shell.execute_reply":"2024-05-04T14:11:09.693373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Визуализируем исходные данные","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(20, 10))\nfor i, img in enumerate(train_img[0:5], 1):\n    subplot = fig.add_subplot(1, 7, i)\n    plt.imshow(img, cmap='gray');\n    subplot.set_title('%s' % train_label[i - 1]);","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:09.697080Z","iopub.execute_input":"2024-05-04T14:11:09.697654Z","iopub.status.idle":"2024-05-04T14:11:10.755954Z","shell.execute_reply.started":"2024-05-04T14:11:09.697622Z","shell.execute_reply":"2024-05-04T14:11:10.754626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Вычисляем X и Y составляющие градиента с помощью оператора Собеля","metadata":{}},{"cell_type":"code","source":"train_sobel_x = np.zeros_like(train_img)\ntrain_sobel_y = np.zeros_like(train_img)\nfor i in range(len(train_img)):\n    train_sobel_x[i] = cv2.Sobel(train_img[i], cv2.CV_64F, dx=1, dy=0, ksize=3)\n    train_sobel_y[i] = cv2.Sobel(train_img[i], cv2.CV_64F, dx=0, dy=1, ksize=3)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:10.757591Z","iopub.execute_input":"2024-05-04T14:11:10.758015Z","iopub.status.idle":"2024-05-04T14:11:11.962108Z","shell.execute_reply.started":"2024-05-04T14:11:10.757981Z","shell.execute_reply":"2024-05-04T14:11:11.960963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_sobel_x = np.zeros_like(test_img)\ntest_sobel_y = np.zeros_like(test_img)\nfor i in range(len(test_img)):\n    test_sobel_x[i] = cv2.Sobel(test_img[i], cv2.CV_64F, dx=1, dy=0, ksize=3)\n    test_sobel_y[i] = cv2.Sobel(test_img[i], cv2.CV_64F, dx=0, dy=1, ksize=3)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:11.963489Z","iopub.execute_input":"2024-05-04T14:11:11.963801Z","iopub.status.idle":"2024-05-04T14:11:12.761105Z","shell.execute_reply.started":"2024-05-04T14:11:11.963773Z","shell.execute_reply":"2024-05-04T14:11:12.759917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Вычисляем угол и длину вектора градиента","metadata":{}},{"cell_type":"code","source":"train_g, train_theta = cv2.cartToPolar(train_sobel_x, train_sobel_y)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:12.762383Z","iopub.execute_input":"2024-05-04T14:11:12.762732Z","iopub.status.idle":"2024-05-04T14:11:13.079869Z","shell.execute_reply.started":"2024-05-04T14:11:12.762701Z","shell.execute_reply":"2024-05-04T14:11:13.078582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_g, test_theta = cv2.cartToPolar(test_sobel_x, test_sobel_y)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:13.082954Z","iopub.execute_input":"2024-05-04T14:11:13.083347Z","iopub.status.idle":"2024-05-04T14:11:13.292029Z","shell.execute_reply.started":"2024-05-04T14:11:13.083289Z","shell.execute_reply":"2024-05-04T14:11:13.290924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(20, 10))\nfor i, img in enumerate(train_g[:5], 1):\n    subplot = fig.add_subplot(1, 7, i)\n    plt.imshow(img, cmap='gray');\n    subplot.set_title('%s' % train_label[i - 1]);\n    subplot = fig.add_subplot(3, 7, i)\n    plt.hist(train_theta[i - 1].flatten(),\n             bins=16, weights=train_g[i - 1].flatten())","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:13.293584Z","iopub.execute_input":"2024-05-04T14:11:13.294111Z","iopub.status.idle":"2024-05-04T14:11:15.426912Z","shell.execute_reply.started":"2024-05-04T14:11:13.294064Z","shell.execute_reply":"2024-05-04T14:11:15.425741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Вычисляем гистограммы градиентов","metadata":{}},{"cell_type":"code","source":"# Гистограммы вычисляются с учетом длины вектора градиента\ntrain_hist = np.zeros((len(train_img), 16))\nfor i in range(len(train_img)):\n    hist, borders = np.histogram(train_theta[i],\n                                 bins=16,\n                                 range=(0., 2. * np.pi),\n                                 weights=train_g[i])\n    train_hist[i] = hist","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:15.428460Z","iopub.execute_input":"2024-05-04T14:11:15.428824Z","iopub.status.idle":"2024-05-04T14:11:21.163158Z","shell.execute_reply.started":"2024-05-04T14:11:15.428794Z","shell.execute_reply":"2024-05-04T14:11:21.161985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_hist = np.zeros((len(test_img), 16))\nfor i in range(len(test_img)):\n    hist, borders = np.histogram(test_theta[i],\n                                 bins=16,\n                                 range=(0., 2. * np.pi),\n                                 weights=test_g[i])\n    test_hist[i] = hist","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:21.164851Z","iopub.execute_input":"2024-05-04T14:11:21.165206Z","iopub.status.idle":"2024-05-04T14:11:24.978161Z","shell.execute_reply.started":"2024-05-04T14:11:21.165174Z","shell.execute_reply":"2024-05-04T14:11:24.977017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Нормируем вектор гистограммы","metadata":{}},{"cell_type":"code","source":"# По умолчанию используется L2 норма\ntrain_hist = train_hist / np.linalg.norm(train_hist, axis=1)[:, None]","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:24.979488Z","iopub.execute_input":"2024-05-04T14:11:24.979826Z","iopub.status.idle":"2024-05-04T14:11:24.990444Z","shell.execute_reply.started":"2024-05-04T14:11:24.979797Z","shell.execute_reply":"2024-05-04T14:11:24.989340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_hist = test_hist / np.linalg.norm(test_hist, axis=1)[:, None]","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:24.995545Z","iopub.execute_input":"2024-05-04T14:11:24.995978Z","iopub.status.idle":"2024-05-04T14:11:25.004340Z","shell.execute_reply.started":"2024-05-04T14:11:24.995941Z","shell.execute_reply":"2024-05-04T14:11:25.003346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Разбиваем выборку на обучение и валидацию","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\ny_train, y_val, x_train, x_val = train_test_split(\n    train_label, train_hist, test_size=0.2,\n    random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.005712Z","iopub.execute_input":"2024-05-04T14:11:25.006132Z","iopub.status.idle":"2024-05-04T14:11:25.021858Z","shell.execute_reply.started":"2024-05-04T14:11:25.006095Z","shell.execute_reply":"2024-05-04T14:11:25.020401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Вычисляем центроиды каждого из 10 классов","metadata":{}},{"cell_type":"code","source":"centroids = np.zeros((10, train_hist.shape[1]), dtype=np.float32)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.023340Z","iopub.execute_input":"2024-05-04T14:11:25.023688Z","iopub.status.idle":"2024-05-04T14:11:25.029169Z","shell.execute_reply.started":"2024-05-04T14:11:25.023660Z","shell.execute_reply":"2024-05-04T14:11:25.027863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(10):\n    centroids[i] = np.mean(x_train[y_train == i], axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.030690Z","iopub.execute_input":"2024-05-04T14:11:25.031031Z","iopub.status.idle":"2024-05-04T14:11:25.046327Z","shell.execute_reply.started":"2024-05-04T14:11:25.031002Z","shell.execute_reply":"2024-05-04T14:11:25.045085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Находим ближайший центройд для валидации","metadata":{}},{"cell_type":"code","source":"pred_val = np.zeros_like(y_val)\nfor i in range(len(y_val)):\n    distances = np.linalg.norm(centroids - x_val[i], axis=1)\n    pred_val[i] = np.argmin(distances)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.047875Z","iopub.execute_input":"2024-05-04T14:11:25.048238Z","iopub.status.idle":"2024-05-04T14:11:25.252489Z","shell.execute_reply.started":"2024-05-04T14:11:25.048207Z","shell.execute_reply":"2024-05-04T14:11:25.251239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Оцениваем качество решение на валидационной выборке","metadata":{}},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\nprint('Accuracy: %s' % accuracy_score(y_val, pred_val))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.253911Z","iopub.execute_input":"2024-05-04T14:11:25.254353Z","iopub.status.idle":"2024-05-04T14:11:25.262751Z","shell.execute_reply.started":"2024-05-04T14:11:25.254294Z","shell.execute_reply":"2024-05-04T14:11:25.261537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report\nprint(classification_report(y_val, pred_val))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.264995Z","iopub.execute_input":"2024-05-04T14:11:25.265449Z","iopub.status.idle":"2024-05-04T14:11:25.306812Z","shell.execute_reply.started":"2024-05-04T14:11:25.265416Z","shell.execute_reply":"2024-05-04T14:11:25.305708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix\nprint(confusion_matrix(y_val, pred_val))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.308348Z","iopub.execute_input":"2024-05-04T14:11:25.308791Z","iopub.status.idle":"2024-05-04T14:11:25.329706Z","shell.execute_reply.started":"2024-05-04T14:11:25.308748Z","shell.execute_reply":"2024-05-04T14:11:25.328553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Предсказания на тестовыйх данных","metadata":{}},{"cell_type":"code","source":"pred_test = np.zeros(len(test_img), np.uint8)\nfor i in range(len(test_img)):\n    distances = np.linalg.norm(centroids - test_hist[i], axis=1)\n    pred_test[i] = np.argmin(distances)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.331184Z","iopub.execute_input":"2024-05-04T14:11:25.331617Z","iopub.status.idle":"2024-05-04T14:11:25.916080Z","shell.execute_reply.started":"2024-05-04T14:11:25.331584Z","shell.execute_reply":"2024-05-04T14:11:25.914861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Визуализируем предсказания","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(20, 10))\nfor i, img in enumerate(test_img[0:5], 1):\n    subplot = fig.add_subplot(1, 7, i)\n    plt.imshow(img, cmap='gray');\n    subplot.set_title('%s' % pred_test[i - 1]);","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:25.917636Z","iopub.execute_input":"2024-05-04T14:11:25.918083Z","iopub.status.idle":"2024-05-04T14:11:26.992400Z","shell.execute_reply.started":"2024-05-04T14:11:25.918042Z","shell.execute_reply":"2024-05-04T14:11:26.991056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Домашнее задание - подбор модели","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:26.993941Z","iopub.execute_input":"2024-05-04T14:11:26.994330Z","iopub.status.idle":"2024-05-04T14:11:27.263508Z","shell.execute_reply.started":"2024-05-04T14:11:26.994271Z","shell.execute_reply":"2024-05-04T14:11:27.262524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DTC = DecisionTreeClassifier(max_depth =5)\nDTC.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:27.264960Z","iopub.execute_input":"2024-05-04T14:11:27.265366Z","iopub.status.idle":"2024-05-04T14:11:27.734218Z","shell.execute_reply.started":"2024-05-04T14:11:27.265328Z","shell.execute_reply":"2024-05-04T14:11:27.733095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_val=DTC.predict(x_val)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:27.738591Z","iopub.execute_input":"2024-05-04T14:11:27.738979Z","iopub.status.idle":"2024-05-04T14:11:27.746004Z","shell.execute_reply.started":"2024-05-04T14:11:27.738948Z","shell.execute_reply":"2024-05-04T14:11:27.744988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Accuracy: %s' % accuracy_score(y_val, pred_val))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:28.318848Z","iopub.execute_input":"2024-05-04T14:11:28.319231Z","iopub.status.idle":"2024-05-04T14:11:28.327262Z","shell.execute_reply.started":"2024-05-04T14:11:28.319201Z","shell.execute_reply":"2024-05-04T14:11:28.326118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RFC = RandomForestClassifier(n_estimators = 200, max_depth=5 )\nRFC.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:29.737399Z","iopub.execute_input":"2024-05-04T14:11:29.739790Z","iopub.status.idle":"2024-05-04T14:11:46.671012Z","shell.execute_reply.started":"2024-05-04T14:11:29.739733Z","shell.execute_reply":"2024-05-04T14:11:46.669829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_val=RFC.predict(x_val)\nprint('Accuracy: %s' % accuracy_score(y_val, pred_val))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:46.672992Z","iopub.execute_input":"2024-05-04T14:11:46.673370Z","iopub.status.idle":"2024-05-04T14:11:46.888487Z","shell.execute_reply.started":"2024-05-04T14:11:46.673339Z","shell.execute_reply":"2024-05-04T14:11:46.887379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import GridSearchCV","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:11:46.889901Z","iopub.execute_input":"2024-05-04T14:11:46.890249Z","iopub.status.idle":"2024-05-04T14:11:46.894980Z","shell.execute_reply.started":"2024-05-04T14:11:46.890219Z","shell.execute_reply":"2024-05-04T14:11:46.893862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"params = {'max_depth': [4, 6, 8, 10]}\n\ngs_model = RandomForestClassifier()","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:26:34.279205Z","iopub.execute_input":"2024-05-04T14:26:34.280031Z","iopub.status.idle":"2024-05-04T14:26:34.284998Z","shell.execute_reply.started":"2024-05-04T14:26:34.279992Z","shell.execute_reply":"2024-05-04T14:26:34.283865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GS = GridSearchCV(gs_model, params)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:26:35.128816Z","iopub.execute_input":"2024-05-04T14:26:35.129227Z","iopub.status.idle":"2024-05-04T14:26:35.134757Z","shell.execute_reply.started":"2024-05-04T14:26:35.129196Z","shell.execute_reply":"2024-05-04T14:26:35.133600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GS.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:26:37.522947Z","iopub.execute_input":"2024-05-04T14:26:37.523403Z","iopub.status.idle":"2024-05-04T14:29:41.724387Z","shell.execute_reply.started":"2024-05-04T14:26:37.523366Z","shell.execute_reply":"2024-05-04T14:29:41.723092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GS.best_params_","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:31:26.879432Z","iopub.execute_input":"2024-05-04T14:31:26.879850Z","iopub.status.idle":"2024-05-04T14:31:26.886620Z","shell.execute_reply.started":"2024-05-04T14:31:26.879820Z","shell.execute_reply":"2024-05-04T14:31:26.885525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GS.best_score_","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:31:42.605530Z","iopub.execute_input":"2024-05-04T14:31:42.605966Z","iopub.status.idle":"2024-05-04T14:31:42.613820Z","shell.execute_reply.started":"2024-05-04T14:31:42.605933Z","shell.execute_reply":"2024-05-04T14:31:42.612564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_val=GS.best_estimator_.predict(x_val)\nprint('Accuracy: %s' % accuracy_score(y_val, pred_val))","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:32:32.541247Z","iopub.execute_input":"2024-05-04T14:32:32.541695Z","iopub.status.idle":"2024-05-04T14:32:32.699193Z","shell.execute_reply.started":"2024-05-04T14:32:32.541661Z","shell.execute_reply":"2024-05-04T14:32:32.698115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test=GS.best_estimator_.predict(test_hist)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:46:08.659328Z","iopub.execute_input":"2024-05-04T14:46:08.659746Z","iopub.status.idle":"2024-05-04T14:46:09.122105Z","shell.execute_reply.started":"2024-05-04T14:46:08.659712Z","shell.execute_reply":"2024-05-04T14:46:09.121154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Готовим файл для отправки","metadata":{}},{"cell_type":"code","source":"import pandas as pd","metadata":{"execution":{"iopub.status.busy":"2024-05-04T14:56:18.824171Z","iopub.execute_input":"2024-05-04T14:56:18.824669Z","iopub.status.idle":"2024-05-04T14:56:19.223620Z","shell.execute_reply.started":"2024-05-04T14:56:18.824631Z","shell.execute_reply":"2024-05-04T14:56:19.222414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df1= pd.DataFrame(pred_test, columns=['Label'])\ndf2=pd.DataFrame(range(1,pred_test.shape[0]+1),columns=['ImageId'])\nresults = pd.concat([df2, df1],axis = 1)\nresults.Label = results.Label.astype(int)\nresults.to_csv(\"digit-recognizer.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T15:00:46.323125Z","iopub.execute_input":"2024-05-04T15:00:46.323571Z","iopub.status.idle":"2024-05-04T15:00:46.373956Z","shell.execute_reply.started":"2024-05-04T15:00:46.323535Z","shell.execute_reply":"2024-05-04T15:00:46.372905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results","metadata":{"execution":{"iopub.status.busy":"2024-05-04T15:00:50.255702Z","iopub.execute_input":"2024-05-04T15:00:50.256105Z","iopub.status.idle":"2024-05-04T15:00:50.268799Z","shell.execute_reply.started":"2024-05-04T15:00:50.256070Z","shell.execute_reply":"2024-05-04T15:00:50.267562Z"},"trusted":true},"execution_count":null,"outputs":[]}]}