{"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":"import numpy as np \nimport pandas as pd ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-09T10:17:29.446492Z","iopub.execute_input":"2021-09-09T10:17:29.446825Z","iopub.status.idle":"2021-09-09T10:17:29.451127Z","shell.execute_reply.started":"2021-09-09T10:17:29.446796Z","shell.execute_reply":"2021-09-09T10:17:29.449961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.applications import MobileNetV2\nfrom keras.utils import to_categorical\nfrom keras.layers import Dense\nfrom keras import Model\nfrom keras.callbacks import ModelCheckpoint\nfrom keras.models import load_model\nimport os\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:32.159999Z","iopub.execute_input":"2021-09-09T10:17:32.160317Z","iopub.status.idle":"2021-09-09T10:17:32.166173Z","shell.execute_reply.started":"2021-09-09T10:17:32.160286Z","shell.execute_reply":"2021-09-09T10:17:32.165296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getFilenames(directory):\n    pth=[]\n    for dirpath,_,filenames in os.walk(directory):\n        for f in filenames:\n            pth.append(os.path.join(dirpath, f))\n    return pth\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:33.435976Z","iopub.execute_input":"2021-09-09T10:17:33.436304Z","iopub.status.idle":"2021-09-09T10:17:33.441496Z","shell.execute_reply.started":"2021-09-09T10:17:33.436274Z","shell.execute_reply":"2021-09-09T10:17:33.440629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imagedir0=\"../input/bottle/BottleDetection/Data/No bottles\"\nimagedir01=\"../input/bottle/not_bottle\"\nimagedir02=\"../input/bottle/no_bottles2\"\n\nfilenames00=getFilenames(imagedir0)\nfilenames00.sort()\n\nfilenames01=getFilenames(imagedir01)\nfilenames01.sort()\n\nfilenames02=getFilenames(imagedir02)\nfilenames02.sort()\n\n\nfilenames0=filenames00+filenames01+filenames02\n\n\ntarget0=[]\nfor i in range(len(filenames0)):\n    target0.append('n')\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:34.958221Z","iopub.execute_input":"2021-09-09T10:17:34.958586Z","iopub.status.idle":"2021-09-09T10:17:35.011676Z","shell.execute_reply.started":"2021-09-09T10:17:34.958554Z","shell.execute_reply":"2021-09-09T10:17:35.010737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#images_dir10 = \"../input/bottle/BottleDetection/Data/small bottle\"\n\nimages_dir11=\"../input/bottle/bottles/newsmall\"\n\n\n#filenames10=getFilenames(images_dir10)\n#filenames10.sort()\n\nfilenames11=getFilenames(images_dir11)\nfilenames11.sort()\n#filenames1=filenames10+filenames11\nfilenames1=filenames11\n\n\n\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:38.780290Z","iopub.execute_input":"2021-09-09T10:17:38.780626Z","iopub.status.idle":"2021-09-09T10:17:38.857950Z","shell.execute_reply.started":"2021-09-09T10:17:38.780594Z","shell.execute_reply":"2021-09-09T10:17:38.857269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random\nfilenames1 = random.sample(filenames1, 8000)\ntarget1=[]\nfor i in range(len(filenames1)):\n    target1.append('s')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:44.247020Z","iopub.execute_input":"2021-09-09T10:17:44.247357Z","iopub.status.idle":"2021-09-09T10:17:44.266819Z","shell.execute_reply.started":"2021-09-09T10:17:44.247326Z","shell.execute_reply":"2021-09-09T10:17:44.265967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#images_dir20 = \"../input/bottle/BottleDetection/Data/Large bottles\"\nimages_dir21=\"../input/bottle/newlarge\"\n\n#filenames20=getFilenames(images_dir20)\n#filenames20.sort()\n\n\nfilenames21=getFilenames(images_dir21)\nfilenames21.sort()\nfilenames2=filenames21\n\n\n#filenames2=filenames20+filenames21\n\ntarget2=[]\n\n\nfor i in range(len(filenames2)):\n    target2.append('l')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:46.233366Z","iopub.execute_input":"2021-09-09T10:17:46.233742Z","iopub.status.idle":"2021-09-09T10:17:46.268960Z","shell.execute_reply.started":"2021-09-09T10:17:46.233709Z","shell.execute_reply":"2021-09-09T10:17:46.268102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_dir11","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:48.897402Z","iopub.execute_input":"2021-09-09T10:17:48.897744Z","iopub.status.idle":"2021-09-09T10:17:48.905148Z","shell.execute_reply.started":"2021-09-09T10:17:48.897714Z","shell.execute_reply":"2021-09-09T10:17:48.904056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filenames=filenames0+filenames1+filenames2\ntarget=target0+target1+target2","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:49.734400Z","iopub.execute_input":"2021-09-09T10:17:49.734741Z","iopub.status.idle":"2021-09-09T10:17:49.739969Z","shell.execute_reply.started":"2021-09-09T10:17:49.734712Z","shell.execute_reply":"2021-09-09T10:17:49.738855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(target)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:50.577833Z","iopub.execute_input":"2021-09-09T10:17:50.578152Z","iopub.status.idle":"2021-09-09T10:17:50.583968Z","shell.execute_reply.started":"2021-09-09T10:17:50.578121Z","shell.execute_reply":"2021-09-09T10:17:50.582882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(filenames)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:51.024805Z","iopub.execute_input":"2021-09-09T10:17:51.025100Z","iopub.status.idle":"2021-09-09T10:17:51.029982Z","shell.execute_reply.started":"2021-09-09T10:17:51.025074Z","shell.execute_reply":"2021-09-09T10:17:51.029192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train,X_test,y_train,y_test=train_test_split(filenames, target, test_size=0.2, random_state=1,stratify=target)\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:51.867838Z","iopub.execute_input":"2021-09-09T10:17:51.868161Z","iopub.status.idle":"2021-09-09T10:17:51.904195Z","shell.execute_reply.started":"2021-09-09T10:17:51.868126Z","shell.execute_reply":"2021-09-09T10:17:51.903378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train,X_val,y_train,y_val=train_test_split(X_train, y_train, test_size=0.2, random_state=1,stratify=y_train)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:54.605483Z","iopub.execute_input":"2021-09-09T10:17:54.605820Z","iopub.status.idle":"2021-09-09T10:17:54.636114Z","shell.execute_reply.started":"2021-09-09T10:17:54.605790Z","shell.execute_reply":"2021-09-09T10:17:54.635254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf_train=pd.DataFrame(columns=['Images','target'])\ndf_validate=pd.DataFrame(columns=['Images','target'])\ndf_test=pd.DataFrame(columns=['Images','target'])\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:56.778572Z","iopub.execute_input":"2021-09-09T10:17:56.778891Z","iopub.status.idle":"2021-09-09T10:17:56.798259Z","shell.execute_reply.started":"2021-09-09T10:17:56.778855Z","shell.execute_reply":"2021-09-09T10:17:56.797354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['Images']=X_train\ndf_train['target']=y_train\n\n\ndf_validate['Images']=X_val\ndf_validate['target']=y_val\n\n\ndf_test['Images']=X_test\ndf_test['target']=y_test","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:57.208252Z","iopub.execute_input":"2021-09-09T10:17:57.208600Z","iopub.status.idle":"2021-09-09T10:17:57.229352Z","shell.execute_reply.started":"2021-09-09T10:17:57.208568Z","shell.execute_reply":"2021-09-09T10:17:57.228146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['target'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:17:59.757724Z","iopub.execute_input":"2021-09-09T10:17:59.758052Z","iopub.status.idle":"2021-09-09T10:17:59.772356Z","shell.execute_reply.started":"2021-09-09T10:17:59.758022Z","shell.execute_reply":"2021-09-09T10:17:59.771305Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_validate['target'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:06.471109Z","iopub.execute_input":"2021-09-09T10:18:06.471491Z","iopub.status.idle":"2021-09-09T10:18:06.480179Z","shell.execute_reply.started":"2021-09-09T10:18:06.471454Z","shell.execute_reply":"2021-09-09T10:18:06.479047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport keras_preprocessing\nfrom keras_preprocessing import image\nfrom keras_preprocessing.image import ImageDataGenerator\n\n\ntraining_datagen = ImageDataGenerator(\n  rescale = 1./255,\n  horizontal_flip=True,\n  vertical_flip=True, \n    rotation_range=40,\n    width_shift_range=0.2,\n    height_shift_range=0.2,\n    shear_range=0.2,\n    zoom_range=0.2)\n\ntrain_generator = training_datagen.flow_from_dataframe(\n        dataframe=df_train,\n        x_col=\"Images\",\n        y_col=\"target\",\n        target_size=(220, 220),\n        batch_size=32,color_mode='rgb',\n    \n    \n    \n    \n    \n    \n        class_mode='categorical')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:08.987685Z","iopub.execute_input":"2021-09-09T10:18:08.988006Z","iopub.status.idle":"2021-09-09T10:18:33.184398Z","shell.execute_reply.started":"2021-09-09T10:18:08.987977Z","shell.execute_reply":"2021-09-09T10:18:33.182827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_datagen = ImageDataGenerator(\n  rescale = 1./255,\n  horizontal_flip=False,\n  vertical_flip=False)\n\nval_generator = val_datagen.flow_from_dataframe(\n        dataframe=df_validate,\n        x_col=\"Images\",\n        y_col=\"target\",\n        target_size=(220, 220),\n        batch_size=32,color_mode='rgb',\n        class_mode='categorical')\n\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:33.187845Z","iopub.execute_input":"2021-09-09T10:18:33.188101Z","iopub.status.idle":"2021-09-09T10:18:43.265324Z","shell.execute_reply.started":"2021-09-09T10:18:33.188076Z","shell.execute_reply":"2021-09-09T10:18:43.264246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_datagen = ImageDataGenerator(\n  rescale = 1./255,\n  horizontal_flip=False,\n  vertical_flip=False)\n\ntest_generator = test_datagen.flow_from_dataframe(\n        dataframe=df_test,\n        x_col=\"Images\",\n        y_col=\"target\",\n        target_size=(220, 220),\n        batch_size=32,color_mode='rgb',\n        class_mode='categorical')","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:43.266589Z","iopub.execute_input":"2021-09-09T10:18:43.266947Z","iopub.status.idle":"2021-09-09T10:18:52.557936Z","shell.execute_reply.started":"2021-09-09T10:18:43.266911Z","shell.execute_reply":"2021-09-09T10:18:52.557057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import keras\nfrom keras import backend as K\nfrom keras.layers.core import Dense, Activation\nfrom keras.optimizers import Adam\nfrom keras.metrics import categorical_crossentropy\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.preprocessing import image\nfrom keras.models import Model\nfrom keras.applications import imagenet_utils\nfrom keras.layers import Dense,GlobalAveragePooling2D\nfrom keras.applications import MobileNet\nfrom keras.applications.mobilenet import preprocess_input\nimport numpy as np\nfrom IPython.display import Image\nfrom keras.optimizers import Adam","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:52.559353Z","iopub.execute_input":"2021-09-09T10:18:52.559713Z","iopub.status.idle":"2021-09-09T10:18:52.569736Z","shell.execute_reply.started":"2021-09-09T10:18:52.559676Z","shell.execute_reply":"2021-09-09T10:18:52.569022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_SHAPE = (220,220,3)\nbase_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE,\n                                               include_top=False,\n                                               weights='../input/bottle/mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_224_no_top.h5')\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:52.573224Z","iopub.execute_input":"2021-09-09T10:18:52.573842Z","iopub.status.idle":"2021-09-09T10:18:57.643998Z","shell.execute_reply.started":"2021-09-09T10:18:52.573801Z","shell.execute_reply":"2021-09-09T10:18:57.643227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=base_model.output\nx=GlobalAveragePooling2D()(x)\nx=Dense(1024,activation='relu')(x) #we add dense layers so that the model can learn more complex functions and classify for better results.\nx=Dense(1024,activation='relu')(x) #dense layer 2\nx=Dense(512,activation='relu')(x) #dense layer 3\npreds=Dense(3,activation='softmax')(x) #final layer with softmax activation\nmodel=Model(inputs=base_model.input,outputs=preds)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:57.647365Z","iopub.execute_input":"2021-09-09T10:18:57.647662Z","iopub.status.idle":"2021-09-09T10:18:57.707618Z","shell.execute_reply.started":"2021-09-09T10:18:57.647634Z","shell.execute_reply":"2021-09-09T10:18:57.706960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:57.709268Z","iopub.execute_input":"2021-09-09T10:18:57.709519Z","iopub.status.idle":"2021-09-09T10:18:57.764747Z","shell.execute_reply.started":"2021-09-09T10:18:57.709495Z","shell.execute_reply":"2021-09-09T10:18:57.763104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for layer in model.layers:\n    layer.trainable=False\n# or if we want to set the first 20 layers of the network to be non-trainable\nfor layer in model.layers[:20]:\n    layer.trainable=False\nfor layer in model.layers[20:]:\n    layer.trainable=True","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:57.765888Z","iopub.execute_input":"2021-09-09T10:18:57.766215Z","iopub.status.idle":"2021-09-09T10:18:57.784892Z","shell.execute_reply.started":"2021-09-09T10:18:57.766179Z","shell.execute_reply":"2021-09-09T10:18:57.784256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=\"adam\", loss=\"categorical_crossentropy\", metrics=[\"categorical_accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:57.788419Z","iopub.execute_input":"2021-09-09T10:18:57.788700Z","iopub.status.idle":"2021-09-09T10:18:57.812961Z","shell.execute_reply.started":"2021-09-09T10:18:57.788675Z","shell.execute_reply":"2021-09-09T10:18:57.812330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# training parameters\nepochs = 10 # maximum number of epochs\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:57.815774Z","iopub.execute_input":"2021-09-09T10:18:57.816024Z","iopub.status.idle":"2021-09-09T10:18:57.822124Z","shell.execute_reply.started":"2021-09-09T10:18:57.815999Z","shell.execute_reply":"2021-09-09T10:18:57.821259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"w=val_generator.next()\nw[1][0]","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:57.823579Z","iopub.execute_input":"2021-09-09T10:18:57.823952Z","iopub.status.idle":"2021-09-09T10:18:58.079547Z","shell.execute_reply.started":"2021-09-09T10:18:57.823913Z","shell.execute_reply":"2021-09-09T10:18:58.078641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_checkpoint = ModelCheckpoint(\"best_model.h5\", save_best_only=True, verbose=1)\n\nhistory = model.fit_generator(train_generator, epochs=10,\n                              validation_data=val_generator,  callbacks=[model_checkpoint])\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:18:58.080859Z","iopub.execute_input":"2021-09-09T10:18:58.081219Z","iopub.status.idle":"2021-09-09T10:51:17.872474Z","shell.execute_reply.started":"2021-09-09T10:18:58.081181Z","shell.execute_reply":"2021-09-09T10:51:17.871702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.save(\"model_99acc.h5\")","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:52:02.461513Z","iopub.execute_input":"2021-09-09T10:52:02.461846Z","iopub.status.idle":"2021-09-09T10:52:02.953167Z","shell.execute_reply.started":"2021-09-09T10:52:02.461815Z","shell.execute_reply":"2021-09-09T10:52:02.952361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.evaluate(test_generator)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:51:25.205412Z","iopub.execute_input":"2021-09-09T10:51:25.205788Z","iopub.status.idle":"2021-09-09T10:51:48.002239Z","shell.execute_reply.started":"2021-09-09T10:51:25.205756Z","shell.execute_reply":"2021-09-09T10:51:48.001468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport matplotlib.pyplot as plt\nimage=cv2.imread('../input/bottle/not_bottle/not_bottle/not_bottle_3446.jpg')\nplt.imshow(image)","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:52:20.278887Z","iopub.execute_input":"2021-09-09T10:52:20.279223Z","iopub.status.idle":"2021-09-09T10:52:20.686996Z","shell.execute_reply.started":"2021-09-09T10:52:20.279190Z","shell.execute_reply":"2021-09-09T10:52:20.686176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testf=[]\noriginal=[]\nfor i in range(df_test.shape[0]):\n    testf.append(df_test.iloc[i,0])\n    \n    if df_test.iloc[i,1]=='s':\n        original.append(2)\n    if df_test.iloc[i,1]=='l':\n        original.append(0)\n    if df_test.iloc[i,1]=='n':\n        original.append(1)\n        \n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:52:08.618582Z","iopub.execute_input":"2021-09-09T10:52:08.618896Z","iopub.status.idle":"2021-09-09T10:52:08.808741Z","shell.execute_reply.started":"2021-09-09T10:52:08.618866Z","shell.execute_reply":"2021-09-09T10:52:08.807934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nimage=cv2.imread(df_test.iloc[100,0])\nplt.imshow(image)\ndf_test.iloc[100,1]","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:52:25.535806Z","iopub.execute_input":"2021-09-09T10:52:25.536120Z","iopub.status.idle":"2021-09-09T10:52:25.697323Z","shell.execute_reply.started":"2021-09-09T10:52:25.536092Z","shell.execute_reply":"2021-09-09T10:52:25.696290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted=[]\nfrom PIL import Image\nfrom keras.preprocessing.image import img_to_array\nfrom keras.preprocessing.image import load_img\nfor i in testf:\n    img = Image.open(i)\n    img = img.resize((220,220), Image.ANTIALIAS)\n    imag=img_to_array(img)\n    imag/=255\n    predict=model.predict(imag[None,:])\n    yp=np.argmax(predict, axis=1)\n    predicted.append(yp)\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:52:34.340620Z","iopub.execute_input":"2021-09-09T10:52:34.340946Z","iopub.status.idle":"2021-09-09T10:54:32.610767Z","shell.execute_reply.started":"2021-09-09T10:52:34.340915Z","shell.execute_reply":"2021-09-09T10:54:32.609831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted=np.array(predicted)\npredicted=predicted.ravel()","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:54:32.612742Z","iopub.execute_input":"2021-09-09T10:54:32.613055Z","iopub.status.idle":"2021-09-09T10:54:32.626379Z","shell.execute_reply.started":"2021-09-09T10:54:32.613026Z","shell.execute_reply":"2021-09-09T10:54:32.625481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report, confusion_matrix,accuracy_score,classification_report\nprint(accuracy_score(original, predicted))","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:54:32.627623Z","iopub.execute_input":"2021-09-09T10:54:32.627985Z","iopub.status.idle":"2021-09-09T10:54:32.636466Z","shell.execute_reply.started":"2021-09-09T10:54:32.627948Z","shell.execute_reply":"2021-09-09T10:54:32.635597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = [\"Large Bottles\", \"No Bottles\", \"Small Bottle \"]\nfrom sklearn.metrics import ConfusionMatrixDisplay\nimport matplotlib.pyplot as plt \n\ncm=confusion_matrix(original, predicted)\ndisp =ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=labels)\ndisp.plot(cmap=plt.cm.Blues)\nplt.savefig('Confusion.jpg',dpi=300)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:54:32.637850Z","iopub.execute_input":"2021-09-09T10:54:32.638460Z","iopub.status.idle":"2021-09-09T10:54:33.058348Z","shell.execute_reply.started":"2021-09-09T10:54:32.638409Z","shell.execute_reply":"2021-09-09T10:54:33.057522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(original, predicted))","metadata":{"execution":{"iopub.status.busy":"2021-09-09T10:54:33.060067Z","iopub.execute_input":"2021-09-09T10:54:33.060535Z","iopub.status.idle":"2021-09-09T10:54:33.082281Z","shell.execute_reply.started":"2021-09-09T10:54:33.060500Z","shell.execute_reply":"2021-09-09T10:54:33.081486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}