{"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":"markdown","source":"# This notebook is not yet completed !!","metadata":{}},{"cell_type":"markdown","source":"![](https://c.tenor.com/Z25t-Dm102AAAAAC/welcome.gif)","metadata":{}},{"cell_type":"markdown","source":"# Work done in this Notebook:\n- Loaded our data, checked for null values.\n- Plotted horizontal bar chart.\n- Displayed few images from training dataset and testing dataset.","metadata":{}},{"cell_type":"markdown","source":"# Overview\n> The Sorghum-100 dataset is a curated subset of the RGB imagery captured during the TERRA-REF experiments, labeled by cultivar.<br>\n> This data could be used to develop and assess a variety of plant phenotyping models which seek to answer questions relating to the presence or absence of desirable traits (e.g., \"does this plant exhibit signs of water stress?''). <br>\n> In this contest, we focus on the question: \"What cultivar is shown in this image?<br><br>\n![](https://terraref.org/sites/terraref.org/files/TERRA-REF-Scanner.jpg)\n> Predicting the cultivar in an image is an especially good challenge problem for familiarizing the machine learning community with the TERRA-REF data. <br>\n> At first blush, the task of predicting the cultivar from an image of a plant may not seem to be the most biologically compelling question to answer -- in the context of plant breeding, the cultivar, or parental lines are typically known. <br>\n> A high accuracy machine learning predictor of the species captured by the sensor data, however, can be used to determine where errors in the planting process may have occurred. \n> For example, seed may be mislabeled prior to planting, or planters may get jammed, depositing seeds non-uniformly in a field.<br>\n> Both types of errors are surprisingly common and can cause major problems when processing data from large-scale field experiments with hundreds of cultivars and complex field planting layouts.<br>","metadata":{}},{"cell_type":"markdown","source":"# To read about [List of Past FGVC competitions](https://www.kaggle.com/c/sorghum-id-fgvc-9/discussion/313171) provided by @Sanyam Bhutani","metadata":{}},{"cell_type":"markdown","source":"# Data Description\n- The Sorghum-100 dataset consists of 48,106 images and 100 different sorghum cultivars grown in June of 2017 (the images come from the middle of the growing season when the plants were quite large but not yet lodging -- or falling over).\n\n- Each image is taken using an RGB spectral camera taken from a vertical view of the sorghum plants in the [TERRA-REF](https://terraref.org/) field in Arizona.","metadata":{}},{"cell_type":"code","source":"# Importing librarys\n\nimport os\nimport random\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib.image import imread\nfrom IPython.display import display, Image","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.151303Z","iopub.execute_input":"2022-03-16T11:14:48.151621Z","iopub.status.idle":"2022-03-16T11:14:48.158164Z","shell.execute_reply.started":"2022-03-16T11:14:48.151589Z","shell.execute_reply":"2022-03-16T11:14:48.157045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# loading the csv files\n\ndata = pd.read_csv(\"../input/sorghum-id-fgvc-9/train_cultivar_mapping.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.160370Z","iopub.execute_input":"2022-03-16T11:14:48.160924Z","iopub.status.idle":"2022-03-16T11:14:48.198089Z","shell.execute_reply.started":"2022-03-16T11:14:48.160875Z","shell.execute_reply":"2022-03-16T11:14:48.197259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# preview \n\ndata","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.199615Z","iopub.execute_input":"2022-03-16T11:14:48.200136Z","iopub.status.idle":"2022-03-16T11:14:48.213931Z","shell.execute_reply.started":"2022-03-16T11:14:48.200089Z","shell.execute_reply":"2022-03-16T11:14:48.212827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking the null values\n\ndata.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.215833Z","iopub.execute_input":"2022-03-16T11:14:48.216339Z","iopub.status.idle":"2022-03-16T11:14:48.231094Z","shell.execute_reply.started":"2022-03-16T11:14:48.216294Z","shell.execute_reply":"2022-03-16T11:14:48.230250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"No Null values\n\n![](https://c.tenor.com/sFdMqQtnaLUAAAAC/hot-uff.gif)","metadata":{}},{"cell_type":"code","source":"# Checking if the name of the files repeats or not\n\ndata.image.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.235963Z","iopub.execute_input":"2022-03-16T11:14:48.236865Z","iopub.status.idle":"2022-03-16T11:14:48.260700Z","shell.execute_reply.started":"2022-03-16T11:14:48.236822Z","shell.execute_reply":"2022-03-16T11:14:48.260031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This code will show us if a id has multiple photos\n\ndata.cultivar.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.261878Z","iopub.execute_input":"2022-03-16T11:14:48.262338Z","iopub.status.idle":"2022-03-16T11:14:48.275723Z","shell.execute_reply.started":"2022-03-16T11:14:48.262188Z","shell.execute_reply":"2022-03-16T11:14:48.274794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"markdown","source":"To plot each label we need to restrict the values we give for horizontal bar chart","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\nfig = px.bar(data, y=data.cultivar.value_counts().index[:25], x=data.cultivar.value_counts().values[:25], orientation='h')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:48.277023Z","iopub.execute_input":"2022-03-16T11:14:48.277699Z","iopub.status.idle":"2022-03-16T11:14:51.010074Z","shell.execute_reply.started":"2022-03-16T11:14:48.277658Z","shell.execute_reply":"2022-03-16T11:14:51.009053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\nfig = px.bar(data, y=data.cultivar.value_counts().index[25:50], x=data.cultivar.value_counts().values[25:50], orientation='h')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.011613Z","iopub.execute_input":"2022-03-16T11:14:51.011870Z","iopub.status.idle":"2022-03-16T11:14:51.085595Z","shell.execute_reply.started":"2022-03-16T11:14:51.011839Z","shell.execute_reply":"2022-03-16T11:14:51.084741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\nfig = px.bar(data, y=data.cultivar.value_counts().index[50:75], x=data.cultivar.value_counts().values[50:75], orientation='h')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.087366Z","iopub.execute_input":"2022-03-16T11:14:51.087882Z","iopub.status.idle":"2022-03-16T11:14:51.160491Z","shell.execute_reply.started":"2022-03-16T11:14:51.087834Z","shell.execute_reply":"2022-03-16T11:14:51.159413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\nfig = px.bar(data, y=data.cultivar.value_counts().index[75:100], x=data.cultivar.value_counts().values[75:100], orientation='h')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.161850Z","iopub.execute_input":"2022-03-16T11:14:51.162165Z","iopub.status.idle":"2022-03-16T11:14:51.368297Z","shell.execute_reply.started":"2022-03-16T11:14:51.162132Z","shell.execute_reply":"2022-03-16T11:14:51.367338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i = \"../input/sorghum-id-fgvc-9/train_images\"\nfor j in i:\n    print(j)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.370722Z","iopub.execute_input":"2022-03-16T11:14:51.370965Z","iopub.status.idle":"2022-03-16T11:14:51.380918Z","shell.execute_reply.started":"2022-03-16T11:14:51.370935Z","shell.execute_reply":"2022-03-16T11:14:51.378089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Lets looks at some of the images","metadata":{}},{"cell_type":"code","source":"# display(Image(filename='../input/sorghum-id-fgvc-9/train_images/2017-06-01__10-26-39-476.png'))","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.384181Z","iopub.execute_input":"2022-03-16T11:14:51.384573Z","iopub.status.idle":"2022-03-16T11:14:51.390460Z","shell.execute_reply.started":"2022-03-16T11:14:51.384533Z","shell.execute_reply":"2022-03-16T11:14:51.389756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show(n,di):\n    if di=='train':\n        path=\"../input/sorghum-id-fgvc-9/train_images\"\n        for i in range(n):\n            files=os.listdir(path)\n            d=random.choice(files)\n            print(\"File Name with dir: \",path+'/'+d)\n            display(Image(filename=path+'/'+d))\n    else:\n        path=\"../input/sorghum-id-fgvc-9/test\"\n        for i in range(n):\n            files=os.listdir(path)\n            d=random.choice(files)\n            print(\"File Name with dir: \",path+'/'+d)\n            display(Image(filename=path+'/'+d))\n        ","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.392208Z","iopub.execute_input":"2022-03-16T11:14:51.392552Z","iopub.status.idle":"2022-03-16T11:14:51.405421Z","shell.execute_reply.started":"2022-03-16T11:14:51.392502Z","shell.execute_reply":"2022-03-16T11:14:51.404721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show(n=5,di='train')","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:51.406956Z","iopub.execute_input":"2022-03-16T11:14:51.407487Z","iopub.status.idle":"2022-03-16T11:14:52.030795Z","shell.execute_reply.started":"2022-03-16T11:14:51.407422Z","shell.execute_reply":"2022-03-16T11:14:52.029476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show(n=5,di='test')","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:52.032366Z","iopub.execute_input":"2022-03-16T11:14:52.032700Z","iopub.status.idle":"2022-03-16T11:14:52.641780Z","shell.execute_reply.started":"2022-03-16T11:14:52.032660Z","shell.execute_reply":"2022-03-16T11:14:52.640835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Prediction\n> Since I have not done any prediction yet we will submit the sample submission, in later version I will create the model for it.","metadata":{}},{"cell_type":"code","source":"sub=pd.read_csv(\"../input/sorghum-id-fgvc-9/sample_submission.csv\")\nsub.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T11:14:52.643163Z","iopub.execute_input":"2022-03-16T11:14:52.643897Z","iopub.status.idle":"2022-03-16T11:14:52.760400Z","shell.execute_reply.started":"2022-03-16T11:14:52.643851Z","shell.execute_reply":"2022-03-16T11:14:52.759541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Work in Progresss \n\n![](https://forums.zenyte.com/uploads/monthly_2020_04/1629007984_source(1).gif.c78f26d9694ecf5b46dafdd78c28103a.gif)","metadata":{}}]}