.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_pipeline_example.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_auto_examples_plot_pipeline_example.py: ==================================================== Example of building a graph classification pipeline. ==================================================== Script makes use of :class:`grakelx.ShortestPath` .. GENERATED FROM PYTHON SOURCE LINES 8-38 .. rst-class:: sphx-glr-script-out .. code-block:: none Accuracy: 82.45% | .. code-block:: Python from __future__ import print_function print(__doc__) import numpy as np from sklearn.metrics import accuracy_score from sklearn.model_selection import GridSearchCV, cross_val_predict from sklearn.pipeline import make_pipeline from sklearn.svm import SVC from grakelx.datasets import fetch_dataset from grakelx.kernels import ShortestPath # Loads the Mutag dataset from: MUTAG = fetch_dataset("MUTAG", verbose=False) G, y = MUTAG.data, MUTAG.target # Values of C parameter of SVM C_grid = (10.0 ** np.arange(-4, 6, 1) / len(G)).tolist() # Creates pipeline estimator = make_pipeline( ShortestPath(normalize=True), GridSearchCV(SVC(kernel="precomputed"), dict(C=C_grid), scoring="accuracy", cv=10) ) # Performs cross-validation and computes accuracy n_folds = 10 acc = accuracy_score(y, cross_val_predict(estimator, G, y, cv=n_folds)) print("Accuracy:", str(round(acc * 100, 2)) + "%") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.006 seconds) .. _sphx_glr_download_auto_examples_plot_pipeline_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pipeline_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pipeline_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_pipeline_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_