|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Regression Models in Selene\n", |
| 8 | + "\n", |
| 9 | + "Selene is a flexible framework, and can be used for tasks beyond simple classification.\n", |
| 10 | + "This tutorial serves as an introduction to training regression models with Selene.\n", |
| 11 | + "For this tutorial, we will predict mean ribosomal load (MRL) from 50 base pair 5' UTR sequences using models and data from [*Human 5′ UTR design and variant effect prediction from a massively parallel translation assay*](https://doi.org/10.1101/310375) by Sample et al.\n", |
| 12 | + "This data was generated from a massively parallel reporter assay (MPRA), which you can read more about in the preprint [on *bioRxiv*](https://doi.org/10.1101/310375).\n", |
| 13 | + "\n", |
| 14 | + "## Setup\n", |
| 15 | + "\n", |
| 16 | + "**Architecture:** The model is defined in [utr_model.py](https://github.com/FunctionLab/selene/blob/master/tutorials/regression_mpra_example/utr_model.py), and only superficially differs from the model in [the paper](https://doi.org/10.1101/310375).\n", |
| 17 | + "Since this is a real-valued regression problem, it is appropriate that the `criterion` method in `utr_model.py` uses the mean squared error.\n", |
| 18 | + "\n", |
| 19 | + "\n", |
| 20 | + "**Data:** The data from Sample et al is available [on GEO](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE114002).\n", |
| 21 | + "However, we have included [the `download_data.py` script](https://github.com/FunctionLab/selene/blob/master/tutorials/regression_mpra_example/download_data.py), to download the data and preprocess it.\n", |
| 22 | + "It should produce three files, `train.mat`, `validate.mat`, and `test.mat`.\n", |
| 23 | + "They include the data for training, validation, and testing.\n", |
| 24 | + "\n", |
| 25 | + "**Configuration file:** The configuration file [`regression_train.yml`](https://github.com/FunctionLab/selene/blob/master/tutorials/regression_mpra_example/regression_train.yml) is slightly different than the configuration files in the classification tutorials.\n", |
| 26 | + "Specifically, `metrics` in `train_model` includes the coefficient of determination (`r2`), since the default metrics (`roc_auc` and `average_precision`) are not appropriate for regression.\n", |
| 27 | + "Further, `report_gt_feature_n_positives` in `train_model` has been set to zero to prevent spurious filtering. \n", |
| 28 | + "\n", |
| 29 | + "## Download the data\n", |
| 30 | + "\n", |
| 31 | + "To download the data, just run the [`download_data.py`](https://github.com/FunctionLab/selene/blob/master/tutorials/regression_mpra_example/download_data.py) script from the command line:\n", |
| 32 | + "```sh\n", |
| 33 | + "python download_data.py\n", |
| 34 | + "```\n", |
| 35 | + "\n", |
| 36 | + "## Train and evaluate the data\n", |
| 37 | + "\n", |
| 38 | + "\n", |
| 39 | + "\n" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": null, |
| 45 | + "metadata": {}, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "from selene_sdk.utils import load_path\n", |
| 49 | + "from selene_sdk.utils import parse_configs_and_run" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "metadata": {}, |
| 55 | + "source": [ |
| 56 | + "Before running `load_path` on `regression_train.yml`, please edit the YAML file to include the absolute path of the model file.\n", |
| 57 | + "\n", |
| 58 | + "Currently, the model is set to train on GPU.\n", |
| 59 | + "If you do not have CUDA on your machine, please set `use_cuda` to `False` in the configuration file. \n", |
| 60 | + "(This will slow down the process considerably.)" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": null, |
| 66 | + "metadata": {}, |
| 67 | + "outputs": [], |
| 68 | + "source": [ |
| 69 | + "configs = load_path(\"./regression_train.yml\", instantiate=False)" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "cell_type": "code", |
| 74 | + "execution_count": null, |
| 75 | + "metadata": {}, |
| 76 | + "outputs": [], |
| 77 | + "source": [ |
| 78 | + "parse_configs_and_run(configs, lr=0.001)" |
| 79 | + ] |
| 80 | + } |
| 81 | + ], |
| 82 | + "metadata": { |
| 83 | + "kernelspec": { |
| 84 | + "display_name": "Python 3", |
| 85 | + "language": "python", |
| 86 | + "name": "python3" |
| 87 | + }, |
| 88 | + "language_info": { |
| 89 | + "codemirror_mode": { |
| 90 | + "name": "ipython", |
| 91 | + "version": 3 |
| 92 | + }, |
| 93 | + "file_extension": ".py", |
| 94 | + "mimetype": "text/x-python", |
| 95 | + "name": "python", |
| 96 | + "nbconvert_exporter": "python", |
| 97 | + "pygments_lexer": "ipython3", |
| 98 | + "version": "3.6.3" |
| 99 | + } |
| 100 | + }, |
| 101 | + "nbformat": 4, |
| 102 | + "nbformat_minor": 2 |
| 103 | +} |
0 commit comments