{"cells":[{"metadata":{},"cell_type":"markdown","source":"![Google LAndmark Recognition](https://miro.medium.com/max/2680/1*d70CQj7zmTsy01WQvi5cpg.jpeg)"},{"metadata":{},"cell_type":"markdown","source":"# Breakdown of this notebook:\n1. **Importing Libraries**\n2. **Loading the dataset**\n3. **Data Visualization:** \n    - Histogram of Count of Landmark ID\n    - Plot the most frequent landmark_ids\n    - Plot the least frequent landmark_ids\n    - Landmark ID distribution\n    - Landmark Id Density Plot\n    - Landmark id distribuition and density plot\n    - Training set: number of images per class(line plot)\n    - Training set: number of images per class(statter plot)\n    - Visualize outliers, min/max or quantiles of the landmarks count\n    - Probability Plot\n4. **Plot Random Images**    "},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport warnings\nfrom scipy import stats\nimport glob\nwarnings.filterwarnings('ignore')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv(\"../input/landmark-recognition-2020/train.csv\")\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check for Duplicates\ntrain.duplicated().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Training data size\",train.shape)\nsubmission = pd.read_csv(\"../input/landmark-recognition-2020/sample_submission.csv\")\nsubmission.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train['landmark_id'].value_counts().hist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# missing data in training data \ntotal = train.isnull().sum().sort_values(ascending = False)\npercent = (train.isnull().sum()/train.isnull().count()).sort_values(ascending = False)\nmissing_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])\nmissing_train_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Occurance of landmark_id in decreasing order(Top categories)\ntemp = pd.DataFrame(train.landmark_id.value_counts().head(8))\ntemp.reset_index(inplace=True)\ntemp.columns = ['landmark_id','count']\ntemp","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Plot the most frequent landmark_ids\nplt.figure(figsize = (9, 8))\nplt.title('Most frequent landmarks')\nsns.set_color_codes(\"pastel\")\nsns.barplot(x=\"landmark_id\", y=\"count\", data=temp,\n            label=\"Count\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Occurance of landmark_id in increasing order\ntemp = pd.DataFrame(train.landmark_id.value_counts().tail(8))\ntemp.reset_index(inplace=True)\ntemp.columns = ['landmark_id','count']\ntemp","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Plot the least frequent landmark_ids\nplt.figure(figsize = (9, 8))\nplt.title('Least frequent landmarks')\nsns.set_color_codes(\"pastel\")\nsns.barplot(x=\"landmark_id\", y=\"count\", data=temp,\n            label=\"Count\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Landmark ID distribution\nplt.figure(figsize = (10, 8))\nplt.title('Landmark ID Distribuition')\nsns.distplot(train['landmark_id'])\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Number of classes under 20 occurences\",(train['landmark_id'].value_counts() <= 20).sum(),'out of total number of categories',len(train['landmark_id'].unique()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Landmark Id Density Plot\nplt.figure(figsize = (8, 8))\nplt.title('Landmark id density plot')\nsns.kdeplot(train['landmark_id'], color=\"tomato\", shade=True)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Landmark id distribuition and density plot\nplt.figure(figsize = (8, 8))\nplt.title('Landmark id distribuition and density plot')\nsns.distplot(train['landmark_id'],color='green', kde=True,bins=100)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.set()\nplt.title('Training set: number of images per class(line plot)')\nsns.set_color_codes(\"pastel\")\nlandmarks_fold = pd.DataFrame(train['landmark_id'].value_counts())\nlandmarks_fold.reset_index(inplace=True)\nlandmarks_fold.columns = ['landmark_id','count']\nax = landmarks_fold['count'].plot(logy=True, grid=True)\nlocs, labels = plt.xticks()\nplt.setp(labels, rotation=30)\nax.set(xlabel=\"Landmarks\", ylabel=\"Number of images\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Training set: number of images per class(statter plot)\nsns.set()\nlandmarks_fold_sorted = pd.DataFrame(train['landmark_id'].value_counts())\nlandmarks_fold_sorted.reset_index(inplace=True)\nlandmarks_fold_sorted.columns = ['landmark_id','count']\nlandmarks_fold_sorted = landmarks_fold_sorted.sort_values('landmark_id')\nax = landmarks_fold_sorted.plot.scatter(\\\n     x='landmark_id',y='count',\n     title='Training set: number of images per class(statter plot)')\nlocs, labels = plt.xticks()\nplt.setp(labels, rotation=30)\nax.set(xlabel=\"Landmarks\", ylabel=\"Number of images\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Visualize outliers, min/max or quantiles of the landmarks count\nsns.set()\nax = landmarks_fold_sorted.boxplot(column='count')\nax.set_yscale('log')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Probability Plot\nsns.set()\nres = stats.probplot(train['landmark_id'], plot=plt)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Plot Random Images"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_list = glob.glob('../input/landmark-recognition-2020/train/*/*/*/*')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.rcParams[\"axes.grid\"] = False\nf, axarr = plt.subplots(4, 3, figsize=(24, 22))\n\ncurr_row = 0\nfor i in range(12):\n    example = cv2.imread(train_list[i])\n    example = example[:,:,::-1]\n    \n    col = i%4\n    axarr[col, curr_row].imshow(example)\n    if col == 3:\n        curr_row += 1","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## References\n - [Google Landmarks v2 Exploratory Data Analysis(EDA)](https://www.kaggle.com/huangxiaoquan/google-landmarks-v2-exploratory-data-analysis-eda/data)\n - [Google Landmark Recogn. Challenge Data Exploration](https://www.kaggle.com/gpreda/google-landmark-recogn-challenge-data-exploration)\n - [A Very Extensive Landmark Exploratory Analysis](https://www.kaggle.com/codename007/a-very-extensive-landmark-exploratory-analysis) \n - [Diving into Google’s Landmark Recognition Kaggle Competition](https://towardsdatascience.com/diving-into-googles-landmark-recognition-kaggle-competition-6975dbe11072)"},{"metadata":{},"cell_type":"markdown","source":"## End of the Notebook"},{"metadata":{},"cell_type":"markdown","source":"## For more updates in this notebook checkout this repository: https://github.com/chiragsamal/Google-Landmark-Recognition "},{"metadata":{},"cell_type":"markdown","source":"<h1> Please Upvote if you found this helpful:) </h1>"}],"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":4,"nbformat_minor":4}