.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_pipeline.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. 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.py: ===================== Building Pipelines ===================== HiClass can be adopted in scikit-learn pipelines, and fully supports sparse matrices as input. This example desmonstrates the use of both of these features. .. GENERATED FROM PYTHON SOURCE LINES 10-46 .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [['Credit reporting' 'Reports'] ['Loan' 'Student loan']] | .. code-block:: default from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline from hiclass import LocalClassifierPerParentNode # Define data X_train = [ "Struggling to repay loan", "Unable to get annual report", ] X_test = [ "Unable to get annual report", "Struggling to repay loan", ] Y_train = [["Loan", "Student loan"], ["Credit reporting", "Reports"]] # We will use logistic regression classifiers for every parent node lr = LogisticRegression() # Let's build a pipeline using CountVectorizer and TfidfTransformer # to extract features as sparse matrices pipeline = Pipeline( [ ("count", CountVectorizer()), ("tfidf", TfidfTransformer()), ("lcppn", LocalClassifierPerParentNode(local_classifier=lr)), ] ) # Now, let's train a local classifier per parent node pipeline.fit(X_train, Y_train) # Finally, let's predict using the pipeline predictions = pipeline.predict(X_test) print(predictions) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.022 seconds) .. _sphx_glr_download_auto_examples_plot_pipeline.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pipeline.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pipeline.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_