Datasets:
Commit
·
edad6ca
1
Parent(s):
ae9f179
Upload dataset and scripts
Browse files- .DS_Store +0 -0
- README.md +54 -3
- scripts/.DS_Store +0 -0
- scripts/.ipynb_checkpoints/Rdkit_descriptor-checkpoint.py +0 -0
- scripts/.ipynb_checkpoints/change_type-checkpoint.py +0 -0
- scripts/.ipynb_checkpoints/clean_data-checkpoint.py +0 -0
- scripts/.ipynb_checkpoints/model_construction-checkpoint.ipynb +0 -0
- scripts/.ipynb_checkpoints/split_dataset-checkpoint.py +0 -0
- scripts/.ipynb_checkpoints/untitled-checkpoint.py +0 -0
- scripts/.virtual_documents/model_construction.ipynb +187 -0
- scripts/Rdkit_descriptor.py +27 -0
- scripts/clean_data.py +24 -0
- scripts/model_analysis.py +121 -0
- scripts/model_constrcution.py +87 -0
- scripts/model_construction.ipynb +0 -0
- scripts/split_dataset.py +16 -0
.DS_Store
ADDED
|
Binary file (10.2 kB). View file
|
|
|
README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
pretty_name: Drug-Likeness RDKit Dataset
|
| 4 |
+
tags:
|
| 5 |
+
- cheminformatics
|
| 6 |
+
- rdkit
|
| 7 |
+
- drug-likeness
|
| 8 |
+
- classification
|
| 9 |
+
- AutoML
|
| 10 |
+
task_categories:
|
| 11 |
+
- classification
|
| 12 |
+
task_ids:
|
| 13 |
+
- binary-classification
|
| 14 |
+
source_datasets:
|
| 15 |
+
- DBPP-Predictor(https://github.com/yxgu2353/DBPP-Predictor.git)
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# Drug-Likeness Prediction Dataset (Based on DBPP-Predictor Data)
|
| 19 |
+
|
| 20 |
+
This dataset was created as part of a final project on drug-likeness prediction, based on the data from the DBPP-Predictor paper:
|
| 21 |
+
|
| 22 |
+
> Gu, Y., Wang, Y., Zhu, K. et al. DBPP-Predictor: a novel strategy for prediction of chemical drug-likeness based on property profiles. J Cheminform 16, 4 (2024). https://doi.org/10.1186/s13321-024-00800-9
|
| 23 |
+
|
| 24 |
+
It includes curated molecular data, preprocessed RDKit descriptors, and training/test splits suitable for training classification models to distinguish drug-like from non-drug-like molecules.
|
| 25 |
+
|
| 26 |
+
## Project Background
|
| 27 |
+
|
| 28 |
+
Drug-likeness refers to the potential of a small molecule to become a drug. Traditional rule-based approaches (e.g., Lipinski's Rule of Five) often fail to generalize across complex compounds. This project uses RDKit descriptors and AutoML (H2O) to construct a highly interpretable, generalizable classification model.
|
| 29 |
+
|
| 30 |
+
## Dataset Description
|
| 31 |
+
|
| 32 |
+
The dataset is derived from the DBPP GitHub repository (https://github.com/yxgu2353/DBPP-Predictor.git). It includes:
|
| 33 |
+
- 5,147 drug-like molecules (FDA and globally approved drugs)
|
| 34 |
+
- 10,000 non-drug-like molecules sampled from ZINC
|
| 35 |
+
|
| 36 |
+
All molecules were standardized using MolVS(clean_data.py), the datasets were split by sklearn(split_dataset.py), and RDKit descriptors (216 features) were computed (Rdkit_descriptor.py).
|
| 37 |
+
|
| 38 |
+
### Files:
|
| 39 |
+
- 'train.parquet': Raw training set (SMILES + labels)
|
| 40 |
+
- 'test.parquet': Raw test set (SMILES + labels)
|
| 41 |
+
- 'train_rdkit_descriptors.parquet': RDKit descriptors for training data
|
| 42 |
+
- 'test_rdkit_descriptors.parquet': RDKit descriptors for test data
|
| 43 |
+
|
| 44 |
+
Each descriptor file contains:
|
| 45 |
+
- 'label': 0 for non-drug, 1 for drug
|
| 46 |
+
- 'Standardized_SMILES'
|
| 47 |
+
- 216 numerical RDKit descriptors
|
| 48 |
+
|
| 49 |
+
## Model Development
|
| 50 |
+
|
| 51 |
+
All models were trained using H2O AutoML with 10-fold cross-validation(model_constrcution.py). The top 3 models were also evaluated using an independent test set, and SHAP analysis was used to interpret the top structural features contributing to drug-likeness(model_analysis.py).
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
scripts/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
scripts/.ipynb_checkpoints/Rdkit_descriptor-checkpoint.py
ADDED
|
File without changes
|
scripts/.ipynb_checkpoints/change_type-checkpoint.py
ADDED
|
File without changes
|
scripts/.ipynb_checkpoints/clean_data-checkpoint.py
ADDED
|
File without changes
|
scripts/.ipynb_checkpoints/model_construction-checkpoint.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/.ipynb_checkpoints/split_dataset-checkpoint.py
ADDED
|
File without changes
|
scripts/.ipynb_checkpoints/untitled-checkpoint.py
ADDED
|
File without changes
|
scripts/.virtual_documents/model_construction.ipynb
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import h2o
|
| 5 |
+
from h2o.automl import H2OAutoML
|
| 6 |
+
import pyarrow as pa
|
| 7 |
+
import pyarrow.parquet as pq
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
h2o.init()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
df_train = pd.read_csv("./intermediate/train_rdkit_descriptors.csv")
|
| 14 |
+
df_test = pd.read_csv("./intermediate/test_rdkit_descriptors.csv")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
x_train = df_train.drop(columns=["label", "Standardized_SMILES"])
|
| 18 |
+
y_train = df_train["label"]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
x_test = df_test.drop(columns=["label", "Standardized_SMILES"])
|
| 22 |
+
y_test = df_test["label"]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
train_h2o = h2o.H2OFrame(pd.concat([x_train, y_train], axis=1))
|
| 26 |
+
test_h2o = h2o.H2OFrame(pd.concat([x_test, y_test], axis=1))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
train_h2o["label"] = train_h2o["label"].asfactor()
|
| 30 |
+
test_h2o["label"] = test_h2o["label"].asfactor()
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
feature_cols = x_train.columns.tolist()
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
aml = H2OAutoML(max_models=20,seed=42,nfolds=10,sort_metric="AUC")
|
| 37 |
+
aml.train(x=feature_cols, y="label", training_frame=train_h2o)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
lb = aml.leaderboard
|
| 41 |
+
lb.head(rows=lb.nrows)
|
| 42 |
+
best_model = aml.leader
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
top_3_models = lb.as_data_frame()["model_id"].head(3).tolist()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
top_3_models
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
for i, model_id in enumerate(top_3_models, start=1):
|
| 52 |
+
model = h2o.get_model(model_id)
|
| 53 |
+
model_path = h2o.save_model(model=model, path=f"../product/top_model_{i}", force=True)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
model_ids = lb.as_data_frame()["model_id"].tolist()
|
| 57 |
+
all_model_summaries = []
|
| 58 |
+
for model_id in model_ids:
|
| 59 |
+
model = h2o.get_model(model_id)
|
| 60 |
+
cv_summary = model.cross_validation_metrics_summary().as_data_frame()
|
| 61 |
+
cv_summary["model_id"] = model_id
|
| 62 |
+
all_model_summaries.append(cv_summary)
|
| 63 |
+
|
| 64 |
+
cv_all_models_df = pd.concat(all_model_summaries, ignore_index=True)
|
| 65 |
+
cv_all_models_df.to_csv("../intermediate/cross_validation_result.csv",index=False)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
from h2o import load_model
|
| 72 |
+
restored_model1 = h2o.load_model("./product/top_model_1/StackedEnsemble_AllModels_1_AutoML_1_20250401_220205")
|
| 73 |
+
restored_model2 = h2o.load_model("./product/top_model_2/StackedEnsemble_BestOfFamily_1_AutoML_1_20250401_220205")
|
| 74 |
+
restored_model3 = h2o.load_model("./product/top_model_3/GBM_4_AutoML_1_20250401_220205")
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
perf1=restored_model1.model_performance(test_h2o)
|
| 78 |
+
perf2=restored_model2.model_performance(test_h2o)
|
| 79 |
+
perf3=restored_model3.model_performance(test_h2o)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
threshold = 0.5
|
| 86 |
+
acc = perf1.accuracy(thresholds=[threshold])[0][1]
|
| 87 |
+
f1 = perf1.F1(thresholds=[threshold])[0][1]
|
| 88 |
+
prec = perf1.precision(thresholds=[threshold])[0][1]
|
| 89 |
+
rec = perf1.recall(thresholds=[threshold])[0][1]
|
| 90 |
+
spec = perf1.specificity(thresholds=[threshold])[0][1]
|
| 91 |
+
print(f"Threshold = {threshold}")
|
| 92 |
+
print(f"Accuracy = {acc:.4f}")
|
| 93 |
+
print(f"F1 Score = {f1:.4f}")
|
| 94 |
+
print(f"Precision = {prec:.4f}")
|
| 95 |
+
print(f"Recall = {rec:.4f}")
|
| 96 |
+
print(f"Specificity = {spec:.4f}")
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
metrics1 = {
|
| 100 |
+
"AUC": perf1.auc(),
|
| 101 |
+
"LogLoss": perf1.logloss(),
|
| 102 |
+
"Accuracy": perf1.accuracy(),
|
| 103 |
+
"F1": perf1.F1(),
|
| 104 |
+
"Precision": perf1.precision(),
|
| 105 |
+
"Recall": perf1.recall(),
|
| 106 |
+
"Specificity": perf1.specificity()
|
| 107 |
+
}
|
| 108 |
+
metrics1
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
perf1.plot(type="roc")
|
| 112 |
+
perf1.plot(type="pr")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
threshold = 0.5
|
| 119 |
+
acc = perf2.accuracy(thresholds=[threshold])[0][1]
|
| 120 |
+
f1 = perf2.F1(thresholds=[threshold])[0][1]
|
| 121 |
+
prec = perf2.precision(thresholds=[threshold])[0][1]
|
| 122 |
+
rec = perf2.recall(thresholds=[threshold])[0][1]
|
| 123 |
+
spec = perf2.specificity(thresholds=[threshold])[0][1]
|
| 124 |
+
print(f"Threshold = {threshold}")
|
| 125 |
+
print(f"Accuracy = {acc:.4f}")
|
| 126 |
+
print(f"F1 Score = {f1:.4f}")
|
| 127 |
+
print(f"Precision = {prec:.4f}")
|
| 128 |
+
print(f"Recall = {rec:.4f}")
|
| 129 |
+
print(f"Specificity = {spec:.4f}")
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
metrics2 = {
|
| 133 |
+
"AUC": perf2.auc(),
|
| 134 |
+
"LogLoss": perf2.logloss(),
|
| 135 |
+
"Accuracy": perf2.accuracy(),
|
| 136 |
+
"F1": perf2.F1(),
|
| 137 |
+
"Precision": perf2.precision(),
|
| 138 |
+
"Recall": perf2.recall(),
|
| 139 |
+
"Specificity": perf2.specificity()
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
metrics2
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
perf2.plot(type="roc")
|
| 147 |
+
perf2.plot(type="pr")
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
threshold = 0.5
|
| 154 |
+
acc = perf3.accuracy(thresholds=[threshold])[0][1]
|
| 155 |
+
f1 = perf3.F1(thresholds=[threshold])[0][1]
|
| 156 |
+
prec = perf3.precision(thresholds=[threshold])[0][1]
|
| 157 |
+
rec = perf3.recall(thresholds=[threshold])[0][1]
|
| 158 |
+
spec = perf3.specificity(thresholds=[threshold])[0][1]
|
| 159 |
+
print(f"Threshold = {threshold}")
|
| 160 |
+
print(f"Accuracy = {acc:.4f}")
|
| 161 |
+
print(f"F1 Score = {f1:.4f}")
|
| 162 |
+
print(f"Precision = {prec:.4f}")
|
| 163 |
+
print(f"Recall = {rec:.4f}")
|
| 164 |
+
print(f"Specificity = {spec:.4f}")
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
metrics3 = {
|
| 168 |
+
"AUC": perf3.auc(),
|
| 169 |
+
"LogLoss": perf3.logloss(),
|
| 170 |
+
"Accuracy": perf3.accuracy(),
|
| 171 |
+
"F1": perf3.F1(),
|
| 172 |
+
"Precision": perf3.precision(),
|
| 173 |
+
"Recall": perf3.recall(),
|
| 174 |
+
"Specificity": perf3.specificity()
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
metrics3
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
perf3.plot(type="roc")
|
| 182 |
+
perf3.plot(type="pr")
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
restored_model3.shap_summary_plot(test_h2o[:,:-1])
|
| 186 |
+
fig = plt.gcf()
|
| 187 |
+
fig.savefig("./product/3shap_summary_plot.png", dpi=300, bbox_inches="tight")
|
scripts/Rdkit_descriptor.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
from rdkit import Chem
|
| 4 |
+
from rdkit.Chem import Descriptors
|
| 5 |
+
|
| 6 |
+
df_train = pd.read_csv("./intermediate/train.csv")
|
| 7 |
+
df_test = pd.read_csv("./intermediate/test.csv")
|
| 8 |
+
df_train = df_train.drop(['SMILES'], axis=1)
|
| 9 |
+
df_test = df_test.drop(['SMILES'], axis=1)
|
| 10 |
+
|
| 11 |
+
descriptor_names = [desc_name for desc_name, _ in Descriptors.descList]
|
| 12 |
+
len(descriptor_names)
|
| 13 |
+
|
| 14 |
+
def calculate_rdkit_descriptors(smiles):
|
| 15 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 16 |
+
if mol is None:
|
| 17 |
+
return None
|
| 18 |
+
return {desc_name: func(mol) for desc_name, func in Descriptors.descList}
|
| 19 |
+
|
| 20 |
+
df_train_descriptors = df_train["Standardized_SMILES"].apply(calculate_rdkit_descriptors)
|
| 21 |
+
df_test_descriptors = df_test["Standardized_SMILES"].apply(calculate_rdkit_descriptors)
|
| 22 |
+
df_train_descriptors = pd.DataFrame(df_train_descriptors.tolist())
|
| 23 |
+
df_test_descriptors = pd.DataFrame(df_test_descriptors.tolist())
|
| 24 |
+
df_train_final = pd.concat([df_train, df_train_descriptors], axis=1)
|
| 25 |
+
df_test_final = pd.concat([df_test, df_test_descriptors], axis=1)
|
| 26 |
+
df_train_final.to_csv("./intermediate/train_rdkit_descriptors.csv", index=False)
|
| 27 |
+
df_test_final.to_csv("./intermediate/test_rdkit_descriptors.csv", index=False)
|
scripts/clean_data.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rdkit import Chem
|
| 2 |
+
from molvs import Standardizer
|
| 3 |
+
import pandas as pd
|
| 4 |
+
df0 = pd.read_csv("data/negative.csv")
|
| 5 |
+
df1 = pd.read_csv("data/positive.csv")
|
| 6 |
+
s = Standardizer()
|
| 7 |
+
|
| 8 |
+
def standardize_smiles(smiles):
|
| 9 |
+
try:
|
| 10 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 11 |
+
if mol:
|
| 12 |
+
clean_mol = s.fragment_parent(mol)
|
| 13 |
+
standardized_mol = s.standardize(clean_mol)
|
| 14 |
+
return Chem.MolToSmiles(standardized_mol)
|
| 15 |
+
except:
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
df0["Standardized_SMILES"] = df0.iloc[:,0].apply(standardize_smiles)
|
| 19 |
+
df0 = df0.dropna(subset=["Standardized_SMILES"])
|
| 20 |
+
df0.to_csv("intermediate/cleaned_negative.csv", index=False)
|
| 21 |
+
|
| 22 |
+
df1["Standardized_SMILES"] = df1.iloc[:,0].apply(standardize_smiles)
|
| 23 |
+
df1 = df1.dropna(subset=["Standardized_SMILES"])
|
| 24 |
+
df1.to_csv("intermediate/cleaned_positive.csv", index=False)
|
scripts/model_analysis.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import h2o
|
| 5 |
+
from h2o.automl import H2OAutoML
|
| 6 |
+
import pyarrow as pa
|
| 7 |
+
import pyarrow.parquet as pq
|
| 8 |
+
|
| 9 |
+
h2o.init()
|
| 10 |
+
|
| 11 |
+
###Data preparation
|
| 12 |
+
df_train = pd.read_csv("./intermediate/train_rdkit_descriptors.csv")
|
| 13 |
+
df_test = pd.read_csv("./intermediate/test_rdkit_descriptors.csv")
|
| 14 |
+
|
| 15 |
+
x_train = df_train.drop(columns=["label", "Standardized_SMILES"])
|
| 16 |
+
y_train = df_train["label"]
|
| 17 |
+
x_test = df_test.drop(columns=["label", "Standardized_SMILES"])
|
| 18 |
+
y_test = df_test["label"]
|
| 19 |
+
|
| 20 |
+
train_h2o = h2o.H2OFrame(pd.concat([x_train, y_train], axis=1))
|
| 21 |
+
test_h2o = h2o.H2OFrame(pd.concat([x_test, y_test], axis=1))
|
| 22 |
+
|
| 23 |
+
train_h2o["label"] = train_h2o["label"].asfactor()
|
| 24 |
+
test_h2o["label"] = test_h2o["label"].asfactor()
|
| 25 |
+
feature_cols = x_train.columns.tolist()
|
| 26 |
+
|
| 27 |
+
###Reload the model
|
| 28 |
+
from h2o import load_model
|
| 29 |
+
restored_model1 = h2o.load_model("../product/top_model_1/StackedEnsemble_AllModels_1_AutoML_1_20250401_220205")
|
| 30 |
+
restored_model2 = h2o.load_model("../product/top_model_2/StackedEnsemble_BestOfFamily_1_AutoML_1_20250401_220205")
|
| 31 |
+
restored_model3 = h2o.load_model("../product/top_model_3/GBM_4_AutoML_1_20250401_220205")
|
| 32 |
+
|
| 33 |
+
###Test the model
|
| 34 |
+
perf1=restored_model1.model_performance(test_h2o)
|
| 35 |
+
perf2=restored_model2.model_performance(test_h2o)
|
| 36 |
+
perf3=restored_model3.model_performance(test_h2o)
|
| 37 |
+
|
| 38 |
+
###Get the result with different threshold
|
| 39 |
+
|
| 40 |
+
threshold = 0.5
|
| 41 |
+
acc = perf1.accuracy(thresholds=[threshold])[0][1]
|
| 42 |
+
f1 = perf1.F1(thresholds=[threshold])[0][1]
|
| 43 |
+
prec = perf1.precision(thresholds=[threshold])[0][1]
|
| 44 |
+
rec = perf1.recall(thresholds=[threshold])[0][1]
|
| 45 |
+
spec = perf1.specificity(thresholds=[threshold])[0][1]
|
| 46 |
+
print(f"Threshold = {threshold}")
|
| 47 |
+
print(f"Accuracy = {acc:.4f}")
|
| 48 |
+
print(f"F1 Score = {f1:.4f}")
|
| 49 |
+
print(f"Precision = {prec:.4f}")
|
| 50 |
+
print(f"Recall = {rec:.4f}")
|
| 51 |
+
print(f"Specificity = {spec:.4f}")
|
| 52 |
+
|
| 53 |
+
threshold = 0.5
|
| 54 |
+
acc = perf2.accuracy(thresholds=[threshold])[0][1]
|
| 55 |
+
f1 = perf2.F1(thresholds=[threshold])[0][1]
|
| 56 |
+
prec = perf2.precision(thresholds=[threshold])[0][1]
|
| 57 |
+
rec = perf2.recall(thresholds=[threshold])[0][1]
|
| 58 |
+
spec = perf2.specificity(thresholds=[threshold])[0][1]
|
| 59 |
+
print(f"Threshold = {threshold}")
|
| 60 |
+
print(f"Accuracy = {acc:.4f}")
|
| 61 |
+
print(f"F1 Score = {f1:.4f}")
|
| 62 |
+
print(f"Precision = {prec:.4f}")
|
| 63 |
+
print(f"Recall = {rec:.4f}")
|
| 64 |
+
print(f"Specificity = {spec:.4f}")
|
| 65 |
+
|
| 66 |
+
threshold = 0.5
|
| 67 |
+
acc = perf3.accuracy(thresholds=[threshold])[0][1]
|
| 68 |
+
f1 = perf3.F1(thresholds=[threshold])[0][1]
|
| 69 |
+
prec = perf3.precision(thresholds=[threshold])[0][1]
|
| 70 |
+
rec = perf3.recall(thresholds=[threshold])[0][1]
|
| 71 |
+
spec = perf3.specificity(thresholds=[threshold])[0][1]
|
| 72 |
+
print(f"Threshold = {threshold}")
|
| 73 |
+
print(f"Accuracy = {acc:.4f}")
|
| 74 |
+
print(f"F1 Score = {f1:.4f}")
|
| 75 |
+
print(f"Precision = {prec:.4f}")
|
| 76 |
+
print(f"Recall = {rec:.4f}")
|
| 77 |
+
print(f"Specificity = {spec:.4f}")
|
| 78 |
+
|
| 79 |
+
metrics1 = {
|
| 80 |
+
"AUC": perf1.auc(),
|
| 81 |
+
"LogLoss": perf1.logloss(),
|
| 82 |
+
"Accuracy": perf1.accuracy(),
|
| 83 |
+
"F1": perf1.F1(),
|
| 84 |
+
"Precision": perf1.precision(),
|
| 85 |
+
"Recall": perf1.recall(),
|
| 86 |
+
"Specificity": perf1.specificity()
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
metrics2 = {
|
| 90 |
+
"AUC": perf2.auc(),
|
| 91 |
+
"LogLoss": perf2.logloss(),
|
| 92 |
+
"Accuracy": perf2.accuracy(),
|
| 93 |
+
"F1": perf2.F1(),
|
| 94 |
+
"Precision": perf2.precision(),
|
| 95 |
+
"Recall": perf2.recall(),
|
| 96 |
+
"Specificity": perf2.specificity()
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
metrics3 = {
|
| 100 |
+
"AUC": perf3.auc(),
|
| 101 |
+
"LogLoss": perf3.logloss(),
|
| 102 |
+
"Accuracy": perf3.accuracy(),
|
| 103 |
+
"F1": perf3.F1(),
|
| 104 |
+
"Precision": perf3.precision(),
|
| 105 |
+
"Recall": perf3.recall(),
|
| 106 |
+
"Specificity": perf3.specificity()
|
| 107 |
+
}
|
| 108 |
+
###Get the figure for roc and pr
|
| 109 |
+
perf1.plot(type="roc")
|
| 110 |
+
perf1.plot(type="pr")
|
| 111 |
+
|
| 112 |
+
perf2.plot(type="roc")
|
| 113 |
+
perf2.plot(type="pr")
|
| 114 |
+
|
| 115 |
+
perf3.plot(type="roc")
|
| 116 |
+
perf3.plot(type="pr")
|
| 117 |
+
|
| 118 |
+
### SHAP analysis
|
| 119 |
+
restored_model3.shap_summary_plot(test_h2o[:,:-1])
|
| 120 |
+
fig = plt.gcf()
|
| 121 |
+
fig.savefig("./product/3shap_summary_plot.png", dpi=300, bbox_inches="tight")
|
scripts/model_constrcution.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import h2o
|
| 5 |
+
from h2o.automl import H2OAutoML
|
| 6 |
+
import pyarrow as pa
|
| 7 |
+
import pyarrow.parquet as pq
|
| 8 |
+
|
| 9 |
+
h2o.init()
|
| 10 |
+
|
| 11 |
+
###Data preparation
|
| 12 |
+
df_train = pd.read_csv("./intermediate/train_rdkit_descriptors.csv")
|
| 13 |
+
df_test = pd.read_csv("./intermediate/test_rdkit_descriptors.csv")
|
| 14 |
+
|
| 15 |
+
x_train = df_train.drop(columns=["label", "Standardized_SMILES"])
|
| 16 |
+
y_train = df_train["label"]
|
| 17 |
+
x_test = df_test.drop(columns=["label", "Standardized_SMILES"])
|
| 18 |
+
y_test = df_test["label"]
|
| 19 |
+
|
| 20 |
+
train_h2o = h2o.H2OFrame(pd.concat([x_train, y_train], axis=1))
|
| 21 |
+
test_h2o = h2o.H2OFrame(pd.concat([x_test, y_test], axis=1))
|
| 22 |
+
|
| 23 |
+
train_h2o["label"] = train_h2o["label"].asfactor()
|
| 24 |
+
test_h2o["label"] = test_h2o["label"].asfactor()
|
| 25 |
+
feature_cols = x_train.columns.tolist()
|
| 26 |
+
|
| 27 |
+
###Training
|
| 28 |
+
aml = H2OAutoML(max_models=20,seed=42,nfolds=10,sort_metric="AUC")
|
| 29 |
+
aml.train(x=feature_cols, y="label", training_frame=train_h2o)
|
| 30 |
+
|
| 31 |
+
###Model Selection
|
| 32 |
+
lb = aml.leaderboard
|
| 33 |
+
lb.head(rows=lb.nrows)
|
| 34 |
+
best_model = aml.leader
|
| 35 |
+
|
| 36 |
+
###Save the best model
|
| 37 |
+
#best_model = h2o.save_model(model = best_model, path ='./product/', force = True)
|
| 38 |
+
top_3_models = lb.as_data_frame()["model_id"].head(3).tolist()
|
| 39 |
+
|
| 40 |
+
for i, model_id in enumerate(top_3_models, start=1):
|
| 41 |
+
model = h2o.get_model(model_id)
|
| 42 |
+
model_path = h2o.save_model(model=model, path=f"./product/top_model_{i}", force=True)
|
| 43 |
+
|
| 44 |
+
###Save the corss validation result for all models
|
| 45 |
+
model_ids = lb.as_data_frame()["model_id"].tolist()
|
| 46 |
+
all_model_summaries = []
|
| 47 |
+
for model_id in model_ids:
|
| 48 |
+
model = h2o.get_model(model_id)
|
| 49 |
+
cv_summary = model.cross_validation_metrics_summary().as_data_frame()
|
| 50 |
+
cv_summary["model_id"] = model_id
|
| 51 |
+
all_model_summaries.append(cv_summary)
|
| 52 |
+
|
| 53 |
+
cv_all_models_df = pd.concat(all_model_summaries, ignore_index=True)
|
| 54 |
+
cv_all_models_df.to_csv("./intermediate/cross_validation_result.csv",index=False)
|
| 55 |
+
|
| 56 |
+
###Reload the model for addtional test
|
| 57 |
+
from h2o import load_model
|
| 58 |
+
restored_model1 = h2o.load_model("./product/top_model_1/StackedEnsemble_AllModels_1_AutoML_1_20250401_220205")
|
| 59 |
+
restored_model2 = h2o.load_model("./product/top_model_2/StackedEnsemble_BestOfFamily_1_AutoML_1_20250401_220205")
|
| 60 |
+
restored_model3 = h2o.load_model("./product/top_model_3/GBM_4_AutoML_1_20250401_220205")
|
| 61 |
+
|
| 62 |
+
perf1=restored_model1.model_performance(test_h2o)
|
| 63 |
+
perf2=restored_model2.model_performance(test_h2o)
|
| 64 |
+
perf3=restored_model3.model_performance(test_h2o)
|
| 65 |
+
|
| 66 |
+
###Obtain the performance
|
| 67 |
+
threshold = 0.5
|
| 68 |
+
acc = perf1.accuracy(thresholds=[threshold])[0][1]
|
| 69 |
+
f1 = perf1.F1(thresholds=[threshold])[0][1]
|
| 70 |
+
prec = perf1.precision(thresholds=[threshold])[0][1]
|
| 71 |
+
rec = perf1.recall(thresholds=[threshold])[0][1]
|
| 72 |
+
spec = perf1.specificity(thresholds=[threshold])[0][1]
|
| 73 |
+
AUC= perf1.auc()
|
| 74 |
+
LogLoss=perf1.logloss()
|
| 75 |
+
print(f"AUC = {AUC}")
|
| 76 |
+
print(f"LogLoss = {LogLoss}")
|
| 77 |
+
print(f"Threshold = {threshold}")
|
| 78 |
+
print(f"Accuracy = {acc:.4f}")
|
| 79 |
+
print(f"F1 Score = {f1:.4f}")
|
| 80 |
+
print(f"Precision = {prec:.4f}")
|
| 81 |
+
print(f"Recall = {rec:.4f}")
|
| 82 |
+
print(f"Specificity = {spec:.4f}")
|
| 83 |
+
|
| 84 |
+
###SHAP analysis for the third-best model
|
| 85 |
+
restored_model3.shap_summary_plot(test_h2o[:,:-1])
|
| 86 |
+
fig = plt.gcf()
|
| 87 |
+
fig.savefig("./product/3shap_summary_plot.png", dpi=300, bbox_inches="tight")
|
scripts/model_construction.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/split_dataset.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from sklearn.model_selection import train_test_split
|
| 4 |
+
|
| 5 |
+
df_positive = pd.read_csv("./intermediate/cleaned_positive.csv")
|
| 6 |
+
df_negative = pd.read_csv("./intermediate/cleaned_negative.csv")
|
| 7 |
+
|
| 8 |
+
pos_train, pos_test = train_test_split(df_positive, test_size=0.2, random_state=42)
|
| 9 |
+
neg_train_full, neg_test = train_test_split(df_negative, test_size=0.2, random_state=42)
|
| 10 |
+
neg_train = neg_train_full.sample(n=len(pos_train), random_state=42)
|
| 11 |
+
neg_remaining = neg_train_full.drop(neg_train.index)
|
| 12 |
+
neg_test = pd.concat([neg_test, neg_remaining]).reset_index(drop=True)
|
| 13 |
+
train_df = pd.concat([pos_train, neg_train]).sample(frac=1, random_state=42).reset_index(drop=True)
|
| 14 |
+
test_df = pd.concat([pos_test, neg_test]).sample(frac=1, random_state=42).reset_index(drop=True)
|
| 15 |
+
train_df.to_csv("./intermediate/train.csv", index=False)
|
| 16 |
+
test_df.to_csv("./intermediate/test.csv", index=False)
|