{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"pip install imutils\n","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:45:55.437259Z","iopub.execute_input":"2022-06-12T10:45:55.437844Z","iopub.status.idle":"2022-06-12T10:46:08.827561Z","shell.execute_reply.started":"2022-06-12T10:45:55.437735Z","shell.execute_reply":"2022-06-12T10:46:08.826596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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)\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.model_selection import train_test_split\n#from imutils import paths\nimport numpy as np\nimport argparse\n#import imutils\nimport cv2\nimport os\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Flatten, Dropout, Activation, Conv2D, MaxPooling2D\nimport imutils\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\n\n# imutils library, a package was created  to store common computer vision processing functions\n#https://pyimagesearch.com/2016/08/08/k-nn-classifier-for-image-classification/#pyis-cta-modal\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 #Ce module fournit une façon portable d'utiliser les fonctionnalités dépendantes du système d'exploitation.\nfor dirname, _, filenames in os.walk('/kaggle/input'): #os.walk Génère les noms de fichier dans un arbre de répertoire en parcourant l'arbre soit de bas-en-haut, soit de haut-en-bas.\n    for filename in filenames:  # 3 : sample/test/train\n        print(os.path.join(dirname, filename)) # il peut être converti en chemin absolu en utilisant os.path.join(os.path.dirname(path), result).\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":"2022-06-12T10:46:08.830082Z","iopub.execute_input":"2022-06-12T10:46:08.830411Z","iopub.status.idle":"2022-06-12T10:46:15.519187Z","shell.execute_reply.started":"2022-06-12T10:46:08.830369Z","shell.execute_reply":"2022-06-12T10:46:15.517355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"print(os.listdir(\"../input\"))\n#for extration\nimport zipfile\n\nwith zipfile.ZipFile(\"../input/dogs-vs-cats-redux-kernels-edition/train.zip\",\"r\") as z:\n    z.extractall(\".\")\n    \nwith zipfile.ZipFile(\"../input/dogs-vs-cats-redux-kernels-edition/test.zip\",\"r\") as z:\n    z.extractall(\".\")","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:15.524556Z","iopub.execute_input":"2022-06-12T10:46:15.526888Z","iopub.status.idle":"2022-06-12T10:46:36.176004Z","shell.execute_reply.started":"2022-06-12T10:46:15.526842Z","shell.execute_reply":"2022-06-12T10:46:36.175129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import imutils","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.180370Z","iopub.execute_input":"2022-06-12T10:46:36.181882Z","iopub.status.idle":"2022-06-12T10:46:36.186668Z","shell.execute_reply.started":"2022-06-12T10:46:36.181834Z","shell.execute_reply":"2022-06-12T10:46:36.185766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"main_dir = \"/kaggle/working/\"\ntrain_dir = \"train\"\npath=os.path.join(main_dir,train_dir) ## kolna pour generer un chemin absolue \n                                    ##'/kaggle/working/train'  fehom tsawer\nos.listdir(path)\nfor p in os.listdir(path):\n    # os.listdir Return a list containing the names of the entries in the directory given by path. \n    category=p.split(\".\")[0] # dog or cat \n    img_array = cv2.imread(os.path.join(path,p),cv2.IMREAD_GRAYSCALE) #imread(path,flag) / method loads an image from the specified file\n    new_img_array=cv2.resize(img_array,dsize=(80,80))\n    L=cv2.resize(img_array,dsize=(80,80)).flatten()\n    # displaying the image \n    plt.imshow(new_img_array,cmap='gray')# or cv2.imshow('new_img_array', img)\n \n    break # we displayed juste one pic\n","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.189060Z","iopub.execute_input":"2022-06-12T10:46:36.189480Z","iopub.status.idle":"2022-06-12T10:46:36.533419Z","shell.execute_reply.started":"2022-06-12T10:46:36.189437Z","shell.execute_reply":"2022-06-12T10:46:36.532660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#mtaa lflatten L #ta nraja nefhem akther  array([ 84,  86,  86, ...,  93, 128, 143], dtype=uint8)","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.535817Z","iopub.execute_input":"2022-06-12T10:46:36.536268Z","iopub.status.idle":"2022-06-12T10:46:36.540344Z","shell.execute_reply.started":"2022-06-12T10:46:36.536226Z","shell.execute_reply":"2022-06-12T10:46:36.539000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Defining two methods to take an input image and convert it to a feature vector","metadata":{}},{"cell_type":"markdown","source":"### 1st method","metadata":{}},{"cell_type":"code","source":"def image_to_feature_vector(image, size=(32, 32)):\n    \n# resize the image to a fixed size, then flatten the image into\n#a list of raw pixel intensities\n   return cv2.resize(image, size).flatten()\n# resizes it to a fixed width and height (size ), \n#and then flattens (aplatir)the RGB pixel intensities into a single list of numbers.","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.541895Z","iopub.execute_input":"2022-06-12T10:46:36.542394Z","iopub.status.idle":"2022-06-12T10:46:36.550084Z","shell.execute_reply.started":"2022-06-12T10:46:36.542345Z","shell.execute_reply":"2022-06-12T10:46:36.549165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2nd method ","metadata":{}},{"cell_type":"markdown","source":"As the name suggests, this function accepts an input image and constructs a color histogram to characterize the color distribution of the image.\nI didn't use it ","metadata":{}},{"cell_type":"code","source":"def extract_color_histogram(image, bins=(8, 8, 8)):\n    \n# extract a 3D color histogram from the HSV color space using\n# the supplied number of `bins` per channel\n    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) #First, we convert our image to the HSV color space\n    hist = cv2.calcHist([hsv], [0, 1, 2], None, bins,[0, 180, 0, 256, 0, 256]) #We then apply the cv2.calcHist function to compute a 3D color histogram for the image\n# handle normalizing the histogram if we are using OpenCV 2.4.X\n    if imutils.is_cv2():\n        hist = cv2.normalize(hist)\n# otherwise, perform \"in place\" normalization in OpenCV 3 (I\n# personally hate the way this is done\n    else:\n        cv2.normalize(hist, hist) #Given our computed hist , we then normalize it,\n# return the flattened histogram as the feature vector\n    return hist.flatten()","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.553584Z","iopub.execute_input":"2022-06-12T10:46:36.554031Z","iopub.status.idle":"2022-06-12T10:46:36.562735Z","shell.execute_reply.started":"2022-06-12T10:46:36.553998Z","shell.execute_reply":"2022-06-12T10:46:36.561595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"HSL (for hue, saturation, lightness) and HSV (for hue, saturation, value) are alternative representations of the RGB color model","metadata":{}},{"cell_type":"code","source":"from imutils import paths","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.564240Z","iopub.execute_input":"2022-06-12T10:46:36.564678Z","iopub.status.idle":"2022-06-12T10:46:36.574535Z","shell.execute_reply.started":"2022-06-12T10:46:36.564631Z","shell.execute_reply":"2022-06-12T10:46:36.573667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# grab the list of images that we'll be describing\nprint(\"[INFO] describing images...\")\ndataset =           \"/kaggle/working/train\"    #\"../input/train/train/\"\nimagePaths = list(paths.list_images(dataset)) #i'll be returning to understand this args[\"dataset\"]\n#imagePaths=['/kaggle/working/train/cat.1880.jpg','/kaggle/working/train/cat.4671.jpg'................\n# initialize the raw pixel intensities matrix, the features matrix,\n# and labels list\nprint(len(imagePaths))\nrawImages = []\n#features = []\nlabels = []\n","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.579050Z","iopub.execute_input":"2022-06-12T10:46:36.579329Z","iopub.status.idle":"2022-06-12T10:46:36.686360Z","shell.execute_reply.started":"2022-06-12T10:46:36.579301Z","shell.execute_reply":"2022-06-12T10:46:36.685589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# loop over the input images\nfor (i, imagePath) in enumerate(imagePaths):\n# load the image and extract the class label (assuming that our\n# path as the format: /path/to/dataset/{class}.{image_num}.jpg\n    image = cv2.imread(imagePath) # ok \n    label = imagePath.split(os.path.sep)[-1].split(\".\")[0]\n# extract raw pixel intensity \"features\", followed by a color\n# histogram to characterize the color distribution of the pixels\n# in the image\n    pixels = image_to_feature_vector(image)\n   # hist = extract_color_histogram(image)\n# update the raw images, features, and labels matricies,\n# respectively\n    rawImages.append(pixels) #rawImages : liste de liste des pixels de chaque image\n   # features.append(hist)\n    labels.append(label)\n# show an update every 1,000 images\n    if i > 0 and i % 1000 == 0:\n        print(\"[INFO] processed {}/{}\".format(i, len(imagePaths)))","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:46:36.687576Z","iopub.execute_input":"2022-06-12T10:46:36.688461Z","iopub.status.idle":"2022-06-12T10:47:32.604329Z","shell.execute_reply.started":"2022-06-12T10:46:36.688417Z","shell.execute_reply":"2022-06-12T10:47:32.603174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show some information on the memory consumed by the raw images\n# matrix and features matrix\nrawImages = np.array(rawImages) #every row is an image \n#features = np.array(features)\nlabels = np.array(labels)#size (n,1)\nprint(\"[INFO] pixels matrix: {:.2f}MB\".format(\nrawImages.nbytes / (1024 * 1000.0))) #en principe /1024/1024\n#print(\"[INFO] features matrix: {:.2f}MB\".format(\n#features.nbytes / (1024 * 1000.0)))\n#labels \n","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:47:32.605969Z","iopub.execute_input":"2022-06-12T10:47:32.606464Z","iopub.status.idle":"2022-06-12T10:47:32.706767Z","shell.execute_reply.started":"2022-06-12T10:47:32.606417Z","shell.execute_reply":"2022-06-12T10:47:32.699915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# partition the data into training and testing splits, using 75%\n# of the data for training and the remaining 25% for testing\n#syntax : X_train, X_test, y_train, y_test\n(trainRI, testRI, trainRL, testRL) = train_test_split(rawImages, labels, test_size=0.25, random_state=42)\n#(trainFeat, testFeat, trainLabels, testLabels) = train_test_split(features, labels, test_size=0.25, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:47:32.708143Z","iopub.execute_input":"2022-06-12T10:47:32.708515Z","iopub.status.idle":"2022-06-12T10:47:32.742240Z","shell.execute_reply.started":"2022-06-12T10:47:32.708472Z","shell.execute_reply":"2022-06-12T10:47:32.741378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# train and evaluate a k-NN classifer on the raw pixel intensities\nprint(\"[INFO] evaluating raw pixel accuracy...\")\nmodel = KNeighborsClassifier(n_neighbors=5,p=2) #p = 2 is for the standard euclidean metric ; by defaut it's p=2\nmodel.fit(trainRI, trainRL) \nacc = model.score(testRI, testRL)  # feha predict mbaed yikaren b test zaama?\nprint(\"[INFO] raw pixel accuracy: {:.2f}%\".format(acc * 100))","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:53:30.450268Z","iopub.execute_input":"2022-06-12T10:53:30.450546Z","iopub.status.idle":"2022-06-12T10:53:46.984902Z","shell.execute_reply.started":"2022-06-12T10:53:30.450507Z","shell.execute_reply":"2022-06-12T10:53:46.983963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train and evaluate a k-NN classifer on the raw pixel intensities\nprint(\"[INFO] evaluating raw pixel accuracy...\")\nmodel = KNeighborsClassifier(n_neighbors=5,p=1) #p = 1 is for manhattan_distance (l1)\nmodel.fit(trainRI, trainRL) #l'input : liste de liste des pixels de chaque image\nacc = model.score(testRI, testRL) # feha predict mbaed yikaren b test zaama?\nprint(\"[INFO] raw pixel accuracy: {:.2f}%\".format(acc * 100)) ","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:47:49.840757Z","iopub.execute_input":"2022-06-12T10:47:49.841263Z","iopub.status.idle":"2022-06-12T10:53:30.449007Z","shell.execute_reply.started":"2022-06-12T10:47:49.841222Z","shell.execute_reply":"2022-06-12T10:53:30.447233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"A question was asked in a course in stanford university \n    Where L1 distance might be preferable to using L2 distance?\nthe response was :\n    I think it's mainly problem-dependent, it’s sort of difficult to say in which cases you think one might be better than the other. but I think that because L1 has this sort of coordinate dependency, it actually depends on the coordinate system of your data,\nif you know that you have a vector, and maybe the individual elements of the vector have meaning. Like maybe you're classifying employees for some reason and then the different elements of that vector correspond to different features or aspects of an employee. Like their salary or the number of years they've been working at the company or something like that. So I think when your individual elements actually have some meaning, is where I think maybe using L1 might make a little bit more sense. But in general, again, this is a hyperparameter\n#### and it really depends on your problem and your data so the best answer is just to try them both and see what works better. \n","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"it's missing the use of cross validation and setting the hyperparameters and i want to seethe decision boundriesmtaa k-NN ","metadata":{}},{"cell_type":"markdown","source":"this was from #https://pyimagesearch.com/2016/08/08/k-nn-classifier-for-image-classification/#pyis-cta-modal modified","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"X=[]\ny=[]\nconvert=lambda category:int(category=='dog')\nfor p in os.listdir(path):\n    category=p.split('.')[0]\n    category=convert(category)\n    img_array= cv2.imread(os.path.join(path,p),cv2.IMREAD_GRAYSCALE)\n    new_img_array=cv2.resize(img_array,dsize=(80,80))\n    X.append(new_img_array)\n    y.append(category)\n    ","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:53:46.990262Z","iopub.execute_input":"2022-06-12T10:53:46.992971Z","iopub.status.idle":"2022-06-12T10:54:13.116572Z","shell.execute_reply.started":"2022-06-12T10:53:46.992929Z","shell.execute_reply":"2022-06-12T10:54:13.115760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = np.array(X).reshape(-1, 80,80,1)\ny = np.array(y)","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:54:13.118107Z","iopub.execute_input":"2022-06-12T10:54:13.118379Z","iopub.status.idle":"2022-06-12T10:54:13.200208Z","shell.execute_reply.started":"2022-06-12T10:54:13.118344Z","shell.execute_reply":"2022-06-12T10:54:13.199364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We devide our training array toi 255 in order to make our model learn faster and more effecient .It's called scaling the training data ","metadata":{}},{"cell_type":"code","source":"X=X/255.0","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:54:13.201746Z","iopub.execute_input":"2022-06-12T10:54:13.202030Z","iopub.status.idle":"2022-06-12T10:54:13.625412Z","shell.execute_reply.started":"2022-06-12T10:54:13.201993Z","shell.execute_reply":"2022-06-12T10:54:13.624614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now let's pass to training our model following these steps \n\nDefine a Sequential model\nStart adding layers to it.\nFirst we will add a Conv2D layer with 64 nodes and kernel size of (3,3). You can also experiment with different values here like 32, 128 etc. Also we have to specify input shape which is your X shape. Activation we will take 'relu' for now however there are many others to experiment with.\nNow after every Conv layer we always do max pooling so we will add max pooling layer with a size of (2,2)\nWe will repeat this combination again because come on 2 is better than one. Haha. We you can also add 3 or more convolution layers but keep in mind the more layers you add more time it will take to train.\nBut we don't have much time so we will add a flatten layer now. As we have to feed our data to Dense layer later.\nWe will now add a Dense layer of 64 nodes. Note for all these layers we are using activation as 'relu' because I found results better with this. You can skip specifying activation but this might make a model a conveniently linear which might not work for us.\nIn the end for getting our result we will add final Dense layer . Activation can be sigmoid or softmax (if you need probability use sigmoid else use softmax). Here I have used sigmoid.\nFinally we will compile the model . There are 3 things to mention here . Loss, Optimizer, Metrics\nLoss :- To make our model better we either minimize loss or maximize accuracy. NN always minimize loss. To measure it we can use different formulas like 'categorical_crossentropy' or 'binary_crossentropy'. Here I have used binary_crossentropy\n\nOptimizer :- If you know a lil bit about mathematics of machine learning you might be familier with local minima or global minima or cost function. To minimize cost function we use different methods For ex :- like gradient descent, stochastic gradient descent. So these are call optimizers. We are using a default one here which is adam\n\nMetrics :- This is to denote the measure of your model. Can be accuracy or some other metric.","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\n\nmodel.add(Conv2D(64,(3,3),activation='relu',input_shape=X.shape[1:]))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\n#add another\nmodel.add(Conv2D(64,(3,3),activation='relu',input_shape=X.shape[1:]))\nmodel.add(MaxPooling2D(pool_size=(2,2)))\n\nmodel.add(Flatten())\nmodel.add(Dense(64,activation='relu'))\n#Add a softmax layer with 10 output units\nmodel.add(Dense(1,activation='sigmoid'))\n\n\nmodel.compile(optimizer=\"adam\",loss=\"binary_crossentropy\",metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:54:13.626805Z","iopub.execute_input":"2022-06-12T10:54:13.627079Z","iopub.status.idle":"2022-06-12T10:54:16.194546Z","shell.execute_reply.started":"2022-06-12T10:54:13.627044Z","shell.execute_reply":"2022-06-12T10:54:16.193761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"now we will fit our model to the training data \nepochs is how many times we train our model \nthe more epochs we have the better result we will get \nbut 10 epochs is enought because it takes too long to run \nBatch size :- How much amount of data at once you wanna pass through the model\n\nvalidation_split :- How much amount of data (in this case its 20 %) you will need to check cross validation error\n\n","metadata":{}},{"cell_type":"code","source":"model.fit(X,y,epochs=10,batch_size=32,validation_split=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:54:16.196043Z","iopub.execute_input":"2022-06-12T10:54:16.196503Z","iopub.status.idle":"2022-06-12T10:55:08.668355Z","shell.execute_reply.started":"2022-06-12T10:54:16.196463Z","shell.execute_reply":"2022-06-12T10:55:08.667575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now we have to preprocess our test data also same as that our training data.","metadata":{}},{"cell_type":"code","source":"train_dir='test'\npath=os.path.join(main_dir,train_dir)\n\n\nX_test=[]\nid_line=[]\ndef create_test1_data(path):\n    for p in os.listdir(path):\n        id_line.append(p.split(\".\")[0])\n        img_array=cv2.imread(os.path.join(path,p),cv2.IMREAD_GRAYSCALE)\n        new_img_array=cv2.resize(img_array,dsize=(80,80))\n        X_test.append(new_img_array)\n        \ncreate_test1_data(path)\nX_test = np.array(X_test).reshape(-1,80,80,1)\nX_test = X_test/255        \n        ","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:55:08.669801Z","iopub.execute_input":"2022-06-12T10:55:08.670161Z","iopub.status.idle":"2022-06-12T10:55:22.425404Z","shell.execute_reply.started":"2022-06-12T10:55:08.670113Z","shell.execute_reply":"2022-06-12T10:55:22.424560Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions=model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:55:22.426661Z","iopub.execute_input":"2022-06-12T10:55:22.426958Z","iopub.status.idle":"2022-06-12T10:55:23.930008Z","shell.execute_reply.started":"2022-06-12T10:55:22.426921Z","shell.execute_reply":"2022-06-12T10:55:23.929152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_val = [int(round(p[0])) for p in predictions]","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:55:23.931746Z","iopub.execute_input":"2022-06-12T10:55:23.932021Z","iopub.status.idle":"2022-06-12T10:55:23.969584Z","shell.execute_reply.started":"2022-06-12T10:55:23.931984Z","shell.execute_reply":"2022-06-12T10:55:23.968894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now you have to make submission data frame to submit your resultset","metadata":{}},{"cell_type":"code","source":"submission_df=pd.DataFrame({'id':id_line,'label':predicted_val})","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:55:23.970845Z","iopub.execute_input":"2022-06-12T10:55:23.971197Z","iopub.status.idle":"2022-06-12T10:55:23.985584Z","shell.execute_reply.started":"2022-06-12T10:55:23.971157Z","shell.execute_reply":"2022-06-12T10:55:23.984605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:55:23.987358Z","iopub.execute_input":"2022-06-12T10:55:23.987758Z","iopub.status.idle":"2022-06-12T10:55:24.022667Z","shell.execute_reply.started":"2022-06-12T10:55:23.987694Z","shell.execute_reply":"2022-06-12T10:55:24.021344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df","metadata":{"execution":{"iopub.status.busy":"2022-06-12T10:55:24.024260Z","iopub.execute_input":"2022-06-12T10:55:24.024546Z","iopub.status.idle":"2022-06-12T10:55:24.041380Z","shell.execute_reply.started":"2022-06-12T10:55:24.024505Z","shell.execute_reply":"2022-06-12T10:55:24.040481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}