{"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":13836,"databundleVersionId":1718836,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"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\n\nfrom IPython.display import clear_output\nclear_output()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-06-16T03:52:52.311438Z","iopub.execute_input":"2024-06-16T03:52:52.311913Z","iopub.status.idle":"2024-06-16T03:53:00.366480Z","shell.execute_reply.started":"2024-06-16T03:52:52.311874Z","shell.execute_reply":"2024-06-16T03:53:00.365382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:53:46.211637Z","iopub.execute_input":"2024-06-16T03:53:46.213025Z","iopub.status.idle":"2024-06-16T03:53:46.217791Z","shell.execute_reply.started":"2024-06-16T03:53:46.212980Z","shell.execute_reply":"2024-06-16T03:53:46.216551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train  = pd.read_csv('/kaggle/input/cassava-leaf-disease-classification/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:53:52.161801Z","iopub.execute_input":"2024-06-16T03:53:52.162230Z","iopub.status.idle":"2024-06-16T03:53:52.212580Z","shell.execute_reply.started":"2024-06-16T03:53:52.162197Z","shell.execute_reply":"2024-06-16T03:53:52.210546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:53:55.222286Z","iopub.execute_input":"2024-06-16T03:53:55.222961Z","iopub.status.idle":"2024-06-16T03:53:55.251872Z","shell.execute_reply.started":"2024-06-16T03:53:55.222906Z","shell.execute_reply":"2024-06-16T03:53:55.249894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()\ntrain.shape","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:53:59.611715Z","iopub.execute_input":"2024-06-16T03:53:59.612150Z","iopub.status.idle":"2024-06-16T03:53:59.643616Z","shell.execute_reply.started":"2024-06-16T03:53:59.612114Z","shell.execute_reply":"2024-06-16T03:53:59.642040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport csv\ndef list_images_index(folder_path , img_code):\n    files = os.listdir(folder_path)\n    \n#     img_extensions = ['.jpg', '.jpeg', '.png']\n    images = [file for file in files ]\n    \n    for index , image in enumerate(images):\n        if(image == img_code):\n            return index","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:02.862083Z","iopub.execute_input":"2024-06-16T03:54:02.862992Z","iopub.status.idle":"2024-06-16T03:54:02.870430Z","shell.execute_reply.started":"2024-06-16T03:54:02.862941Z","shell.execute_reply":"2024-06-16T03:54:02.868940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport csv\ndef images_index(path,code):\n    files = os.listdir(path)\n    images = [file for file in files ]\n    \n    for index , image in enumerate(images):\n        if(image == code):\n            return index","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:06.477097Z","iopub.execute_input":"2024-06-16T03:54:06.478685Z","iopub.status.idle":"2024-06-16T03:54:06.488732Z","shell.execute_reply.started":"2024-06-16T03:54:06.478619Z","shell.execute_reply":"2024-06-16T03:54:06.486961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/cassava-leaf-disease-classification/train_images/'\ncode = '2405559933.jpg'\nlist_images_index(path , code)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:09.891571Z","iopub.execute_input":"2024-06-16T03:54:09.892061Z","iopub.status.idle":"2024-06-16T03:54:09.911758Z","shell.execute_reply.started":"2024-06-16T03:54:09.892025Z","shell.execute_reply":"2024-06-16T03:54:09.910270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"code = '2405559933.jpg'\nimage = Image.open('/kaggle/input/cassava-leaf-disease-classification/train_images/2405559933.jpg')\nimg_arr = np.array(image)\nplt.imshow(image)\nindex = list_images_index(path , code)\nprint('Category of disease is :',train.iloc[index , 1])","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:18.687609Z","iopub.execute_input":"2024-06-16T03:54:18.690668Z","iopub.status.idle":"2024-06-16T03:54:19.296345Z","shell.execute_reply.started":"2024-06-16T03:54:18.690588Z","shell.execute_reply":"2024-06-16T03:54:19.294876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images = []","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:26.152126Z","iopub.execute_input":"2024-06-16T03:54:26.153667Z","iopub.status.idle":"2024-06-16T03:54:26.160541Z","shell.execute_reply.started":"2024-06-16T03:54:26.153613Z","shell.execute_reply":"2024-06-16T03:54:26.158720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/cassava-leaf-disease-classification/train_images/'\nfor filename in os.listdir(path):\n    images.append(filename)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:31.020352Z","iopub.execute_input":"2024-06-16T03:54:31.020833Z","iopub.status.idle":"2024-06-16T03:54:31.038204Z","shell.execute_reply.started":"2024-06-16T03:54:31.020795Z","shell.execute_reply":"2024-06-16T03:54:31.036408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame(images)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:35.262277Z","iopub.execute_input":"2024-06-16T03:54:35.263496Z","iopub.status.idle":"2024-06-16T03:54:35.271562Z","shell.execute_reply.started":"2024-06-16T03:54:35.263443Z","shell.execute_reply":"2024-06-16T03:54:35.270177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_arr_list = []","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:40.701626Z","iopub.execute_input":"2024-06-16T03:54:40.702077Z","iopub.status.idle":"2024-06-16T03:54:40.707646Z","shell.execute_reply.started":"2024-06-16T03:54:40.702041Z","shell.execute_reply":"2024-06-16T03:54:40.706187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = '/kaggle/input/cassava-leaf-disease-classification/train_images/'\ncount = 0\nfor img in images:\n    if(count <= 1000):\n        pathhh  = os.path.join(path , img)\n        im = Image.open(pathhh)\n        img_arr = np.array(im)\n        img_arr_list.append(img_arr)\n        \n        count +=1","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:44.491521Z","iopub.execute_input":"2024-06-16T03:54:44.492969Z","iopub.status.idle":"2024-06-16T03:54:55.727705Z","shell.execute_reply.started":"2024-06-16T03:54:44.492906Z","shell.execute_reply":"2024-06-16T03:54:55.726546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_flatten1 = []","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:54:57.991888Z","iopub.execute_input":"2024-06-16T03:54:57.992432Z","iopub.status.idle":"2024-06-16T03:54:57.998405Z","shell.execute_reply.started":"2024-06-16T03:54:57.992388Z","shell.execute_reply":"2024-06-16T03:54:57.996929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count = 0\nfor i in img_arr_list:\n    k = i.flatten()\n    count += 1\n    img_flatten1.append(k)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:55:03.566547Z","iopub.execute_input":"2024-06-16T03:55:03.571181Z","iopub.status.idle":"2024-06-16T03:55:05.134361Z","shell.execute_reply.started":"2024-06-16T03:55:03.571106Z","shell.execute_reply":"2024-06-16T03:55:05.132815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# rescalling \nimg_flatten1 = np.array(img_flatten1)\nimg_flatten1 = (img_flatten1 / (1./255)).astype(np.uint8)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:55:07.175957Z","iopub.execute_input":"2024-06-16T03:55:07.176376Z","iopub.status.idle":"2024-06-16T03:55:15.233044Z","shell.execute_reply.started":"2024-06-16T03:55:07.176343Z","shell.execute_reply":"2024-06-16T03:55:15.231744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nxtrain , xtest , ytrain , ytest = train_test_split(img_flatten1 , train.iloc[:1001,1].to_numpy() , test_size = 0.2 , random_state= 0)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:55:27.486028Z","iopub.execute_input":"2024-06-16T03:55:27.486496Z","iopub.status.idle":"2024-06-16T03:55:28.247848Z","shell.execute_reply.started":"2024-06-16T03:55:27.486448Z","shell.execute_reply":"2024-06-16T03:55:28.246190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:55:31.696194Z","iopub.execute_input":"2024-06-16T03:55:31.696720Z","iopub.status.idle":"2024-06-16T03:55:31.799208Z","shell.execute_reply.started":"2024-06-16T03:55:31.696683Z","shell.execute_reply":"2024-06-16T03:55:31.797965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr = LogisticRegression(multi_class = 'multinomial' , solver = 'lbfgs' , n_jobs = -1)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:55:35.666223Z","iopub.execute_input":"2024-06-16T03:55:35.667467Z","iopub.status.idle":"2024-06-16T03:55:35.672482Z","shell.execute_reply.started":"2024-06-16T03:55:35.667425Z","shell.execute_reply":"2024-06-16T03:55:35.671161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"lr.fit(xtrain , ytrain)","metadata":{"execution":{"iopub.status.busy":"2024-06-16T03:55:41.785884Z","iopub.execute_input":"2024-06-16T03:55:41.786391Z","iopub.status.idle":"2024-06-16T03:55:51.421182Z","shell.execute_reply.started":"2024-06-16T03:55:41.786351Z","shell.execute_reply":"2024-06-16T03:55:51.419370Z"}},"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":"","metadata":{},"execution_count":null,"outputs":[]}]}