{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\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\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train_data=pd.read_csv(\"../input/train.csv\")\ntest_data=pd.read_csv(\"../input/test.csv\")\nml_ch=pd.read_csv(\"../input/mulliken_charges.csv\")\ndp_mts=pd.read_csv(\"../input/dipole_moments.csv\")\nstructures=pd.read_csv(\"../input/structures.csv\")\nmngt_she_tensors=pd.read_csv(\"../input/magnetic_shielding_tensors.csv\")\npot_ener=pd.read_csv(\"../input/potential_energy.csv\")\nscc=pd.read_csv(\"../input/scalar_coupling_contributions.csv\")\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"training data"},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{"trusted":true},"cell_type":"code","source":"print(train_data.shape)\nprint(train_data.molecule_name.nunique())\ntrain_data.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"about 'dsgdb9nsd_000001' molecule (CH4) "},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data[train_data['molecule_name']=='dsgdb9nsd_000001']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"unique molecules list in train"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data.atom_index_0.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mols_train=train_data['molecule_name'].unique()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"dipolements"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(dp_mts.shape)\nprint(dp_mts.molecule_name.nunique())\ndp_mts.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"dipolemoments represents complete molecule"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Mullikan charges"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(ml_ch.shape)\nprint(ml_ch.molecule_name.nunique())\nml_ch.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"structures"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(structures.shape)\nprint(structures.molecule_name.nunique())\nstructures.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"about 'dsgdb9nsd_000001' molecule (CH4)  structure"},{"metadata":{"trusted":true},"cell_type":"code","source":"structures[structures['molecule_name']=='dsgdb9nsd_000001']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"test data"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(test_data.shape)\nprint(test_data.molecule_name.nunique())\ntest_data.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"lets check atom  'dsgdb9nsd_000004' in test data"},{"metadata":{"trusted":true},"cell_type":"code","source":"test_data.atom_index_0.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_data[test_data['molecule_name']=='dsgdb9nsd_000004']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"85003+45772","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mols_test=test_data['molecule_name'].unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"(mols_train[:45772]) & (mols_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mols_test","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"total molecules in train and test is equal to 130775, which are given in total molecules in 'structure' data "},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"magnetic sheild tensors"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(mngt_she_tensors.shape)\nprint(mngt_she_tensors.molecule_name.nunique())\nmngt_she_tensors.head(10)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"about 'dsgdb9nsd_000001' molecule (CH4)  magnetic sheild tensors"},{"metadata":{"trusted":true},"cell_type":"code","source":"mngt_she_tensors[mngt_she_tensors['molecule_name']=='dsgdb9nsd_000001']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"potential energies"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(pot_ener.shape)\nprint(pot_ener.molecule_name.nunique())\npot_ener.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"potemtial energy represent about complete molecule"},{"metadata":{"trusted":true},"cell_type":"code","source":"list_of_mols_train=\ntrain_data['potential_energy']=pot_ener['molecule_name']==i","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"scalar_coupling_contributions"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(scc.shape)\nprint(scc.molecule_name.nunique())\nscc.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"scc[scc['molecule_name']=='dsgdb9nsd_000001']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"scc represents individual atom-atom and direction"},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"structures.groupby(['molecule_name','atom'])['atom'].size()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"creating dummy variable for train"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data.dtypes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data['atom_index_0']=train_data['atom_index_0'].astype('category')\ntrain_data['atom_index_1']=train_data['atom_index_1'].astype('category')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data.dtypes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data[train_data['atom_index_0']==0]\ntrain_data.drop([1600734,1600735,1600736],inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dummies_type_train=pd.get_dummies(train_data['type'])\ndummies_index0_train=pd.get_dummies(train_data['atom_index_0'],prefix='0_index')\ndummies_index1_train=pd.get_dummies(train_data['atom_index_1'],prefix='1_index')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(dummies_index0_train.shape)\nprint(dummies_index1_train.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dummies_index0_train.columns","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"creating dummy variable for test"},{"metadata":{"trusted":true},"cell_type":"code","source":"dummies_type_test=pd.get_dummies(test_data['type'])\ndummies_index0_test=pd.get_dummies(test_data['atom_index_0'],prefix='0_index')\ndummies_index1_test=pd.get_dummies(test_data['atom_index_1'],prefix='1_index')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dummies_index0_test.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(dummies_index0_test.shape)\nprint(dummies_index1_test.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data[train_data.atom_index_0=='0']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dummies_index0_train=dummies_index0_train.drop('0_index_0',axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_train=pd.concat([dummies_type_train,dummies_index0_train,dummies_index1_train],axis=1).values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_test=pd.concat([dummies_type_test,dummies_index0_test,dummies_index1_test],axis=1).values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_train=train_data['scalar_coupling_constant'].values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.linear_model import Ridge","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ridge = Ridge(alpha=0.1, normalize=True) ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ridge.fit(X_train,y_train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_pred=ridge.predict(X_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample=pd.read_csv(\"../input/sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample['scalar_coupling_constant']=y_pred","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample.to_csv('sample.csv',index=False)","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}