<jupyter_start><jupyter_text>Installing DeepChem DeepChem is a python-based open source deep learning framework and offers feature rich set toolchain that democratizes the use of deep-learning in drug discovery, materials science, quantum chemistry, and biology.<jupyter_code>!curl -Lo conda_installer.py https://raw.githubusercontent.com/deepchem/deepchem/master/scripts/colab_install.py
import conda_installer
conda_installer.install()
!/root/miniconda/bin/conda info -e<jupyter_output>% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3501  100  3501    0     0  32719      0 --:--:-- --:--:-- --:--:-- 32719<jupyter_text><jupyter_code>!pip install --pre deepchem<jupyter_output>Collecting deepchem
[?25l  Downloading https://files.pythonhosted.org/packages/04/7f/3f678587e621d1b904ed6d1af65e353b1d681d6b9f4ffaf243c79745c654/deepchem-2.6.0.dev20210403043508-py3-none-any.whl (552kB)

[K     |▋                               | 10kB 17.0MB/s eta 0:00:01
[K     |█▏                              | 20kB 20.2MB/s eta 0:00:01
[K     |█▉                              | 30kB 25.0MB/s eta 0:00:01
[K     |██▍                             | 40kB 28.0MB/s eta 0:00:01
[K     |███                             | 51kB 22.1MB/s eta 0:00:01
[K     |███▋                            | 61kB 24.3MB/s eta 0:00:01
[K     |████▏                           | 71kB 23.2MB/s eta 0:00:01
[K     |████▊                           | 81kB 21.3MB/s eta 0:00:01
[K     |█████▍                          | 92kB 20.1MB/s eta 0:00:01
[K     |██████                          | 102kB 21.0MB/s eta 0:00:01
[K     |██████▌                         | 112kB 21.0MB/s eta 0:00:01
[K     |███████▏                [...]<jupyter_text>We can now import the `deepchem` package to play with.<jupyter_code>import deepchem as dc
dc.__version__<jupyter_output><empty_output><jupyter_text>Baseline - Fingerprints + NNImplementing and recording the baseline for Tox21 dataset.<jupyter_code>tasks, datasets, transformers = dc.molnet.load_tox21(featurizer='GraphConv')
train_dataset, valid_dataset, test_dataset = datasets
print(train_dataset)<jupyter_output><DiskDataset X.shape: (6264,), y.shape: (6264, 12), w.shape: (6264, 12), task_names: ['NR-AR' 'NR-AR-LBD' 'NR-AhR' ... 'SR-HSE' 'SR-MMP' 'SR-p53']><jupyter_text>The graph convolution model similar to a recurrent neural network in which the set of descriptors per atom is updated with each iteration based on those of its neighbours. The final layer is a fully connected layer which predicts output in a multi task setting.The graph convolutions start with a set of descriptiors, it then combines and recombines over various convolutional layers.<jupyter_code>tasks<jupyter_output><empty_output><jupyter_text>Above are the tasks in the Tox21 dataset - there are 12 tasks, each corresponding to different biotoxicity targets, such as cell receptors and stress response pathways.<jupyter_code>datasets[0]<jupyter_output><empty_output><jupyter_text>There are three dataset objects - train split, val split and test split. Each split consists of X and y. X is the features and y is the output label. For example the train split has X.shape (6264, ) and y.shape (6264, 12). This implies that there are 6264 samples in the train split. Training a Model on Fingerprints<jupyter_code>import warnings
warnings.filterwarnings("ignore")
n_tasks = len(tasks)
model = dc.models.GraphConvModel(n_tasks, mode='classification')
model.fit(train_dataset, nb_epoch=50)<jupyter_output><empty_output><jupyter_text>The GraphConv method is based on Duvenaud et al., . It uses a graph convolution model similar to a recurrent neural network in which the set of descriptors per atom is updated with each iteration based on those of its neighbours. The final layer is a fully connected layer which predicts output in a multi task setting.<jupyter_code>import numpy as np

metric = dc.metrics.Metric(dc.metrics.roc_auc_score)
print('training set score:', model.evaluate(train_dataset, [metric], transformers))
print('test set score:', model.evaluate(test_dataset, [metric], transformers))<jupyter_output>training set score: {'roc_auc_score': 0.9725301575583809}
test set score: {'roc_auc_score': 0.7081477950456065}<jupyter_text>The training set score is much higher than test set score. This indicates overfitting - and is why metrics on the validation set need to be measured in otder to tune parameters and detect overfitting.<jupyter_code>print(test_dataset.ids[0])
print(test_dataset.y[0])
model.predict(test_dataset)[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10646387832699619, 'fraction_numerical': 0.06189269117025771, 'mean_word_length': 3.2276785714285716, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '404713', 'license': 'MIT', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1500, 'n_words': 451, 'path': 'baselines/Tox21_GraphConv.ipynb', 'repo_name': 'nihal-rao/deepchem', 'size': '4734'}