.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/graph_based/plot_1_dl2vec.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_graph_based_plot_1_dl2vec.py: DL2Vec ======== This example corresponds to the paper `Predicting candidate genes from phenotypes, functions and anatomical site of expression `_. This work is a graph-based machine-learning method to learn from biomedical ontologies. This method works by transforming the ontology into a graph following a set of rules. Random walks are generated from the obtained graph and then processed by a Word2Vec model, which generates embeddings of the original ontology classes. This algorithm is applied to generate numerical representations of genes and diseases based on the background knowledge found in the Gene Ontology, which was extended to incorporate phenotypes, functions of the gene products and anatomical location of gene expression. The representations of genes and diseases are then used to predict candidate genes for a given disease. .. GENERATED FROM PYTHON SOURCE LINES 19-24 To show an example of DL2Vec, we need 3 components: - The ontology projector - The random walks generator - The Word2Vec model .. GENERATED FROM PYTHON SOURCE LINES 24-37 .. code-block:: Python import sys sys.path.append('../../') import mowl mowl.init_jvm("10g") from mowl.datasets.builtin import GDADatasetV2 from mowl.models import RandomWalkPlusW2VModel from mowl.projection import DL2VecProjector from mowl.walking import DeepWalk from gensim.models.word2vec import LineSentence from gensim.models import Word2Vec .. GENERATED FROM PYTHON SOURCE LINES 38-39 Instantiating the dataset and the model .. GENERATED FROM PYTHON SOURCE LINES 39-49 .. code-block:: Python dataset = GDADatasetV2() print(f"Number of classes: f{len(dataset.classes)}") model = RandomWalkPlusW2VModel(dataset) model.set_projector(DL2VecProjector()) model.set_walker(DeepWalk(5, 5, 0.1, workers=4)) model.set_w2v_model(vector_size=5, epochs=2, window=5, min_count=1, workers=4) model.train() .. rst-class:: sphx-glr-script-out .. code-block:: none Number of classes: f197774 .. GENERATED FROM PYTHON SOURCE LINES 50-51 Evaluating the model .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python from mowl.evaluation import GDAEvaluator model.set_evaluator(GDAEvaluator) model.evaluate(dataset.testing) .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 11.823 seconds) **Estimated memory usage:** 5145 MB .. _sphx_glr_download_examples_graph_based_plot_1_dl2vec.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_dl2vec.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_dl2vec.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_1_dl2vec.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_