{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# import os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\nimport warnings\nwarnings.simplefilter(action='ignore', category=FutureWarning)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-06T22:13:45.622227Z","iopub.execute_input":"2021-12-06T22:13:45.622917Z","iopub.status.idle":"2021-12-06T22:13:45.646653Z","shell.execute_reply.started":"2021-12-06T22:13:45.622812Z","shell.execute_reply":"2021-12-06T22:13:45.645981Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\n%matplotlib inline\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl\n\nimport seaborn as sns\nfrom pandas.plotting import scatter_matrix\n\nfrom sklearn import manifold\n\ndata_dir = '../input/petfinder-pawpularity-score'","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:45.656332Z","iopub.execute_input":"2021-12-06T22:13:45.656957Z","iopub.status.idle":"2021-12-06T22:13:47.052557Z","shell.execute_reply.started":"2021-12-06T22:13:45.656911Z","shell.execute_reply":"2021-12-06T22:13:47.051487Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(data_dir + '/train.csv')\ntest = pd.read_csv(data_dir + '/test.csv')\nsample_submission = pd.read_csv(data_dir + '/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.054141Z","iopub.execute_input":"2021-12-06T22:13:47.054366Z","iopub.status.idle":"2021-12-06T22:13:47.110858Z","shell.execute_reply.started":"2021-12-06T22:13:47.054340Z","shell.execute_reply":"2021-12-06T22:13:47.109936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape, test.shape, sample_submission.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.112448Z","iopub.execute_input":"2021-12-06T22:13:47.112770Z","iopub.status.idle":"2021-12-06T22:13:47.122455Z","shell.execute_reply.started":"2021-12-06T22:13:47.112708Z","shell.execute_reply":"2021-12-06T22:13:47.121633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.124182Z","iopub.execute_input":"2021-12-06T22:13:47.124846Z","iopub.status.idle":"2021-12-06T22:13:47.149123Z","shell.execute_reply.started":"2021-12-06T22:13:47.124800Z","shell.execute_reply":"2021-12-06T22:13:47.147968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.150428Z","iopub.execute_input":"2021-12-06T22:13:47.150740Z","iopub.status.idle":"2021-12-06T22:13:47.206889Z","shell.execute_reply.started":"2021-12-06T22:13:47.150700Z","shell.execute_reply":"2021-12-06T22:13:47.206239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.207779Z","iopub.execute_input":"2021-12-06T22:13:47.208394Z","iopub.status.idle":"2021-12-06T22:13:47.226951Z","shell.execute_reply.started":"2021-12-06T22:13:47.208353Z","shell.execute_reply":"2021-12-06T22:13:47.226135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Photo Metadata**  \nThe train.csv and test.csv files contain metadata for photos in the training set and test set, respectively. Each pet photo is labeled with the value of 1 (Yes) or 0 (No) for each of the following features:  \n\n* Focus - Pet stands out against uncluttered background, not too close / far.\n* Eyes - Both eyes are facing front or near-front, with at least 1 eye / pupil decently clear.\n* Face - Decently clear face, facing front or near-front.\n* Near - Single pet taking up significant portion of photo (roughly over 50% of photo width or height).\n* Action - Pet in the middle of an action (e.g., jumping).\n* Accessory - Accompanying physical or digital accessory / prop (i.e. toy, digital sticker), excluding collar and leash.\n* Group - More than 1 pet in the photo.\n* Collage - Digitally-retouched photo (i.e. with digital photo frame, combination of multiple photos).\n* Human - Human in the photo.\n* Occlusion - Specific undesirable objects blocking part of the pet (i.e. human, cage or fence). Note that not all blocking objects are considered occlusion.\n* Info - Custom-added text or labels (i.e. pet name, description).\n* Blur - Noticeably out of focus or noisy, especially for the pet’s eyes and face. For Blur entries, “Eyes” column is always set to 0.","metadata":{}},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.228043Z","iopub.execute_input":"2021-12-06T22:13:47.228261Z","iopub.status.idle":"2021-12-06T22:13:47.237064Z","shell.execute_reply.started":"2021-12-06T22:13:47.228235Z","shell.execute_reply":"2021-12-06T22:13:47.236070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"below_original code (very thanks subinium) : https://www.kaggle.com/subinium/tps-may-categorical-eda","metadata":{}},{"cell_type":"code","source":"from cycler import cycler\n\nraw_light_palette = [\n    (0, 122, 255), # Blue\n    (255, 149, 0), # Orange\n    (52, 199, 89), # Green\n    (255, 59, 48), # Red\n    (175, 82, 222),# Purple\n    (255, 45, 85), # Pink\n    (88, 86, 214), # Indigo\n    (90, 200, 250),# Teal\n    (255, 204, 0)  # Yellow\n]\n\nraw_dark_palette = [\n    (10, 132, 255), # Blue\n    (255, 159, 10), # Orange\n    (48, 209, 88),  # Green\n    (255, 69, 58),  # Red\n    (191, 90, 242), # Purple\n    (94, 92, 230),  # Indigo\n    (255, 55, 95),  # Pink\n    (100, 210, 255),# Teal\n    (255, 214, 10)  # Yellow\n]\n\nraw_gray_light_palette = [\n    (142, 142, 147),# Gray\n    (174, 174, 178),# Gray (2)\n    (199, 199, 204),# Gray (3)\n    (209, 209, 214),# Gray (4)\n    (229, 229, 234),# Gray (5)\n    (242, 242, 247),# Gray (6)\n]\n\nraw_gray_dark_palette = [\n    (142, 142, 147),# Gray\n    (99, 99, 102),  # Gray (2)\n    (72, 72, 74),   # Gray (3)\n    (58, 58, 60),   # Gray (4)\n    (44, 44, 46),   # Gray (5)\n    (28, 28, 39),   # Gray (6)\n]\n\nlight_palette = np.array(raw_light_palette)/255\ndark_palette = np.array(raw_dark_palette)/255\ngray_light_palette = np.array(raw_gray_light_palette)/255\ngray_dark_palette = np.array(raw_gray_dark_palette)/255\n\nmpl.rcParams['axes.prop_cycle'] = cycler('color',dark_palette)\nmpl.rcParams['figure.facecolor']  = gray_dark_palette[-2]\nmpl.rcParams['figure.edgecolor']  = gray_dark_palette[-2]\nmpl.rcParams['axes.facecolor'] =  gray_dark_palette[-2]\n\nwhite_color = gray_light_palette[-2]\nmpl.rcParams['text.color'] = white_color\nmpl.rcParams['axes.labelcolor'] = white_color\nmpl.rcParams['axes.edgecolor'] = white_color\nmpl.rcParams['xtick.color'] = white_color\nmpl.rcParams['ytick.color'] = white_color\n\nmpl.rcParams['figure.dpi'] = 200\n\nmpl.rcParams['axes.spines.top'] = False\nmpl.rcParams['axes.spines.right'] = False","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.239447Z","iopub.execute_input":"2021-12-06T22:13:47.240030Z","iopub.status.idle":"2021-12-06T22:13:47.253904Z","shell.execute_reply.started":"2021-12-06T22:13:47.239994Z","shell.execute_reply":"2021-12-06T22:13:47.252829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Heatmap for the entire data\n\nfig, ax = plt.subplots(1, 1, figsize=(12, 12))\ntrain_corr = train.corr()\n\nmask = np.zeros_like(train_corr, dtype=np.bool)\nmask[np.triu_indices_from(mask)] = True\n\nsns.heatmap(train_corr, ax=ax,\n           square=True, center=0, linewidth=1,\n           cmap=sns.diverging_palette(240, 10, as_cmap=True),\n           cbar_kws={'shrink': .82},\n           mask=mask,\n           annot=True,\n           annot_kws={'size':7}\n           )\nax.set_title(f'Correlation', loc='left', fontweight='bold')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:47.255265Z","iopub.execute_input":"2021-12-06T22:13:47.256130Z","iopub.status.idle":"2021-12-06T22:13:48.300836Z","shell.execute_reply.started":"2021-12-06T22:13:47.256092Z","shell.execute_reply":"2021-12-06T22:13:48.299813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = train.drop(['Pawpularity'], axis=1)\ndf_label = train['Pawpularity'].copy()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:48.302231Z","iopub.execute_input":"2021-12-06T22:13:48.302575Z","iopub.status.idle":"2021-12-06T22:13:48.308998Z","shell.execute_reply.started":"2021-12-06T22:13:48.302545Z","shell.execute_reply":"2021-12-06T22:13:48.307961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# correlation > 0.099\n\nfig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)\nplt.figure(figsize=(14, 6))\nplt.rc('font', size=10)\n\nsns.scatterplot(data=df, x='Subject Focus', y=df_label, alpha=0.1, ax=ax0)\nsns.scatterplot(data=df, x='Accessory', y=df_label, alpha=0.1, ax=ax1)\nsns.scatterplot(data=df, x='Group', y=df_label, alpha=0.1, ax=ax2)\nsns.scatterplot(data=df, x='Blur', y=df_label, alpha=0.1, ax=ax3)\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:48.310556Z","iopub.execute_input":"2021-12-06T22:13:48.310866Z","iopub.status.idle":"2021-12-06T22:13:49.290153Z","shell.execute_reply.started":"2021-12-06T22:13:48.310824Z","shell.execute_reply":"2021-12-06T22:13:49.289527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# correlation < 0.099 : group 1 \n\nfig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)\nplt.figure(figsize=(14, 6))\nplt.rc('font', size=10)\n\nsns.scatterplot(data=df, x='Eyes', y=df_label, alpha=0.1, ax=ax0)\nsns.scatterplot(data=df, x='Face', y=df_label, alpha=0.1, ax=ax1)\nsns.scatterplot(data=df, x='Near', y=df_label, alpha=0.1, ax=ax2)\nsns.scatterplot(data=df, x='Action', y=df_label, alpha=0.1, ax=ax3)\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:49.291541Z","iopub.execute_input":"2021-12-06T22:13:49.291963Z","iopub.status.idle":"2021-12-06T22:13:50.235124Z","shell.execute_reply.started":"2021-12-06T22:13:49.291930Z","shell.execute_reply":"2021-12-06T22:13:50.234347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# correlation < 0.099 : group 2\n\nfig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)\nplt.figure(figsize=(14, 6))\nplt.rc('font', size=10)\n\nsns.scatterplot(data=df, x='Collage', y=df_label, alpha=0.1, ax=ax0)\nsns.scatterplot(data=df, x='Human', y=df_label, alpha=0.1, ax=ax1)\nsns.scatterplot(data=df, x='Occlusion', y=df_label, alpha=0.1, ax=ax2)\nsns.scatterplot(data=df, x='Info', y=df_label, alpha=0.1, ax=ax3)\n\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:50.236732Z","iopub.execute_input":"2021-12-06T22:13:50.237308Z","iopub.status.idle":"2021-12-06T22:13:51.211118Z","shell.execute_reply.started":"2021-12-06T22:13:50.237264Z","shell.execute_reply":"2021-12-06T22:13:51.209962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(x=train['Pawpularity'])","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:51.212610Z","iopub.execute_input":"2021-12-06T22:13:51.213373Z","iopub.status.idle":"2021-12-06T22:13:51.573353Z","shell.execute_reply.started":"2021-12-06T22:13:51.213321Z","shell.execute_reply":"2021-12-06T22:13:51.572532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_100 = train[train['Pawpularity'] > 90]\ntrain_100.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:51.574463Z","iopub.execute_input":"2021-12-06T22:13:51.574656Z","iopub.status.idle":"2021-12-06T22:13:51.589857Z","shell.execute_reply.started":"2021-12-06T22:13:51.574633Z","shell.execute_reply":"2021-12-06T22:13:51.589045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"attributes = ['Subject Focus', 'Blur', 'Action', 'Near', 'Collage', 'Info']\nattributes_corr = ['Subject Focus', 'Accessory', 'Group', 'Blur']\n\nscatter_matrix(train_100[attributes_corr], figsize=(12, 8))","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:51.591027Z","iopub.execute_input":"2021-12-06T22:13:51.591682Z","iopub.status.idle":"2021-12-06T22:13:53.188514Z","shell.execute_reply.started":"2021-12-06T22:13:51.591646Z","shell.execute_reply":"2021-12-06T22:13:53.187658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_100_label = train_100['Pawpularity']\ntrain_100 = train_100[attributes_corr]","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:53.189713Z","iopub.execute_input":"2021-12-06T22:13:53.190588Z","iopub.status.idle":"2021-12-06T22:13:53.196717Z","shell.execute_reply.started":"2021-12-06T22:13:53.190546Z","shell.execute_reply":"2021-12-06T22:13:53.195729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Dimension reduction Visualization \n\ntsne = manifold.TSNE(n_components=2, random_state=42)\ntransformed_data = tsne.fit_transform(train_100)\n\ntsne_df = pd.DataFrame(np.column_stack((transformed_data, train_100_label)),\n                      columns=['X', 'y', 'label']\n                      )\ntsne_df.loc[:, 'label'] = tsne_df['label'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:53.198171Z","iopub.execute_input":"2021-12-06T22:13:53.198408Z","iopub.status.idle":"2021-12-06T22:13:55.045822Z","shell.execute_reply.started":"2021-12-06T22:13:53.198374Z","shell.execute_reply":"2021-12-06T22:13:55.045142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tsne_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:55.047144Z","iopub.execute_input":"2021-12-06T22:13:55.047631Z","iopub.status.idle":"2021-12-06T22:13:55.060538Z","shell.execute_reply.started":"2021-12-06T22:13:55.047591Z","shell.execute_reply":"2021-12-06T22:13:55.059680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### F..Fireworks?","metadata":{"execution":{"iopub.status.busy":"2021-11-24T06:53:45.267815Z","iopub.execute_input":"2021-11-24T06:53:45.268367Z","iopub.status.idle":"2021-11-24T06:53:45.271812Z","shell.execute_reply.started":"2021-11-24T06:53:45.268187Z","shell.execute_reply":"2021-11-24T06:53:45.271229Z"}}},{"cell_type":"code","source":"# Cluster Visualization \n\ngrid = sns.FacetGrid(tsne_df, hue='label', size=8)\ngrid.map(plt.scatter, \"X\", 'y').add_legend()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:55.062074Z","iopub.execute_input":"2021-12-06T22:13:55.062673Z","iopub.status.idle":"2021-12-06T22:13:56.223575Z","shell.execute_reply.started":"2021-12-06T22:13:55.062543Z","shell.execute_reply":"2021-12-06T22:13:56.222780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_30 = train[(train['Pawpularity'] >= 20) & (train['Pawpularity'] <= 40)]\ntrain_30_label = train_30['Pawpularity']\ntrain_30 = train_30[attributes_corr]","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:56.224652Z","iopub.execute_input":"2021-12-06T22:13:56.224889Z","iopub.status.idle":"2021-12-06T22:13:56.233185Z","shell.execute_reply.started":"2021-12-06T22:13:56.224863Z","shell.execute_reply":"2021-12-06T22:13:56.232317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Dimension reduction Visualization \n\ntsne = manifold.TSNE(n_components=2, random_state=42)\ntransformed_data = tsne.fit_transform(train_30)\n\ntsne_df = pd.DataFrame(np.column_stack((transformed_data, train_30_label)),\n                      columns=['X', 'y', 'label']\n                      )\ntsne_df.loc[:, 'label'] = tsne_df['label'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:13:56.234677Z","iopub.execute_input":"2021-12-06T22:13:56.235026Z","iopub.status.idle":"2021-12-06T22:14:30.226909Z","shell.execute_reply.started":"2021-12-06T22:13:56.234982Z","shell.execute_reply":"2021-12-06T22:14:30.226218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Cluster Visualization (40 > Pawpularity > 30)\n\ngrid = sns.FacetGrid(tsne_df, hue='label', size=8)\ngrid.map(plt.scatter, \"X\", 'y').add_legend()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:14:30.231286Z","iopub.execute_input":"2021-12-06T22:14:30.233883Z","iopub.status.idle":"2021-12-06T22:14:32.052633Z","shell.execute_reply.started":"2021-12-06T22:14:30.233827Z","shell.execute_reply":"2021-12-06T22:14:32.051824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Several datas with different characteristics are shown in the section where the Pawpularity score is most distributed. (30, 100)","metadata":{}},{"cell_type":"markdown","source":"Original Code (Grandmaster, Tensor girl) : https://www.kaggle.com/usharengaraju/tensorflow-probability-ngboost-w-b","metadata":{}},{"cell_type":"code","source":"features = [\n    f for f in train.columns if f not in ('Id', 'Pawpularity')\n]\ntrain_features = train[features]\ndf_train = train_features.melt(value_vars=features)\n\nplt.figure(figsize=(15,7))\nsns.countplot(data=df_train, y='variable', hue='value')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-12-06T22:14:32.054726Z","iopub.execute_input":"2021-12-06T22:14:32.055328Z","iopub.status.idle":"2021-12-06T22:14:32.592727Z","shell.execute_reply.started":"2021-12-06T22:14:32.055283Z","shell.execute_reply":"2021-12-06T22:14:32.591704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}