当前位置:网站首页>TorchDrug--药物属性预测
TorchDrug--药物属性预测
2022-06-30 19:26:00 【发呆的比目鱼】
TorchDrug–药物属性预测
在本教程中,我们将学习如何使用 TorchDrug 训练图神经网络以进行分子特性预测。属性预测旨在根据分子的图形结构和特征预测分子的化学性质。
准备数据集
我们使用ClinTox数据集进行说明。ClinTox包含 1,484 个分子,在临床试验中标有 FDA 批准状态和毒性状态。
在这里,我们下载数据集并将其拆分为训练、验证和测试集。训练集/有效集/测试集的分割分别为 80%、10% 和 10%。
import torch
from torchdrug import data, datasets
dataset = datasets.ClinTox("~/molecule-datasets/")
lengths = [int(0.8 * len(dataset)), int(0.1 * len(dataset))]
lengths += [len(dataset) - sum(lengths)]
train_set, valid_set, test_set = torch.utils.data.random_split(dataset, lengths)
让我们可视化数据集中的一些样本。
graphs = []
labels = []
for i in range(4):
sample = dataset[i]
graphs.append(sample.pop("graph"))
label = ["%s: %d" % (k, v) for k, v in sample.items()]
label = ", ".join(label)
labels.append(label)
graph = data.Molecule.pack(graphs)
graph.visualize(labels, num_row=1)

定义我们的模型
该模型由两部分组成,一个与任务无关的图表示模型和一个特定于任务的模块。我们定义了一个具有 4 个隐藏层的图同构网络 (GIN) 作为我们的表示模型。两个预测任务将通过任务特定模块的多任务训练共同优化。
from torchdrug import core, models, tasks, utils
model = models.GIN(input_dim=dataset.node_feature_dim,
hidden_dims=[256, 256, 256, 256],
short_cut=True, batch_norm=True, concat_hidden=True)
task = tasks.PropertyPrediction(model, task=dataset.tasks,
criterion="bce", metric=("auprc", "auroc"))
训练和测试
现在我们可以训练我们的模型了。我们为我们的模型设置了一个优化器,并将所有内容放在一个 Engine 实例中。训练我们的模型可能需要几分钟。
optimizer = torch.optim.Adam(task.parameters(), lr=1e-3)
solver = core.Engine(task, train_set, valid_set, test_set, optimizer,
gpus=[0], batch_size=1024)
solver.train(num_epoch=100)
solver.evaluate("valid")
模型训练完成后,我们会在验证集上对其进行评估。结果可能类似于以下内容。
auprc [CT_TOX]: 0.455744
auprc [FDA_APPROVED]: 0.985126
auroc [CT_TOX]: 0.861976
auroc [FDA_APPROVED]: 0.816788
为了对模型有一些直觉,我们可以研究模型的预测。以下代码为每个类别选择一个样本,并绘制结果。
边栏推荐
- 闲鱼难“翻身”
- 台湾SSS鑫创SSS1700替代Cmedia CM6533 24bit 96KHZ USB音频编解码芯片
- 盘点华为云GaussDB(for Redis)六大秒级能力
- 数据智能——DTCC2022!中国数据库技术大会即将开幕
- 超视频时代的音视频架构建设|Science和英特尔联袂推出“架构师成长计划”第二季
- VR全景拍摄为什么要加盟?巧借资源实现共赢
- What is the difference between tolocal8bit and toutf8() in QT
- 将 EMQX Cloud 数据通过公网桥接到 AWS IoT
- Code shoe set - mt3111 · assignment
- qt中toLocal8Bit和toUtf8()有什么区别
猜你喜欢

Conditional compilation

RP原型资源分享-购物类App

Code shoe set - mt3435 · assignment - bipartite graph problem - Graphic explanation

标配10个安全气囊,奇瑞艾瑞泽8安全防护无死角

Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"

说实话ThreadLocal真不是啥高级的东西

Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field

QQmlApplicationEngine failed to load component qrc:/main.qml:-1 No such file or directory

The former king of fruit juice sold for 1.6 billion yuan

2022年高考都结束了,还有人真觉得程序员下班后不需要学习吗?
随机推荐
Graduates
内存数据库如何发挥内存优势?
标配10个安全气囊,奇瑞艾瑞泽8安全防护无死角
MySQL billing Statistics (Part 1): MySQL installation and client dbeaver connection
matlab 将三角剖分结果保存为STL文件
MQ component (2022.5.16-5.22)
RP prototype resource sharing - shopping app
DELL R720服务器安装网卡Broadcom 5720驱动
Which brokerage has the lowest commission? In addition, is it safe to open a mobile account?
Force deduction ----- count the string containing the given prefix
FH6908A负极关断同步整流模拟低压降二极管控制IC芯片TSOT23-6超低功耗整流器 1w功耗 <100uA静态 替代MP6908
arthas调试 确定问题工具包
线下门店为什么要做新零售?
The project is configured with eslint. When the editor does not close the eslint function, the eslint does not take effect
【NLP】【TextCNN】 文本分类
composer
盘点华为云GaussDB(for Redis)六大秒级能力
Tencent conference application market was officially launched, with more than 20 applications in the first batch
Redis beginner to master 01
RP原型资源分享-购物类App