.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_linear_feature_gen.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_linear_feature_gen.py: Tweaking Feature Generation for Linear Methods ============================================================= In both `API <../auto_examples/plot_linear_quickstart.html>`_ and `CLI <../cli/linear.html>`_ usage of linear methods, LibMultiLabel handles the feature generation step by default. Unless necessary, you do not need to generate features in different ways as described in this tutorial. This tutorial demonstrates how to customize the way to generate features for linear methods through an API example. Here we use the `rcv1 `_ dataset as an example. .. GENERATED FROM PYTHON SOURCE LINES 11-25 .. code-block:: Python from sklearn.preprocessing import MultiLabelBinarizer from libmultilabel import linear datasets = linear.load_dataset("txt", "data/rcv1/train.txt", "data/rcv1/test.txt") tfidf_params = { "max_features": 20000, "min_df": 3, "ngram_range": (1, 3) } preprocessor = linear.Preprocessor(tfidf_params=tfidf_params) preprocessor.fit(datasets) datasets = preprocessor.transform(datasets) .. GENERATED FROM PYTHON SOURCE LINES 26-33 The argument ``tfidf_params`` of the ``Preprocessor`` can specify how to generate the TF-IDF features. In this example, we adjust the ``max_features``, ``min_df``, and ``ngram_range`` of the preprocessor. For explanation of these three and other options, refer to the `sklearn page `_. Users can also try other methods to generalize features, like word embedding. Finally, we use the generated numerical features to train and evaluate the model. The rest of the steps is the same in the quickstarts. Please refer to them for details. .. _sphx_glr_download_auto_examples_plot_linear_feature_gen.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_linear_feature_gen.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_linear_feature_gen.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_