{"cells":[{"metadata":{},"cell_type":"markdown","source":"### Importing libraries"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nfrom pathlib import Path\n\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Reading and inspecting data"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"%%time \npath=Path('../input')\ntrain=pd.read_csv(path/'train.csv')\ntest=pd.read_csv(path/'test.csv')\nstruct=pd.read_csv(path/'structures.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(f'The shape of train is {train.shape}')\nprint(f'The shape of test is {test.shape}')\nprint(f'The shape of struct is {struct.shape}')\nprint(f\"\\nThe number of NA's in train is {train.isna().sum().sum()}.\")\nprint(f\"The number of NA's in test is {test.isna().sum().sum()}.\")\nprint(f\"The number of NA's in struct is {struct.isna().sum().sum()}.\")\nprint(f\"\\nThe column names of train are \\n{train.columns}.\")\nprint(f\"\\nThe column names of test are \\n{test.columns}.\")\nprint(f\"\\nThe column names of struct are \\n{struct.columns}.\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head(20)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test.head(20)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"struct.head(20)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\n\ncols=test.columns\n\ndata=pd.concat([train[cols], test])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data.describe()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Counting values"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(f\"The number of molecules in the train set is {train['molecule_name'].nunique()}.\")\nprint(f\"The number of molecules in the test set is {test['molecule_name'].nunique()}\")\n\nprint(f\"\\nThe number of interaction types in the train set is {train['type'].nunique()}.\")\nprint(f\"The number of interaction types in the test set is {test['type'].nunique()}\")\nprint(f\"The number of interaction types in the train and test sets combined is {data['type'].nunique()}\")\n\nprint(f\"\\nThe number of atomic types in struct is {struct['atom'].nunique()}\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"types_count = data['type'].value_counts()\ntypes_order = types_count.index.values\ntypes_count","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%matplotlib inline\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nwidth = 22\nheight = 7\nfs = '24'\n\nplt.figure(figsize=(width, height))\n\nsns.set(font_scale=1.6)\n\nplt.subplot(1, 3, 1)\nsns.countplot(data['type'], order=types_order)\nplt.title('train+test', fontsize=fs)\nplt.ylabel('Counts')\n\nplt.subplot(1, 3, 2)\nsns.countplot(train['type'], order=types_order)\nplt.title('train', fontsize=fs)\nplt.ylabel('Counts')\n\nplt.subplot(1, 3, 3)\nsns.countplot(test['type'], order=types_order)\nplt.title('test', fontsize=fs)\nplt.ylabel('Counts')\n\nplt.tight_layout()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The distributions of the interaction types are very similar in train and test."},{"metadata":{"trusted":true},"cell_type":"code","source":"struct['atom'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"width = 6\nheight = 6\nfs = '20'\nfs_label = '17'\n\nplt.figure(figsize=(width, height))\n\nsns.set(font_scale=1.2)\n\nsns.countplot(x='atom', data=struct, order = struct['atom'].value_counts().index)\nplt.title(\"Atoms present in the 'struct' file\", fontsize=fs)\nplt.xlabel('Atoms', fontsize=fs_label)\nplt.ylabel('Counts', fontsize=fs_label)\n\nplt.tight_layout()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(f\"The minimum values of the 'atom_index_1' and 'atom_index_2' are {data.atom_index_0.min()}\" \\\n      f\" and {data.atom_index_1.min()}, respectively.\")\n\nprint(f\"The maximum values of the 'atom_index_1' and 'atom_index_2' are {data.atom_index_0.max()}\" \\\n      f\" and {data.atom_index_1.max()}, respectively.\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Thus, the largest number of atoms in a molecule is 29."},{"metadata":{},"cell_type":"markdown","source":"Let's take a little bit closer look at the number of atoms per molecule."},{"metadata":{"trusted":true},"cell_type":"code","source":"atom_counts = data.groupby('molecule_name').size().reset_index(name='count')\natom_counts.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"atom_counts.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(f\"The total number of molecules in train and test is {len(atom_counts)}.\")\nprint(f\"The minimum number of couplings per molecule is {np.min(atom_counts['count'].values)}.\")\nprint(f\"The maximum number of couplings per moluecule is {np.max(atom_counts['count'].values)}.\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Scalar Coupling Constants\n\nLet's take a look at the numerical values of the scalar coupling counstants in the train set. We will be groupping our observations by the interaction type.\n\nThe list of unique coupling types:"},{"metadata":{"trusted":true},"cell_type":"code","source":"coupling_types = train['type'].unique()\n\ncoupling_types","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\n\nvsize = 4\nhsize = 2\n\nplt.figure()\nfig, ax = plt.subplots(vsize,hsize,figsize=(18,20))\n\nfor (i, ct) in enumerate(coupling_types):\n    i += 1\n    plt.subplot(vsize, hsize, i)\n\n    sns.distplot(train.loc[train['type'] == ct, 'scalar_coupling_constant'], color='blue', bins=60, label=ct)\n    \n    plt.title(\"Scalar Coupling Type \"+ct, fontsize='20')\n    plt.xlabel('Scalar Coupling Constant', fontsize='16')\n    plt.ylabel('Density', fontsize='16')\n    locs, labels = plt.xticks()\n    plt.tick_params(axis='x', which='major', labelsize=16)#, pad=-40)\n    plt.tick_params(axis='y', which='major', labelsize=16)\n    #plt.legend(loc='best', fontsize='16')\n    \nplt.tight_layout()    \nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}