.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` 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:`grakel.ShortestPath` .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Accuracy: 82.45% | .. code-block:: default from __future__ import print_function print(__doc__) import numpy as np from sklearn.svm import SVC from sklearn.model_selection import GridSearchCV from sklearn.model_selection import cross_val_predict from sklearn.pipeline import make_pipeline from sklearn.metrics import accuracy_score from grakel.datasets import fetch_dataset from grakel.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. ** 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.481 seconds) .. _sphx_glr_download_auto_examples_plot_pipeline_example.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_pipeline_example.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_pipeline_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_