{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"81e15f4b-44fc-6e1b-d1b4-f9c6b55154dc"},"source":"## Exploration ##\nuses https://www.kaggle.com/philschmidt/noaa-fisheries-steller-sea-lion-population-count/counting-sea-lions"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"021fef5a-4405-e552-caef-e42c3e51c50d"},"outputs":[],"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"4f55b445-5efa-1e5b-083e-3b7382c695c7"},"outputs":[],"source":"from glob import glob\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom scipy import stats"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"8543efa1-8039-389d-9e5c-583f3c603e79"},"outputs":[],"source":"df = pd.read_csv('../input/Train/train.csv')\ndf.head()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fa1d1f79-9e15-31b6-3ae8-71d31af549b3"},"outputs":[],"source":"def corrfunc(x, y, **kws):\n    r, _ = stats.pearsonr(x, y)\n    ax = plt.gca()\n    ax.annotate(\"r = {:.3f}\".format(r),\n                xy=(.1, .9), xycoords=ax.transAxes)\n\ng = sns.PairGrid(df[['adult_males', 'subadult_males', 'adult_females', 'juveniles', 'pups']], palette=[\"red\"])\n#g.map_upper(plt.scatter, s=10)\ng.map_lower(plt.scatter, s=10)\ng.map_diag(sns.distplot, kde=False)\n#g.map_lower(sns.kdeplot, cmap=\"Blues_d\")\ng.map_lower(corrfunc)\n#sns.pairplot(df)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"68826d98-d247-a9f5-c08f-7b6de6cfcae1"},"outputs":[],"source":"Is there a correlation between pups percentage and flock size?"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"02f5f57c-9610-6aec-e387-2288202c9387"},"outputs":[],"source":"df['total'] = df['adult_males']+df['subadult_males'] + df['adult_females'] + df['juveniles']+df['pups']\ndf['no_pups'] = df['adult_males']+df['subadult_males'] + df['adult_females'] + df['juveniles']\ndf['pups_perc'] = df['pups'] / df['total']\nflock_without_pups = df[df['pups']==0]\nflock_with_pups = df[df['pups']>0]\nbig_flock_with_pups = flock_with_pups[flock_with_pups['total']>150]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"1167459f-6d3b-d223-1408-25965a1334ac"},"outputs":[],"source":"g_flock_with_pups = sns.PairGrid(flock_with_pups[['adult_males', 'subadult_males', 'adult_females', 'juveniles','pups_perc','total']], palette=[\"red\"])\ng_flock_with_pups.map_lower(plt.scatter, s=10)\ng_flock_with_pups.map_diag(sns.distplot, kde=False)\ng_flock_with_pups.map_lower(corrfunc)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"435f8052-13d6-53bd-7d92-9e73f541190c"},"outputs":[],"source":"g_flock_with_pups = sns.PairGrid(flock_with_pups[['adult_males', 'subadult_males', 'adult_females', 'juveniles','pups','pups_perc']], palette=[\"red\"])\ng_flock_with_pups.map_lower(plt.scatter, s=10)\ng_flock_with_pups.map_diag(sns.distplot, kde=False)\ng_flock_with_pups.map_lower(corrfunc)"},{"cell_type":"markdown","metadata":{"_cell_guid":"ab5584bf-3c45-64e3-39b9-45f8451e0fd6"},"source":"Looks like: the more pups, the bigger percentage of them. Check on bigger flocks:\n   "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2a6c6c9f-97c9-169c-0161-65e884376947"},"outputs":[],"source":"flock_with_many_pups = flock_with_pups[flock_with_pups['pups']>20]\ng_flock_with_many_pups = sns.PairGrid(flock_with_many_pups[['adult_males', 'subadult_males', 'adult_females', 'juveniles','pups','pups_perc']], palette=[\"red\"])\ng_flock_with_many_pups.map_lower(plt.scatter, s=10)\ng_flock_with_many_pups.map_diag(sns.distplot, kde=False)\ng_flock_with_many_pups.map_lower(corrfunc)"},{"cell_type":"markdown","metadata":{"_cell_guid":"4b6fda79-f21f-f112-a7d8-521261fb9a4f"},"source":"Check if female lion has a pup in one year, and none next year. Assume that pup become yuvenile in a year.\n\nThen juveniles + pubs should be more correlated to females."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0659c992-6b75-32b5-3b5f-ce5e7266445c"},"outputs":[],"source":"df['young'] = df['juveniles']+df['pups']\nflock_with_young = df[df['young']>20]\ng_flock_with_young = sns.PairGrid(flock_with_young[['adult_males', 'subadult_males', 'adult_females','young','total']], palette=[\"red\"])\ng_flock_with_young.map_lower(plt.scatter, s=10)\ng_flock_with_young.map_diag(sns.distplot, kde=False)\ng_flock_with_young.map_lower(corrfunc)\n"},{"cell_type":"markdown","metadata":{"_cell_guid":"7c31ac25-852f-7a47-7d60-4b2e5fb293be"},"source":"**To be continued**"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b8ec4c59-935b-7eee-e44c-c5bf247ebcd3"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.0"}},"nbformat":4,"nbformat_minor":0}