This project was done in the Bioinformatics lecture by Chanin Nantasenamat. You can find my notes and rearranged codes in this Project documents for better understanding while taking this course.
Part 1: Data Collection
- In this part, We’re going to learn the target protein search that we focused on if we want to have a machine learning model for discovering breast cancer drugs then we’re going to select aromatase as my protein search.
If we’re looking into Alzheimer, we might want to search for acetylcholine estrase which we’ll be using in this particular series. - We’re going to collect the data set from the ChEMBL database using the Python library (chembl_webresource_client).
- Then, we get the bioactivity data and then we’re going to pre-process that
- dropping missing data
- dropping duplicates
- labelling compounds according to bioactivity threshold
in order to obtain a curated bioactivity data.
! pip install chembl_webresource_client
# Import necessary libraries
import pandas as pd
from chembl_webresource_client.new_client import new_client
Search for Target Protein
Target search for coronavirus
# Target search for coronavirus
target = new_client.target
target_query = target.search('coronavirus')
targets = pd.DataFrame.from_dict(target_query)
targets
cross_references | organism | pref_name | score | species_group_flag | target_chembl_id | target_components | target_type | tax_id | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | [] | Coronavirus | Coronavirus | 17.0 | False | CHEMBL613732 | [] | ORGANISM | 11119 |
| 1 | [] | SARS coronavirus | SARS coronavirus | 15.0 | False | CHEMBL612575 | [] | ORGANISM | 227859 |
| 2 | [] | Feline coronavirus | Feline coronavirus | 15.0 | False | CHEMBL612744 | [] | ORGANISM | 12663 |
| 3 | [] | Human coronavirus 229E | Human coronavirus 229E | 13.0 | False | CHEMBL613837 | [] | ORGANISM | 11137 |
| 4 | [{‘xref_id’: ‘P0C6U8’, ‘xref_name’: None, ‘xre… | SARS coronavirus | SARS coronavirus 3C-like proteinase | 10.0 | False | CHEMBL3927 | [{‘accession’: ‘P0C6U8’, ‘component_descriptio… | SINGLE PROTEIN | 227859 |
| 5 | [] | Middle East respiratory syndrome-related coron… | Middle East respiratory syndrome-related coron… | 9.0 | False | CHEMBL4296578 | [] | ORGANISM | 1335626 |
| 6 | [{‘xref_id’: ‘P0C6X7’, ‘xref_name’: None, ‘xre… | SARS coronavirus | Replicase polyprotein 1ab | 4.0 | False | CHEMBL5118 | [{‘accession’: ‘P0C6X7’, ‘component_descriptio… | SINGLE PROTEIN | 227859 |
| 7 | [] | Severe acute respiratory syndrome coronavirus 2 | Replicase polyprotein 1ab | 4.0 | False | CHEMBL4523582 | [{‘accession’: ‘P0DTD1’, ‘component_descriptio… | SINGLE PROTEIN | 2697049 |
Select and retrieve bioactivity data for SARS coronavirus 3C-like proteinase
selected_target = target.target_chembl_id[4]
selected_target
'CHEMBL3927'
We will retrieve only bioactivity data for coronavirus 3C -like proteinase (CHEMBL3927) that are (CHEMBL3927) that are reported as IC$_{50}$ values in nM (nanomolar) unit.
activity = new_client.activity
res = activity.filter(target_chembl_id=selected_target).filter(standard_type="IC50")
df = pd.Dataframe.from_dixt(res)
df.head(3)
| activity_comment | activity_id | activity_properties | assay_chembl_id | assay_description | assay_type | assay_variant_accession | assay_variant_mutation | bao_endpoint | bao_format | … | target_organism | target_pref_name | target_tax_id | text_value | toid | type | units | uo_units | upper_value | value | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | None | 1480935 | [] | CHEMBL829584 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | … | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 7.2 |
| 1 | None | 1480936 | [] | CHEMBL829584 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | … | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 9.4 |
| 2 | None | 1481061 | [] | CHEMBL830868 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | … | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 13.5 |
Checking if the dataset filtered by IC50 standard type is unique.
Standard value is the potency of the drug and so the lower potency number of the drug becomes good and likewise the higher potency number of the drug becomes bad.
The lower concentration that is required the better because if you have higher number it means that you require more amount of the drug in order to produce the same inhibition at 50.
df.standard_type.unique()
array(['IC50'], dtype=object)
We will save the resulting data to a CSV file bioactivity_data.csv.
df.to_csv("bioactivity_data.csv", index= False)
Copying files to Google Drive
!pip install drive
from google.colab import drive
drive.mount("/content/drive/", force_remount= True)
! cp bioactivity_data.csv "/content/gdrive/My Drive/Colab Notebooks/data"
! ls -l "/content/gdrive/My Drive/Colab Notebooks/data"
! ls
bioactivity_data.csv gdrive sample_data
! head bioactivity_data.csv
Handling Missing Data
If any compounds has missing value for the standard_value column then drop it.
df2 = df[df.standard_value.notna()]
df2
| activity_comment | activity_id | activity_properties | assay_chembl_id | assay_description | assay_type | assay_variant_accession | assay_variant_mutation | bao_endpoint | bao_format | bao_label | canonical_smiles | data_validity_comment | data_validity_description | document_chembl_id | document_journal | document_year | ligand_efficiency | molecule_chembl_id | molecule_pref_name | parent_molecule_chembl_id | pchembl_value | potential_duplicate | qudt_units | record_id | relation | src_id | standard_flag | standard_relation | standard_text_value | standard_type | standard_units | standard_upper_value | standard_value | target_chembl_id | target_organism | target_pref_name | target_tax_id | text_value | toid | type | units | uo_units | upper_value | value | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | None | 1480935 | [] | CHEMBL829584 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | single protein format | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | None | None | CHEMBL1139624 | Bioorg. Med. Chem. Lett. | 2005 | {‘bei’: ‘18.28’, ‘le’: ‘0.33’, ‘lle’: ‘3.25’, … | CHEMBL187579 | None | CHEMBL187579 | 5.14 | False | http://www.openphacts.org/units/Nanomolar | 384103 | = | 1 | True | = | None | IC50 | nM | None | 7200.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 7.2 |
| 1 | None | 1480936 | [] | CHEMBL829584 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | single protein format | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | None | None | CHEMBL1139624 | Bioorg. Med. Chem. Lett. | 2005 | {‘bei’: ‘12.10’, ‘le’: ‘0.33’, ‘lle’: ‘1.22’, … | CHEMBL188487 | None | CHEMBL188487 | 5.03 | False | http://www.openphacts.org/units/Nanomolar | 383984 | = | 1 | True | = | None | IC50 | nM | None | 9400.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 9.4 |
| 2 | None | 1481061 | [] | CHEMBL830868 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | single protein format | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | None | None | CHEMBL1139624 | Bioorg. Med. Chem. Lett. | 2005 | {‘bei’: ‘11.56’, ‘le’: ‘0.29’, ‘lle’: ‘2.21’, … | CHEMBL185698 | None | CHEMBL185698 | 4.87 | False | http://www.openphacts.org/units/Nanomolar | 384106 | = | 1 | True | = | None | IC50 | nM | None | 13500.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 13.5 |
| 3 | None | 1481065 | [] | CHEMBL829584 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | single protein format | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | None | None | CHEMBL1139624 | Bioorg. Med. Chem. Lett. | 2005 | {‘bei’: ‘16.64’, ‘le’: ‘0.32’, ‘lle’: ‘1.25’, … | CHEMBL426082 | None | CHEMBL426082 | 4.88 | False | http://www.openphacts.org/units/Nanomolar | 384075 | = | 1 | True | = | None | IC50 | nM | None | 13110.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 13.11 |
| 4 | None | 1481066 | [] | CHEMBL829584 | In vitro inhibitory concentration against SARS… | B | None | None | BAO_0000190 | BAO_0000357 | single protein format | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | None | None | CHEMBL1139624 | Bioorg. Med. Chem. Lett. | 2005 | {‘bei’: ‘16.84’, ‘le’: ‘0.32’, ‘lle’: ‘2.16’, … | CHEMBL187717 | None | CHEMBL187717 | 5.70 | False | http://www.openphacts.org/units/Nanomolar | 384234 | = | 1 | True | = | None | IC50 | nM | None | 2000.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 2.0 |
| … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … |
| 128 | None | 12041507 | [] | CHEMBL2150313 | Inhibition of SARS-CoV PLpro expressed in Esch… | B | None | None | BAO_0000190 | BAO_0000019 | assay format | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | None | None | CHEMBL2146458 | Bioorg. Med. Chem. | 2012 | {‘bei’: ‘14.70’, ‘le’: ‘0.27’, ‘lle’: ‘1.57’, … | CHEMBL2146517 | METHYL TANSHINONATE | CHEMBL2146517 | 4.97 | False | http://www.openphacts.org/units/Nanomolar | 1727226 | = | 1 | True | = | None | IC50 | nM | None | 10600.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 10.6 |
| 129 | None | 12041508 | [] | CHEMBL2150313 | Inhibition of SARS-CoV PLpro expressed in Esch… | B | None | None | BAO_0000190 | BAO_0000019 | assay format | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | None | None | CHEMBL2146458 | Bioorg. Med. Chem. | 2012 | {‘bei’: ‘16.86’, ‘le’: ‘0.31’, ‘lle’: ‘1.56’, … | CHEMBL187460 | CRYPTOTANSHINONE | CHEMBL187460 | 5.00 | False | http://www.openphacts.org/units/Nanomolar | 1727227 | = | 1 | True | = | None | IC50 | nM | None | 10100.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 10.1 |
| 130 | None | 12041509 | [] | CHEMBL2150313 | Inhibition of SARS-CoV PLpro expressed in Esch… | B | None | None | BAO_0000190 | BAO_0000019 | assay format | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | None | None | CHEMBL2146458 | Bioorg. Med. Chem. | 2012 | {‘bei’: ‘17.88’, ‘le’: ‘0.32’, ‘lle’: ‘0.84’, … | CHEMBL363535 | TANSHINONE I | CHEMBL363535 | 4.94 | False | http://www.openphacts.org/units/Nanomolar | 1727228 | = | 1 | True | = | None | IC50 | nM | None | 11500.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 11.5 |
| 131 | None | 12041510 | [] | CHEMBL2150313 | Inhibition of SARS-CoV PLpro expressed in Esch… | B | None | None | BAO_0000190 | BAO_0000019 | assay format | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | None | None | CHEMBL2146458 | Bioorg. Med. Chem. | 2012 | {‘bei’: ‘17.86’, ‘le’: ‘0.32’, ‘lle’: ‘1.68’, … | CHEMBL227075 | DIHYDROTANSHINONE I | CHEMBL227075 | 4.97 | False | http://www.openphacts.org/units/Nanomolar | 1727229 | = | 1 | True | = | None | IC50 | nM | None | 10700.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 10.7 |
| 132 | None | 12041511 | [] | CHEMBL2150313 | Inhibition of SARS-CoV PLpro expressed in Esch… | B | None | None | BAO_0000190 | BAO_0000019 | assay format | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | None | None | CHEMBL2146458 | Bioorg. Med. Chem. | 2012 | {‘bei’: ‘14.53’, ‘le’: ‘0.27’, ‘lle’: ‘-0.01’,… | CHEMBL45830 | MILTIRONE | CHEMBL45830 | 4.10 | False | http://www.openphacts.org/units/Nanomolar | 1727230 | = | 1 | True | = | None | IC50 | nM | None | 78900.0 | CHEMBL3927 | SARS coronavirus | SARS coronavirus 3C-like proteinase | 227859 | None | None | IC50 | uM | UO_0000065 | None | 78.9 |
There is no missing data for this dataset.
Data pre-processing of bioactivity data
Labeling compounds as either being active, inactive or intermediate
We’re going to do some data pre-processing of the bioactivity data so for the benefit of creating machine learning models where we could classify compounds into three categories as either being a
- an active compound
- an inactive compound or
- an intermediate compound.
The active compound will be defined as drugs that have IC50 of less than 1000 nM. The inactive compound will be defined as drugs that IC50 of greater than 10,000 nM. Drugs having value in between 1000 nM and 10,000 nM will be called intermediate compound.
bioactivity_class = []
for i in df2.standard_value:
if float(i) >= 10000:
bioactivity_class.append("inactive")
elif float(i) <= 1000:
bioactivity_class.append("active")
else:
bioactivity_class.append("intermediate")
Iterate the molecule_chembl_id to a list
molecule_chembl_id = []
for i in df2.molecule_chembl_id:
molecule_chembl_id.append(i)
Iterate canocical_smiles to a list
canonical_smiles = []
for i in df2.canonical_smiles:
canonical_smiles.append(i)
Combine the 4 lists into a dataframe
data_tuples = list(zip(molecule_chembl_id, canonical_smiles, bioactivity_class, standard_value))
df3 = pd.DataFrame( data_tuples, columns=['molecule_chembl_id', 'canonical_smiles', 'bioactivity_class', 'standard_value'])
df3
| molecule_chembl_id | canonical_smiles | bioactivity_class | standard_value | |
|---|---|---|---|---|
| 0 | CHEMBL187579 | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | intermediate | 7200.0 |
| 1 | CHEMBL188487 | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | intermediate | 9400.0 |
| 2 | CHEMBL185698 | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | inactive | 13500.0 |
| 3 | CHEMBL426082 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | inactive | 13110.0 |
| 4 | CHEMBL187717 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | intermediate | 2000.0 |
| … | … | … | … | … |
| 128 | CHEMBL2146517 | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | inactive | 10600.0 |
| 129 | CHEMBL187460 | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | inactive | 10100.0 |
| 130 | CHEMBL363535 | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | inactive | 11500.0 |
| 131 | CHEMBL227075 | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | inactive | 10700.0 |
| 132 | CHEMBL45830 | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | inactive | 78900.0 |
Saves dataframe to CSV
df3.to_csv("bioactivity_preprocessed_data.csv", index= False)
Let’s copy to the Google Drive
! cp bioactivity_preprocessed_data.csv "/content/gdrive/My Drive/Colab Notebooks/data"
! cp bioactivity_preprocessed_data.csv "/content/gdrive/My Drive/Colab Notebooks/data"
! ls "/content/gdrive/My Drive/Colab Notebooks/data"
Part 2: Exploratory Data Analysis
- Clean the smiles notation which represent the chemical structure of the compound in the dataset
- Remove small organic compounds
- Remove salt
- Calculate Lipinski’s descriptions
- MW
- Log P
- No. H-bond donor
- No. H-bond acceptor
- Perform Exploratory Data Analysis (EDA)
- Box Plot
- Scatter Plot
- Statistical Analysis
We’re going to select only two by activity class which are the active and the inactive so that we can easily compare between the active compounds and the inactive compounds.
Install conda and rdkit
! wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh
! chmod +x Miniconda3-py37_4.8.2-Linux-x86_64.sh
! bash ./Miniconda3-py37_4.8.2-Linux-x86_64.sh -b -f -p /usr/local
! conda install -c rdkit rdkit -y
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages/')
Load bioactivity data
import pandas as pd
df = pd.read_csv("bioactivity_data_preprocessed.csv")
Calculate Lipinski descriptions
Christopher Lipinski, a scientist at Pfizer, came up with a set of rule-of-thumb for evaluating the druglikeness of compounds. Such druglikeness is based on the Absorption, Distribution, Metabolism and Excretion (ADME) that is also known as the pharmacokinetic profile. Lipinski analyzed all orally active FDA-approved drugs in the formulation of what is to be known as the Rule-of-Five or Lipinski’s Rule.
The Lipinski’s Rule stated the following:
- Molecular weight < 500 Dalton
- Octanol-water partition coefficient (LogP) < 5
- Hydrogen bond donors < 5
- Hydrogen bond acceptors < 10
Import libraries
import numpy as np
from rdkit import Chem
from rdkit.Chem import Descriptors, Lipinski
Calculate Descriptors
# Inspired by: https://codeocean.com/explore/capsules?query=tag:data-curation
def lipinski(smiles, verbose=False):
moldata= []
for elem in smiles:
mol=Chem.MolFromSmiles(elem)
moldata.append(mol)
baseData= np.arange(1,1)
i=0
for mol in moldata:
desc_MolWt = Descriptors.MolWt(mol)
desc_MolLogP = Descriptors.MolLogP(mol)
desc_NumHDonors = Lipinski.NumHDonors(mol)
desc_NumHAcceptors = Lipinski.NumHAcceptors(mol)
row = np.array([desc_MolWt,
desc_MolLogP,
desc_NumHDonors,
desc_NumHAcceptors])
if(i==0):
baseData=row
else:
baseData=np.vstack([baseData, row])
i=i+1
columnNames=["MW","LogP","NumHDonors","NumHAcceptors"]
descriptors = pd.DataFrame(data=baseData,columns=columnNames)
return descriptors
Smiles notation contains the chemical information and so what the chemical information tells us is the exact atomic details of het molecule.
df_lipinski = lipinski(df.canonical_smiles)
Combine Dataframes
df_lipinski
| MW | LogP | NumHDonors | NumHAcceptors | |
|---|---|---|---|---|
| 0 | 281.271 | 1.89262 | 0.0 | 5.0 |
| 1 | 415.589 | 3.81320 | 0.0 | 2.0 |
| 2 | 421.190 | 2.66050 | 0.0 | 4.0 |
| 3 | 293.347 | 3.63080 | 0.0 | 3.0 |
| 4 | 338.344 | 3.53900 | 0.0 | 5.0 |
| … | … | … | … | … |
| 128 | 338.359 | 3.40102 | 0.0 | 5.0 |
| 129 | 296.366 | 3.44330 | 0.0 | 3.0 |
| 130 | 276.291 | 4.09564 | 0.0 | 3.0 |
| 131 | 278.307 | 3.29102 | 0.0 | 3.0 |
| 132 | 282.383 | 4.10530 | 0.0 | 2.0 |
133 rows × 4 columns
We have 4 descriptors that are MW(molecular weight) which tells us the size, LogP which tells us the solubility and NumHDonors which tells us the relative number of the hydrogen bond donors and NumHAcceptors which tells us the relative number of the hydrogen acceptors.
df
| molecule_chembl_id | canonical_smiles | standard_value | bioactivity_class | |
|---|---|---|---|---|
| 0 | CHEMBL187579 | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | 7200.0 | inactive |
| 1 | CHEMBL188487 | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | 9400.0 | inactive |
| 2 | CHEMBL185698 | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | 13500.0 | active |
| 3 | CHEMBL426082 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | 13110.0 | active |
| 4 | CHEMBL187717 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | 2000.0 | inactive |
| … | … | … | … | … |
| 128 | CHEMBL2146517 | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | 10600.0 | NaN |
| 129 | CHEMBL187460 | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | 10100.0 | NaN |
| 130 | CHEMBL363535 | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | 11500.0 | NaN |
| 131 | CHEMBL227075 | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | 10700.0 | NaN |
| 132 | CHEMBL45830 | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | 78900.0 | NaN |
133 rows × 4 columns
df_combined = pd.concat([df,df_lipinski], axis=1)
df_combined
| molecule_chembl_id | canonical_smiles | standard_value | bioactivity_class | MW | LogP | NumHDonors | NumHAcceptors | |
|---|---|---|---|---|---|---|---|---|
| 0 | CHEMBL187579 | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | 7200.0 | inactive | 281.271 | 1.89262 | 0.0 | 5.0 |
| 1 | CHEMBL188487 | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | 9400.0 | inactive | 415.589 | 3.81320 | 0.0 | 2.0 |
| 2 | CHEMBL185698 | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | 13500.0 | active | 421.190 | 2.66050 | 0.0 | 4.0 |
| 3 | CHEMBL426082 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | 13110.0 | active | 293.347 | 3.63080 | 0.0 | 3.0 |
| 4 | CHEMBL187717 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | 2000.0 | inactive | 338.344 | 3.53900 | 0.0 | 5.0 |
| … | … | … | … | … | … | … | … | … |
| 128 | CHEMBL2146517 | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | 10600.0 | NaN | 338.359 | 3.40102 | 0.0 | 5.0 |
| 129 | CHEMBL187460 | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | 10100.0 | NaN | 296.366 | 3.44330 | 0.0 | 3.0 |
| 130 | CHEMBL363535 | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | 11500.0 | NaN | 276.291 | 4.09564 | 0.0 | 3.0 |
| 131 | CHEMBL227075 | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | 10700.0 | NaN | 278.307 | 3.29102 | 0.0 | 3.0 |
| 132 | CHEMBL45830 | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | 78900.0 | NaN | 282.383 | 4.10530 | 0.0 | 2.0 |
133 rows × 8 columns
Convert IC50 to pIC50
The reason for doing the IC50 to pIC50 transformation which is essentially the negative logarithmic transformation from IC50 value is that the original IC50 value has uneven distribution of the data points.
To allow IC50 data to be more uniformly distributed, we will convert IC50 to the negative logarithmic scale which is essentially -log10(IC50).
This custom function pIC50() will accept a DataFrame as input and will:
- Take the IC50 values from the
standard_valuecolumn and converts it from nM to M by multiplying the value by 10−9 - Take the molar value and apply -log10
- Delete the
standard_valuecolumn and create a newpIC50column
# https://github.com/chaninlab/estrogen-receptor-alpha-qsar/blob/master/02_ER_alpha_RO5.ipynb
import numpy as np
def pIC50(input):
pIC50 = []
for i in input['standard_value_norm']:
molar = i*(10**-9) # Converts nM to M
pIC50.append(-np.log10(molar))
input['pIC50'] = pIC50
x = input.drop('standard_value_norm', 1)
return x
Point to note: Values greater than 100,000,000 will be fixed at 100,000,000 otherwise the negative logarithmic value will become negative.
df_combined.standard_value.describe()
count 1.330000e+02
mean 8.017926e+12
std 3.344888e+13
min 5.000000e+01
25% 1.070000e+04
50% 2.350000e+04
75% 3.000000e+05
max 3.311311e+14
Name: standard_value, dtype: float64
-np.log10( (10**-9)* 100000000 )
1.0
-np.log10( (10**-9)* 10000000000 ) #make interpretation a bit more difficult
-1.0
def norm_value(input):
norm = []
# read through the individual values in the standard value column
for i in input['standard_value']:
# if the value is greater than 100 million it will cap the value to be hundred million
# so that the value will not exceed 100 million
# Therefore after performing negative algorithmic transformation it will not be less than 1.0.
if i > 100000000:
i = 100000000
norm.append(i)
input['standard_value_norm'] = norm
x = input.drop('standard_value', 1)
return x
Apply the norm_value() function so that the values in the standard_value is normalized.
df_norm = norm_value(df_combined)
df_norm
| molecule_chembl_id | canonical_smiles | bioactivity_class | MW | LogP | NumHDonors | NumHAcceptors | standard_value_norm | |
|---|---|---|---|---|---|---|---|---|
| 0 | CHEMBL187579 | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | inactive | 281.271 | 1.89262 | 0.0 | 5.0 | 7200.0 |
| 1 | CHEMBL188487 | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | inactive | 415.589 | 3.81320 | 0.0 | 2.0 | 9400.0 |
| 2 | CHEMBL185698 | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | active | 421.190 | 2.66050 | 0.0 | 4.0 | 13500.0 |
| 3 | CHEMBL426082 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | active | 293.347 | 3.63080 | 0.0 | 3.0 | 13110.0 |
| 4 | CHEMBL187717 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | inactive | 338.344 | 3.53900 | 0.0 | 5.0 | 2000.0 |
| … | … | … | … | … | … | … | … | … |
| 128 | CHEMBL2146517 | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | NaN | 338.359 | 3.40102 | 0.0 | 5.0 | 10600.0 |
| 129 | CHEMBL187460 | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | NaN | 296.366 | 3.44330 | 0.0 | 3.0 | 10100.0 |
| 130 | CHEMBL363535 | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | NaN | 276.291 | 4.09564 | 0.0 | 3.0 | 11500.0 |
| 131 | CHEMBL227075 | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | NaN | 278.307 | 3.29102 | 0.0 | 3.0 | 10700.0 |
| 132 | CHEMBL45830 | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | NaN | 282.383 | 4.10530 | 0.0 | 2.0 | 78900.0 |
133 rows × 8 columns
df_norm.standard_value_norm.describe()
count 1.330000e+02
mean 2.110164e+07
std 4.089714e+07
min 5.000000e+01
25% 1.070000e+04
50% 2.350000e+04
75% 3.000000e+05
max 1.000000e+08
Name: standard_value_norm, dtype: float64
We’re going to apply the PIC50 function to the normalized data frame and we’re going to call the new data frame to be df_final.
df_final = pcIC50(df_norm)
df_final
| molecule_chembl_id | canonical_smiles | bioactivity_class | MW | LogP | NumHDonors | NumHAcceptors | pIC50 | |
|---|---|---|---|---|---|---|---|---|
| 0 | CHEMBL187579 | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | inactive | 281.271 | 1.89262 | 0.0 | 5.0 | 5.142668 |
| 1 | CHEMBL188487 | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | inactive | 415.589 | 3.81320 | 0.0 | 2.0 | 5.026872 |
| 2 | CHEMBL185698 | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | active | 421.190 | 2.66050 | 0.0 | 4.0 | 4.869666 |
| 3 | CHEMBL426082 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | active | 293.347 | 3.63080 | 0.0 | 3.0 | 4.882397 |
| 4 | CHEMBL187717 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | inactive | 338.344 | 3.53900 | 0.0 | 5.0 | 5.698970 |
| … | … | … | … | … | … | … | … | … |
| 128 | CHEMBL2146517 | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | NaN | 338.359 | 3.40102 | 0.0 | 5.0 | 4.974694 |
| 129 | CHEMBL187460 | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | NaN | 296.366 | 3.44330 | 0.0 | 3.0 | 4.995679 |
| 130 | CHEMBL363535 | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | NaN | 276.291 | 4.09564 | 0.0 | 3.0 | 4.939302 |
| 131 | CHEMBL227075 | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | NaN | 278.307 | 3.29102 | 0.0 | 3.0 | 4.970616 |
| 132 | CHEMBL45830 | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | NaN | 282.383 | 4.10530 | 0.0 | 2.0 | 4.102923 |
133 rows × 8 columns
We have created a new column called pIC50 and we have already deleted the original IC50 column.
df_final.pIC50.describe()
count 133.000000
mean 4.060148
std 1.783762
min 1.000000
25% 3.522879
50% 4.628932
75% 4.970616
max 7.301030
Name: pIC50, dtype: float64
Removing the “intermediate” bioactivity class
df_2class = df_final[df_final.bioactivity_class != "intermediate"]
| molecule_chembl_id | canonical_smiles | bioactivity_class | MW | LogP | NumHDonors | NumHAcceptors | pIC50 | |
|---|---|---|---|---|---|---|---|---|
| 0 | CHEMBL187579 | Cc1noc(C)c1CN1C(=O)C(=O)c2cc(C#N)ccc21 | inactive | 281.271 | 1.89262 | 0.0 | 5.0 | 5.142668 |
| 1 | CHEMBL188487 | O=C1C(=O)N(Cc2ccc(F)cc2Cl)c2ccc(I)cc21 | inactive | 415.589 | 3.81320 | 0.0 | 2.0 | 5.026872 |
| 2 | CHEMBL185698 | O=C1C(=O)N(CC2COc3ccccc3O2)c2ccc(I)cc21 | active | 421.190 | 2.66050 | 0.0 | 4.0 | 4.869666 |
| 3 | CHEMBL426082 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2ccccc21 | active | 293.347 | 3.63080 | 0.0 | 3.0 | 4.882397 |
| 4 | CHEMBL187717 | O=C1C(=O)N(Cc2cc3ccccc3s2)c2c1cccc2[N+](=O)[O-] | inactive | 338.344 | 3.53900 | 0.0 | 5.0 | 5.698970 |
| … | … | … | … | … | … | … | … | … |
| 128 | CHEMBL2146517 | COC(=O)[C@@]1(C)CCCc2c1ccc1c2C(=O)C(=O)c2c(C)c… | NaN | 338.359 | 3.40102 | 0.0 | 5.0 | 4.974694 |
| 129 | CHEMBL187460 | C[C@H]1COC2=C1C(=O)C(=O)c1c2ccc2c1CCCC2(C)C | NaN | 296.366 | 3.44330 | 0.0 | 3.0 | 4.995679 |
| 130 | CHEMBL363535 | Cc1coc2c1C(=O)C(=O)c1c-2ccc2c(C)cccc12 | NaN | 276.291 | 4.09564 | 0.0 | 3.0 | 4.939302 |
| 131 | CHEMBL227075 | Cc1cccc2c3c(ccc12)C1=C(C(=O)C3=O)[C@@H](C)CO1 | NaN | 278.307 | 3.29102 | 0.0 | 3.0 | 4.970616 |
| 132 | CHEMBL45830 | CC(C)C1=Cc2ccc3c(c2C(=O)C1=O)CCCC3(C)C | NaN | 282.383 | 4.10530 | 0.0 | 2.0 | 4.102923 |
133 rows × 8 columns
Exploratory Data Analysis (Chemical Space Analysis) via Lipinski descriptors
We’re going to call the exploratory data analysis to be chemical space analysis because what it essentially does is it allows us to look at the chemical space.
The chemical space is kind of like a chemical universe.
Each chemical compound could be thought of as like stars.
Jose Medina Franco
Active molecules would be compared to a constellation and it will be referred to as constellation. He developed an approach which he termed constellation plot whereby you could perform chemical space analysis and create the constellation plot whereby the active molecule would be correspondingly have larger size in comparison with the less active molecule.
Import library
import seaborn as sns
sns.set(style = "ticks")
import maplotlib.pyplot as plt
Frequency plot of the 2 bioactivity classes
We’re going to create a frequency plot comparing the inactive molecules.
plt.figure(figsize=(5.5, 5.5))
sns.countplot(x='bioactivity_class', data=df_2class, edgecolor='black')
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('Frequency', fontsize=14, fontweight='bold')
plt.savefig('plot_bioactivity_class.pdf')

Scatter plot of MW versus LogP
We’re going to make a scatter plot of the molecular weight versus feed LogP or the solubility of the molecules.
plt.figure(figsize=(5.5, 5.5))
sns.scatterplot(x='MW', y='LogP', data=df_2class, hue='bioactivity_class', size='pIC50', edgecolor='black', alpha=0.7)
plt.xlabel('MW', fontsize=14, fontweight='bold')
plt.ylabel('LogP', fontsize=14, fontweight='bold')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0)
plt.savefig('plot_MW_vs_LogP.pdf')

Box Plots
pIC50 value
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'pIC50', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('pIC50 value', fontsize=14, fontweight='bold')
plt.savefig('plot_ic50.pdf')

Statistical analysis | Mann – Whitney U Test
We’re going to apply this Mann – Whitney U Test to test the statistical significance of the difference whether they are different or not different and so the code for performing the manually U Test was modified from Machine Learning Mastery
def mannwhitney(descriptor, verbose=False):
# https://machinelearningmastery.com/nonparametric-statistical-significance-tests-in-python/
from numpy.random import seed
from numpy.random import randn
from scipy.stats import mannwhitneyu
# seed the random number generator
seed(1)
# actives and inactives
selection = [descriptor, 'bioactivity_class']
df = df_2class[selection]
active = df[df.bioactivity_class == 'active']
active = active[descriptor]
selection = [descriptor, 'bioactivity_class']
df = df_2class[selection]
inactive = df[df.bioactivity_class == 'inactive']
inactive = inactive[descriptor]
# compare samples
stat, p = mannwhitneyu(active, inactive)
#print('Statistics=%.3f, p=%.3f' % (stat, p))
# interpret
alpha = 0.05
if p > alpha:
interpretation = 'Same distribution (fail to reject H0)'
else:
interpretation = 'Different distribution (reject H0)'
results = pd.DataFrame({'Descriptor':descriptor,
'Statistics':stat,
'p':p,
'alpha':alpha,
'Interpretation':interpretation}, index=[0])
filename = 'mannwhitneyu_' + descriptor + '.csv'
results.to_csv(filename)
return results
mannwhitney("PIC50")
| Descriptor | Statistics | p | alpha | Interpretation | |
|---|---|---|---|---|---|
| 0 | pIC50 | 0.0 | 1.662636e-10 | 0.05 | Different distribution (reject H0) |
MW
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'MW', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('MW', fontsize=14, fontweight='bold')
plt.savefig('plot_MW.pdf')

mannwhitney("MW")
| Descriptor | Statistics | p | alpha | Interpretation | |
|---|---|---|---|---|---|
| 0 | MW | 409.5 | 0.001525 | 0.05 | Different distribution (reject H0) |
LogP
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'LogP', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('LogP', fontsize=14, fontweight='bold')
plt.savefig('plot_LogP.pdf')

mannwhitney('LogP')
| Descriptor | Statistics | p | alpha | Interpretation | |
|---|---|---|---|---|---|
| 0 | LogP | 712.5 | 0.295805 | 0.05 | Same distribution (fail to reject H0) |
NumHDonors
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'NumHDonors', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('NumHDonors', fontsize=14, fontweight='bold')
plt.savefig('plot_NumHDonors.pdf')

mannwhitney('NumHDonors')
| Descriptor | Statistics | p | alpha | Interpretation | |
|---|---|---|---|---|---|
| 0 | NumHDonors | 299.5 | 0.000024 | 0.05 | Different distribution (reject H0) |
NumHAcceptors
plt.figure(figsize=(5.5, 5.5))
sns.boxplot(x = 'bioactivity_class', y = 'NumHAcceptors', data = df_2class)
plt.xlabel('Bioactivity class', fontsize=14, fontweight='bold')
plt.ylabel('NumHAcceptors', fontsize=14, fontweight='bold')
plt.savefig('plot_NumHAcceptors.pdf')

mannwhitney('NumHAcceptors')
| Descriptor | Statistics | p | alpha | Interpretation | |
|---|---|---|---|---|---|
| 0 | NumHAcceptors | 415.0 | 0.001557 | 0.05 | Different distribution (reject H0) |
Interpretations of Statistical
Box Plots
pIC50 values
Taking a look at pIC50 values, the actives and inactives displayed statistically significant difference, which is to be expected since threshold values (IC50 < 1,000 nM = Actives while IC50 > 10,000 nM = Inactives, corresponding to pIC50 > 6 = Actives and pIC50 < 5 = Inactives) were used to define actives and inactives.
Lipinski’s descriptors
Of the 4 Lipinski’s descriptors (MW, LogP, NumHDonors and NumHAcceptors), only LogP exhibited no difference between the actives and inactives while the other 3 descriptors (MW, NumHDonors and NumHAcceptors) shows statistically significant difference between actives and inactives.
Zip Files
! zip -r results.zip . -i *.csv *.pdf
Part 3: Descriptor calculation
- Read in CSV file as a Dataframe
- Prepare input file to PADEL-Descriptor
- Calculate fingerprints using PADEL – Descriptor
Download PaDEL – Descriptor
! wget https://github.com/dataprofessor/bioinformatics/raw/master/padel.zip
! wget https://github.com/dataprofessor/bioinformatics/raw/master/padel.sh
! unzip padel.zip
Load Bioactivity Data
! wget https://raw.githubusercontent.com/dataprofessor/data/master/acetylcholinesterase_04_bioactivity_data_3class_pIC50.csv
import pandas as pd
df3 = pd.read_csv('acetylcholinesterase_04_bioactivity_data_3class_pIC50.csv')
df3
| Unnamed: 0 | molecule_chembl_id | canonical_smiles | class | MW | LogP | NumHDonors | NumHAcceptors | pIC50 | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | CHEMBL133897 | CCOc1nn(-c2cccc(OCc3ccccc3)c2)c(=O)o1 | active | 312.325 | 2.80320 | 0.0 | 6.0 | 6.124939 |
| 1 | 1 | CHEMBL336398 | O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC1CC1 | active | 376.913 | 4.55460 | 0.0 | 5.0 | 7.000000 |
| 2 | 2 | CHEMBL131588 | CN(C(=O)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F)c1ccccc1 | inactive | 426.851 | 5.35740 | 0.0 | 5.0 | 4.301030 |
| 3 | 3 | CHEMBL130628 | O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F | active | 404.845 | 4.70690 | 0.0 | 5.0 | 6.522879 |
| 4 | 4 | CHEMBL130478 | CSc1nc(-c2ccc(OC(F)(F)F)cc2)nn1C(=O)N(C)C | active | 346.334 | 3.09530 | 0.0 | 6.0 | 6.096910 |
| … | … | … | … | … | … | … | … | … | … |
| 4690 | 4690 | CHEMBL4293155 | CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3ccccc3Cl)CC… | intermediate | 511.150 | 7.07230 | 2.0 | 3.0 | 5.612610 |
| 4691 | 4691 | CHEMBL4282558 | CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3cccc(Cl)c3)… | intermediate | 511.150 | 7.07230 | 2.0 | 3.0 | 5.595166 |
| 4692 | 4692 | CHEMBL4281727 | CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3ccc(Br)cc3)… | intermediate | 555.601 | 7.18140 | 2.0 | 3.0 | 5.419075 |
| 4693 | 4693 | CHEMBL4292349 | CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3cccc([N+](=… | intermediate | 521.702 | 6.32710 | 2.0 | 5.0 | 5.460924 |
| 4694 | 4694 | CHEMBL4278260 | CC(C)(C)c1cc(/C=C/C(=O)NCCC2CCN(Cc3ccc(C#N)cc3… | intermediate | 501.715 | 6.29058 | 2.0 | 4.0 | 5.555955 |
4695 rows × 9 columns
selection = ['canonical_smiles','molecule_chembl_id']
df3_selection = df3[selection]
df3_selection.to_csv('molecule.smi', sep='\t', index=False, header=False)
! cat molecule.smi | head -5
CCOc1nn(-c2cccc(OCc3ccccc3)c2)c(=O)o1 CHEMBL133897 O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC1CC1 CHEMBL336398 CN(C(=O)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F)c1ccccc1 CHEMBL131588 O=C(N1CCCCC1)n1nc(-c2ccc(Cl)cc2)nc1SCC(F)(F)F CHEMBL130628 CSc1nc(-c2ccc(OC(F)(F)F)cc2)nn1C(=O)N(C)C CHEMBL130478
How many molecules do we have?
! cat molecule.smi | wc -l
4695
Calculate fingerprint descriptors
Calculate PaDEL descriptors
! cat padel.sh
! bash padel.sh
! ls -l
Preparing the X and Y Data Matrices
X data matrix
df3_X = pd.read_csv('descriptors_output.csv')
df3_X
| Name | PubchemFP0 | PubchemFP1 | PubchemFP2 | PubchemFP3 | PubchemFP4 | PubchemFP5 | PubchemFP6 | PubchemFP7 | PubchemFP8 | PubchemFP9 | PubchemFP10 | PubchemFP11 | PubchemFP12 | PubchemFP13 | PubchemFP14 | PubchemFP15 | PubchemFP16 | PubchemFP17 | PubchemFP18 | PubchemFP19 | PubchemFP20 | PubchemFP21 | PubchemFP22 | PubchemFP23 | PubchemFP24 | PubchemFP25 | PubchemFP26 | PubchemFP27 | PubchemFP28 | PubchemFP29 | PubchemFP30 | PubchemFP31 | PubchemFP32 | PubchemFP33 | PubchemFP34 | PubchemFP35 | PubchemFP36 | PubchemFP37 | PubchemFP38 | … | PubchemFP841 | PubchemFP842 | PubchemFP843 | PubchemFP844 | PubchemFP845 | PubchemFP846 | PubchemFP847 | PubchemFP848 | PubchemFP849 | PubchemFP850 | PubchemFP851 | PubchemFP852 | PubchemFP853 | PubchemFP854 | PubchemFP855 | PubchemFP856 | PubchemFP857 | PubchemFP858 | PubchemFP859 | PubchemFP860 | PubchemFP861 | PubchemFP862 | PubchemFP863 | PubchemFP864 | PubchemFP865 | PubchemFP866 | PubchemFP867 | PubchemFP868 | PubchemFP869 | PubchemFP870 | PubchemFP871 | PubchemFP872 | PubchemFP873 | PubchemFP874 | PubchemFP875 | PubchemFP876 | PubchemFP877 | PubchemFP878 | PubchemFP879 | PubchemFP880 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | CHEMBL336398 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0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 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | CHEMBL130478 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … |
| 4690 | CHEMBL4293155 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4691 | CHEMBL4282558 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1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 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
4695 rows × 882 columns
df3_X = df3_X.drop(columns=['Name'])
df3_X
Y variable
Convert IC50 to pIC50
df3_Y = df3['pIC50']
df3_Y
Combining X and Y variable
dataset3 = pd.concat([df3_X,df3_Y], axis=1)
dataset3

dataset3 = pd.concat([df3_X,df3_Y], axis=1)
dataset3
| PubchemFP0 | PubchemFP1 | PubchemFP2 | PubchemFP3 | PubchemFP4 | PubchemFP5 | PubchemFP6 | PubchemFP7 | PubchemFP8 | PubchemFP9 | PubchemFP10 | PubchemFP11 | PubchemFP12 | PubchemFP13 | PubchemFP14 | PubchemFP15 | PubchemFP16 | PubchemFP17 | PubchemFP18 | PubchemFP19 | PubchemFP20 | PubchemFP21 | PubchemFP22 | PubchemFP23 | PubchemFP24 | PubchemFP25 | PubchemFP26 | PubchemFP27 | PubchemFP28 | PubchemFP29 | PubchemFP30 | PubchemFP31 | PubchemFP32 | PubchemFP33 | PubchemFP34 | PubchemFP35 | PubchemFP36 | PubchemFP37 | PubchemFP38 | PubchemFP39 | … | PubchemFP842 | PubchemFP843 | PubchemFP844 | PubchemFP845 | PubchemFP846 | PubchemFP847 | PubchemFP848 | PubchemFP849 | PubchemFP850 | PubchemFP851 | PubchemFP852 | PubchemFP853 | PubchemFP854 | PubchemFP855 | PubchemFP856 | PubchemFP857 | PubchemFP858 | PubchemFP859 | PubchemFP860 | PubchemFP861 | PubchemFP862 | PubchemFP863 | PubchemFP864 | PubchemFP865 | PubchemFP866 | PubchemFP867 | PubchemFP868 | PubchemFP869 | PubchemFP870 | PubchemFP871 | PubchemFP872 | PubchemFP873 | PubchemFP874 | PubchemFP875 | PubchemFP876 | PubchemFP877 | PubchemFP878 | PubchemFP879 | PubchemFP880 | pIC50 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6.124939 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7.000000 |
| 2 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4.301030 |
| 3 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6.522879 |
| 4 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6.096910 |
| … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | …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 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5.460924 |
| 4694 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5.555955 |
4695 rows × 882 columns
dataset3.to_csv('acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv', index=False)
Part 4: Model Building
- Read in CSV file as a Dataframe
- Remove low variance features
- Data Splitting
- Build Regression Model
- Make a scatter plot
Import libraries
import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
Load the data set
❓ In Part 3, we have prepared a pop-can fingerprint and in Part 2, we have prepared Lipinski descriptors and then the question was what’s the difference between these two?
➕ Firstly the descriptor will provide us with a set of simple molecular descriptors that essentially will be giving us a quick overview of the drop light properties of the molecule.
➕ So, historically Christopher Lipinski created a set of four descriptors that the had investigated in his research that are responsible for drop light properties whereby the analyzed a set of orally active drugs and then he came up with his rule of five will make good oral drugs.
➕ For the top ten fingerprints which we will be using as well for the model building. It is describing the local features of the molecules so that Lipinski descriptor will be describing the global features of the molecule particularly the molecular size of the molecule the solubility of the molecule and also the number of hydrogen bond donor and acceptor which is the propensity to accept and donate hydrogen bonds.
! wget https://github.com/dataprofessor/data/raw/master/acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv
df = pd.read_csv('acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv')
Features
The Acetylcholinesterase data set contains 881 input features and 1 output variable (pIC50 values).
Each molecule will be given a unique fingerprint kind of like each of us humans fingerprint kind of like each of humans have unique fingerprint. So the unique fingerprints of each molecule will allow the machine learning algorithm to learn from the unique properties in terms of the molecular properties of the compound and then create a model that will be able to distinguish between compounds that are active compounds that are inactive.
❗ This is the goal of our model building we want to see which functional group of fingerprints are essential for designing a good drug or a potent one.
So target variable that we are using for our prediction is called pIC50 which is the negative logarithm of IC50 value.
Input features
X = df.drop('pIC50', axis=1)
X
| PubchemFP0 | PubchemFP1 | PubchemFP2 | PubchemFP3 | PubchemFP4 | PubchemFP5 | PubchemFP6 | PubchemFP7 | PubchemFP8 | PubchemFP9 | PubchemFP10 | PubchemFP11 | PubchemFP12 | PubchemFP13 | PubchemFP14 | PubchemFP15 | PubchemFP16 | PubchemFP17 | PubchemFP18 | PubchemFP19 | PubchemFP20 | PubchemFP21 | PubchemFP22 | PubchemFP23 | PubchemFP24 | PubchemFP25 | PubchemFP26 | PubchemFP27 | PubchemFP28 | PubchemFP29 | PubchemFP30 | PubchemFP31 | PubchemFP32 | PubchemFP33 | PubchemFP34 | PubchemFP35 | PubchemFP36 | PubchemFP37 | PubchemFP38 | PubchemFP39 | … | PubchemFP841 | PubchemFP842 | PubchemFP843 | PubchemFP844 | PubchemFP845 | PubchemFP846 | PubchemFP847 | PubchemFP848 | PubchemFP849 | PubchemFP850 | PubchemFP851 | PubchemFP852 | PubchemFP853 | PubchemFP854 | PubchemFP855 | PubchemFP856 | PubchemFP857 | PubchemFP858 | PubchemFP859 | PubchemFP860 | PubchemFP861 | PubchemFP862 | PubchemFP863 | PubchemFP864 | PubchemFP865 | PubchemFP866 | PubchemFP867 | PubchemFP868 | PubchemFP869 | PubchemFP870 | PubchemFP871 | PubchemFP872 | PubchemFP873 | PubchemFP874 | PubchemFP875 | PubchemFP876 | PubchemFP877 | PubchemFP878 | PubchemFP879 | PubchemFP880 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 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| … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … |
| 4690 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4691 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4692 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4693 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4694 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | … | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
4695 rows × 881 columns
Output Features
Y = df.pIC50
Y

Let’s examine the data dimension
X.shape
(4695, 881)
Y.shape
(4695,)
Remove low variance features
from sklearn.feature_selection import VarianceThreshold
selection = VarianceThreshold(threshold=(.8 * (1 - .8)))
X = selection.fit_transform(X)
X.shape
(4695, 137)
Data split (80 / 20 ratio)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)
X_train.shape, Y_train.shape
((3756, 137), (3756,))
X_test.shape, Y_test.shape
((939, 137), (939,))
Building a Regression Model using Random Forest
model = RandomForestRegressor(n_estimators=100)
model.fit(X_train, Y_train)
r2 = model.score(X_test, Y_test)
r2
0.540922477079912
Y_pred = model.predict(X_test)
Scatter Plot of Experimental vs Predicted pIC50 Values
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(color_codes=True)
sns.set_style("white")
ax = sns.regplot(Y_test, Y_pred, scatter_kws={'alpha':0.4})
ax.set_xlabel('Experimental pIC50', fontsize='large', fontweight='bold')
ax.set_ylabel('Predicted pIC50', fontsize='large', fontweight='bold')
ax.set_xlim(0, 12)
ax.set_ylim(0, 12)
ax.figure.set_size_inches(5, 5)
plt.show

Part 5: Model Comparison
- Read in CSV files as a Dataframe
- Remove low variance features
- Data Splitting
- Build Several Regression Models
- Make a performance comparison plot
Import Libraries
!pip install lazypredict
import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
import lazypredict
from lazypredict.Supervised import LazyRegressor
Load the data set
! wget https://github.com/dataprofessor/data/raw/master/acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv
df = pd.read_csv('acetylcholinesterase_06_bioactivity_data_3class_pIC50_pubchem_fp.csv')
X = df.drop('pIC50', axis=1)
Y = df.pIC50
Data pre-processing
# Examine X dimension
X.shape
(4695, 881)
# Remove low variance features
from sklearn.feature_selection import VarianceThreshold
selection = VarianceThreshold(threshold=(.8 * (1 - .8)))
X = selection.fit_transform(X)
X.shape
(4695, 137)
# Perform data splitting using 80/20 ratio
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)
Compare ML Algorithms
# Defines and builds the lazyclassifier
clf = LazyRegressor(verbose=0,ignore_warnings=True, custom_metric=None)
models_train,predictions_train = clf.fit(X_train, X_train, Y_train, Y_train)
models_test,predictions_test = clf.fit(X_train, X_test, Y_train, Y_test)
# Performance table of the training set (80% subset)
predictions_train
| Adjusted R-Squared | R-Squared | RMSE | Time Taken | |
|---|---|---|---|---|
| Model | ||||
| ExtraTreesRegressor | 0.86 | 0.86 | 0.57 | 5.98 |
| DecisionTreeRegressor | 0.86 | 0.86 | 0.57 | 0.17 |
| ExtraTreeRegressor | 0.86 | 0.86 | 0.57 | 0.14 |
| GaussianProcessRegressor | 0.86 | 0.86 | 0.57 | 5.03 |
| RandomForestRegressor | 0.82 | 0.83 | 0.64 | 4.70 |
| XGBRegressor | 0.82 | 0.83 | 0.65 | 2.12 |
| BaggingRegressor | 0.80 | 0.81 | 0.67 | 0.59 |
| MLPRegressor | 0.76 | 0.77 | 0.75 | 6.38 |
| HistGradientBoostingRegressor | 0.67 | 0.69 | 0.87 | 3.40 |
| LGBMRegressor | 0.67 | 0.69 | 0.87 | 0.44 |
| KNeighborsRegressor | 0.63 | 0.65 | 0.92 | 2.97 |
| SVR | 0.56 | 0.58 | 1.01 | 6.54 |
| NuSVR | 0.55 | 0.57 | 1.02 | 4.91 |
| GradientBoostingRegressor | 0.44 | 0.46 | 1.14 | 1.71 |
| Ridge | 0.31 | 0.33 | 1.27 | 0.06 |
| LinearRegression | 0.31 | 0.33 | 1.27 | 0.11 |
| TransformedTargetRegressor | 0.31 | 0.33 | 1.27 | 0.10 |
| LassoCV | 0.30 | 0.33 | 1.27 | 3.63 |
| ElasticNetCV | 0.30 | 0.33 | 1.27 | 3.49 |
| RidgeCV | 0.30 | 0.33 | 1.27 | 0.19 |
| SGDRegressor | 0.30 | 0.32 | 1.28 | 0.19 |
| BayesianRidge | 0.29 | 0.32 | 1.28 | 0.15 |
| HuberRegressor | 0.29 | 0.31 | 1.29 | 0.66 |
| LassoLarsCV | 0.28 | 0.31 | 1.29 | 0.56 |
| LassoLarsIC | 0.28 | 0.31 | 1.29 | 0.14 |
| LinearSVR | 0.27 | 0.30 | 1.30 | 0.77 |
| PoissonRegressor | 0.25 | 0.28 | 1.32 | 0.12 |
| AdaBoostRegressor | 0.20 | 0.23 | 1.36 | 0.89 |
| OrthogonalMatchingPursuit | 0.20 | 0.23 | 1.37 | 0.08 |
| OrthogonalMatchingPursuitCV | 0.20 | 0.23 | 1.37 | 0.18 |
| GeneralizedLinearRegressor | 0.19 | 0.22 | 1.37 | 0.07 |
| TweedieRegressor | 0.19 | 0.22 | 1.37 | 0.09 |
| GammaRegressor | 0.19 | 0.22 | 1.37 | 0.07 |
| Lars | 0.19 | 0.22 | 1.37 | 0.15 |
| LarsCV | 0.12 | 0.15 | 1.43 | 0.54 |
| Lasso | -0.04 | 0.00 | 1.55 | 0.07 |
| ElasticNet | -0.04 | 0.00 | 1.55 | 0.06 |
| DummyRegressor | -0.04 | 0.00 | 1.55 | 0.04 |
| LassoLars | -0.04 | 0.00 | 1.55 | 0.07 |
| PassiveAggressiveRegressor | -0.17 | -0.13 | 1.65 | 0.14 |
| KernelRidge | -14.25 | -13.70 | 5.95 | 1.41 |
| RANSACRegressor | -808435070627303626113024.00 | -778939570047825400037376.00 | 1370167375456.90 | 1.18 |
# Performance table of the test set (20% subset)
predictions_test
| R-Squared | RMSE | Time Taken | |
|---|---|---|---|
| Model | |||
| HistGradientBoostingRegressor | 0.54 | 1.06 | 2.13 |
| LGBMRegressor | 0.54 | 1.06 | 0.46 |
| RandomForestRegressor | 0.52 | 1.08 | 4.56 |
| BaggingRegressor | 0.48 | 1.12 | 0.54 |
| NuSVR | 0.48 | 1.12 | 3.47 |
| SVR | 0.48 | 1.12 | 4.29 |
| KNeighborsRegressor | 0.46 | 1.14 | 0.97 |
| MLPRegressor | 0.45 | 1.15 | 6.73 |
| GradientBoostingRegressor | 0.42 | 1.18 | 1.70 |
| XGBRegressor | 0.42 | 1.18 | 1.17 |
| ExtraTreesRegressor | 0.34 | 1.26 | 5.89 |
| Ridge | 0.32 | 1.28 | 0.04 |
| RidgeCV | 0.32 | 1.28 | 0.13 |
| ElasticNetCV | 0.32 | 1.28 | 3.75 |
| LassoCV | 0.32 | 1.28 | 3.95 |
| ExtraTreeRegressor | 0.31 | 1.29 | 0.12 |
| SGDRegressor | 0.31 | 1.29 | 0.18 |
| TransformedTargetRegressor | 0.31 | 1.29 | 0.07 |
| LinearRegression | 0.31 | 1.29 | 0.08 |
| BayesianRidge | 0.31 | 1.29 | 0.16 |
| LassoLarsCV | 0.31 | 1.29 | 0.45 |
| LassoLarsIC | 0.31 | 1.29 | 0.09 |
| HuberRegressor | 0.31 | 1.29 | 0.61 |
| LinearSVR | 0.29 | 1.31 | 0.73 |
| DecisionTreeRegressor | 0.28 | 1.31 | 0.16 |
| OrthogonalMatchingPursuit | 0.24 | 1.36 | 0.04 |
| OrthogonalMatchingPursuitCV | 0.24 | 1.36 | 0.12 |
| Lars | 0.21 | 1.38 | 0.10 |
| AdaBoostRegressor | 0.21 | 1.38 | 0.77 |
| LarsCV | 0.15 | 1.43 | 0.46 |
| Lasso | -0.00 | 1.55 | 0.05 |
| ElasticNet | -0.00 | 1.55 | 0.03 |
| DummyRegressor | -0.00 | 1.55 | 0.03 |
| LassoLars | -0.00 | 1.55 | 0.05 |
| PassiveAggressiveRegressor | -0.22 | 1.71 | 0.09 |
| GaussianProcessRegressor | -4.99 | 3.80 | 3.88 |
| KernelRidge | -13.82 | 5.98 | 1.28 |
| RANSACRegressor | -225543784142202044678144.00 | 737597884681.01 | 1.13 |
Data Visualization of Model performance
# Bar plot of R-squared values
import matplotlib.pyplot as plt
import seaborn as sns
#train["R-Squared"] = [0 if i < 0 else i for i in train.iloc[:,0] ]
plt.figure(figsize=(5, 10))
sns.set_theme(style="whitegrid")
ax = sns.barplot(y=predictions_train.index, x="R-Squared", data=predictions_train)
ax.set(xlim=(0, 1))
[(0.0, 1.0)]

# Bar plot of RMSE values
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(5, 10))
sns.set_theme(style="whitegrid")
ax = sns.barplot(y=predictions_train.index, x="RMSE", data=predictions_train)
ax.set(xlim=(0, 10))
[(0.0, 10.0)]

# Bar plot of calculation time
import matplotlib.pyplot as plt
import seaborn as sns
plt.figure(figsize=(5, 10))
sns.set_theme(style="whitegrid")
ax = sns.barplot(y=predictions_train.index, x="Time Taken", data=predictions_train,
order = predictions_train.sort_values("Time Taken").index)
ax.set(xlim=(0, 10))
[(0.0, 10.0)]

Part 6: Model Deployment
- Build Regression Model from Part 4
- Code the Web app -> Save Model to file
Leave a Reply