scikit-activeml


Namescikit-activeml JSON
Version 0.5.2 PyPI version JSON
download
home_pagehttps://github.com/scikit-activeml/scikit-activeml
SummaryOur package scikit-activeml is a Python library for active learning on top of SciPy and scikit-learn.
upload_time2024-08-28 16:01:25
maintainerNone
docs_urlNone
authorMarek Herde
requires_python>=3.9
licenseBSD 3-Clause License
keywords active learning machine learning semi-supervised learning data mining pattern recognition artificial intelligence
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. intro_start

|

.. image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/scikit-activeml-logo.png
   :class: dark-light
   :align: center
   :width: 40%

|

=====================================================================
scikit-activeml: A Library and Toolbox for Active Learning Algorithms
=====================================================================
|Doc| |Codecov| |PythonVersion| |PyPi| |Black| |Downloads| |Paper|

.. |Doc| image:: https://img.shields.io/badge/docs-latest-green
   :target: https://scikit-activeml.github.io/scikit-activeml-docs/latest/

.. |Codecov| image:: https://codecov.io/gh/scikit-activeml/scikit-activeml/branch/master/graph/badge.svg
   :target: https://app.codecov.io/gh/scikit-activeml/scikit-activeml

.. |PythonVersion| image:: https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg
   :target: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue

.. |PyPi| image:: https://badge.fury.io/py/scikit-activeml.svg
   :target: https://badge.fury.io/py/scikit-activeml

.. |Paper| image:: https://img.shields.io/badge/paper-10.20944/preprints202103.0194.v1-blue.svg
   :target: https://www.preprints.org/manuscript/202103.0194/v1

.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
   :target: https://github.com/psf/black

.. |Downloads| image:: https://static.pepy.tech/badge/scikit-activeml
   :target: https://www.pepy.tech/projects/scikit-activeml

Machine learning models often need large amounts of training data to
perform well. Whereas unlabeled data can be easily gathered, the labeling process
is difficult, time-consuming, or expensive in most applications. Active learning can help solve
this problem by querying labels for those data samples improving the performance
the most. Thereby, the goal is that the learning algorithm performs sufficiently well with
fewer labels. With this goal in mind, **scikit-activeml** has been developed as a Python library for active learning
on top of `scikit-learn <https://scikit-learn.org/stable/>`_.

.. intro_end

.. user_installation_start

User Installation
=================

The easiest way of installing scikit-activeml is using ``pip``:

::

    pip install -U scikit-activeml

The installation via `pip` defines only minimum requirements to avoid
potential package downgrades withing your installation. If you encounter
any incompatibility issues, you can downgrade packages by installing the
`maximum requirements <https://github.com/scikit-activeml/scikit-activeml/blob/master/requirements_max.txt>`_,
we tested at the release of the current package
version:

::

    pip install -r requirements_max.txt

.. user_installation_end

.. examples_start

Examples
========
We provide a broad overview of different use-cases in our `tutorial section <https://scikit-activeml.github.io/scikit-activeml-docs/latest/tutorials.html>`_ offering

- `Pool-based Active Learning - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/00_pool_getting_started.html>`_,
- `Deep Pool-based Active Learning - scikit-activeml with Skorch <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/01_deep_pool_al_with_skorch.html>`_,
- `Pool-based Active Learning for Regression - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/02_pool_regression_getting_started.html>`_,
- `Pool-based Active Learning - Sample Annotating <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/03_pool_oracle_annotations.html>`_,
- `Pool-based Active Learning - Simple Evaluation Study <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/04_pool_simple_evaluation_study.html>`_,
- `Active Image Classification via Self-supervised Learning <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/05_pool_al_with_self_supervised_learning.html>`_,
- `Multi-annotator Pool-based Active Learning - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/10_multiple_annotators_getting_started.html>`_,
- `Stream-based Active Learning - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/20_stream_getting_started.html>`_,
- `Batch Stream-based Active Learning with Pool Query Strategies <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/21_stream_batch_with_pool_al.html>`_,
- and `Stream-based Active Learning With River <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/22_river_classifier.html>`_.

Two simple code snippets illustrating the straightforwardness of implementing active learning cycles with our Python package ``skactiveml`` are given in the following.

Pool-based Active Learning
##########################

The following code snippet implements an active learning cycle with 20 iterations using a Gaussian process
classifier and uncertainty sampling. To use other classifiers, you can simply wrap classifiers from
``sklearn`` or use classifiers provided by ``skactiveml``. Note that the main difficulty using
active learning with ``sklearn`` is the ability to handle unlabeled data, which we denote as a specific value
(``MISSING_LABEL``) in the label vector ``y``. More query strategies can be found in the documentation.

.. code-block:: python

    import numpy as np
    from sklearn.gaussian_process import GaussianProcessClassifier
    from sklearn.datasets import make_blobs
    from skactiveml.pool import UncertaintySampling
    from skactiveml.utils import unlabeled_indices, MISSING_LABEL
    from skactiveml.classifier import SklearnClassifier

    # Generate data set.
    X, y_true = make_blobs(n_samples=200, centers=4, random_state=0)
    y = np.full(shape=y_true.shape, fill_value=MISSING_LABEL)

    # Use the first 10 instances as initial training data.
    y[:10] = y_true[:10]

    # Create classifier and query strategy.
    clf = SklearnClassifier(
        GaussianProcessClassifier(random_state=0),
        classes=np.unique(y_true),
        random_state=0
    )
    qs = UncertaintySampling(method='entropy')

    # Execute active learning cycle.
    n_cycles = 20
    for c in range(n_cycles):
        query_idx = qs.query(X=X, y=y, clf=clf)
        y[query_idx] = y_true[query_idx]

    # Fit final classifier.
    clf.fit(X, y)

As a result, we obtain an actively trained Gaussian process classifier.
A corresponding visualization of its decision boundary (black line) and the
sample utilities (greenish contours) is given below.

.. image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/pal-example-output.png
   :width: 400

Stream-based Active Learning
############################

The following code snippet implements an active learning cycle with 200 data points and
the default budget of 10% using a pwc classifier and split uncertainty sampling.
Like in the pool-based example you can wrap other classifiers from ``sklearn``,
``sklearn`` compatible classifiers or like the example classifiers provided by ``skactiveml``.

.. code-block:: python

    import numpy as np
    from sklearn.datasets import make_blobs
    from skactiveml.classifier import ParzenWindowClassifier
    from skactiveml.stream import Split
    from skactiveml.utils import MISSING_LABEL

    # Generate data set.
    X, y_true = make_blobs(n_samples=200, centers=4, random_state=0)

    # Create classifier and query strategy.
    clf = ParzenWindowClassifier(random_state=0, classes=np.unique(y_true))
    qs = Split(random_state=0)

    # Initializing the training data as an empty array.
    X_train = []
    y_train = []

    # Initialize the list that stores the result of the classifier's prediction.
    correct_classifications = []

    # Execute active learning cycle.
    for x_t, y_t in zip(X, y_true):
        X_cand = x_t.reshape([1, -1])
        y_cand = y_t
        clf.fit(X_train, y_train)
        correct_classifications.append(clf.predict(X_cand)[0] == y_cand)
        sampled_indices = qs.query(candidates=X_cand, clf=clf)
        qs.update(candidates=X_cand, queried_indices=sampled_indices)
        X_train.append(x_t)
        y_train.append(y_cand if len(sampled_indices) > 0 else MISSING_LABEL)

As a result, we obtain an actively trained Parzen window classifier.
A corresponding visualization of its accuracy curve accross the active learning
cycle is given below.

.. image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/stream-example-output.png
   :width: 400

Query Strategy Overview
#######################

For better orientation, we provide an `overview <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/strategy_overview.html>`_
(incl. paper references and `visual examples <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/sphinx_gallery_examples/index.html>`_)
of the query strategies implemented by ``skactiveml``.

|Overview| |Visualization|

.. |Overview| image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/strategy-overview.gif
   :width: 365

.. |Visualization| image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/example-overview.gif
   :width: 365

.. examples_end

.. citing_start

Citing
======
If you use ``skactiveml`` in one of your research projects and find it helpful,
please cite the following:

::

    @article{skactiveml2021,
        title={scikit-activeml: {A} {L}ibrary and {T}oolbox for {A}ctive {L}earning {A}lgorithms},
        author={Daniel Kottke and Marek Herde and Tuan Pham Minh and Alexander Benz and Pascal Mergard and Atal Roghman and Christoph Sandrock and Bernhard Sick},
        journal={Preprints},
        doi={10.20944/preprints202103.0194.v1},
        year={2021},
        url={https://github.com/scikit-activeml/scikit-activeml}
    }

.. citing_end



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/scikit-activeml/scikit-activeml",
    "name": "scikit-activeml",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "active learning, machine learning, semi-supervised learning, data mining, pattern recognition, artificial intelligence",
    "author": "Marek Herde",
    "author_email": "marek.herde@uni-kassel.de",
    "download_url": "https://files.pythonhosted.org/packages/1e/fa/707f9b62991d3abba5098aa14e501696a3f5f426745bedadc0c230ef1886/scikit-activeml-0.5.2.tar.gz",
    "platform": null,
    "description": ".. intro_start\n\n|\n\n.. image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/scikit-activeml-logo.png\n   :class: dark-light\n   :align: center\n   :width: 40%\n\n|\n\n=====================================================================\nscikit-activeml: A Library and Toolbox for Active Learning Algorithms\n=====================================================================\n|Doc| |Codecov| |PythonVersion| |PyPi| |Black| |Downloads| |Paper|\n\n.. |Doc| image:: https://img.shields.io/badge/docs-latest-green\n   :target: https://scikit-activeml.github.io/scikit-activeml-docs/latest/\n\n.. |Codecov| image:: https://codecov.io/gh/scikit-activeml/scikit-activeml/branch/master/graph/badge.svg\n   :target: https://app.codecov.io/gh/scikit-activeml/scikit-activeml\n\n.. |PythonVersion| image:: https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg\n   :target: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue\n\n.. |PyPi| image:: https://badge.fury.io/py/scikit-activeml.svg\n   :target: https://badge.fury.io/py/scikit-activeml\n\n.. |Paper| image:: https://img.shields.io/badge/paper-10.20944/preprints202103.0194.v1-blue.svg\n   :target: https://www.preprints.org/manuscript/202103.0194/v1\n\n.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/psf/black\n\n.. |Downloads| image:: https://static.pepy.tech/badge/scikit-activeml\n   :target: https://www.pepy.tech/projects/scikit-activeml\n\nMachine learning models often need large amounts of training data to\nperform well. Whereas unlabeled data can be easily gathered, the labeling process\nis difficult, time-consuming, or expensive in most applications. Active learning can help solve\nthis problem by querying labels for those data samples improving the performance\nthe most. Thereby, the goal is that the learning algorithm performs sufficiently well with\nfewer labels. With this goal in mind, **scikit-activeml** has been developed as a Python library for active learning\non top of `scikit-learn <https://scikit-learn.org/stable/>`_.\n\n.. intro_end\n\n.. user_installation_start\n\nUser Installation\n=================\n\nThe easiest way of installing scikit-activeml is using ``pip``:\n\n::\n\n    pip install -U scikit-activeml\n\nThe installation via `pip` defines only minimum requirements to avoid\npotential package downgrades withing your installation. If you encounter\nany incompatibility issues, you can downgrade packages by installing the\n`maximum requirements <https://github.com/scikit-activeml/scikit-activeml/blob/master/requirements_max.txt>`_,\nwe tested at the release of the current package\nversion:\n\n::\n\n    pip install -r requirements_max.txt\n\n.. user_installation_end\n\n.. examples_start\n\nExamples\n========\nWe provide a broad overview of different use-cases in our `tutorial section <https://scikit-activeml.github.io/scikit-activeml-docs/latest/tutorials.html>`_ offering\n\n- `Pool-based Active Learning - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/00_pool_getting_started.html>`_,\n- `Deep Pool-based Active Learning - scikit-activeml with Skorch <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/01_deep_pool_al_with_skorch.html>`_,\n- `Pool-based Active Learning for Regression - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/02_pool_regression_getting_started.html>`_,\n- `Pool-based Active Learning - Sample Annotating <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/03_pool_oracle_annotations.html>`_,\n- `Pool-based Active Learning - Simple Evaluation Study <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/04_pool_simple_evaluation_study.html>`_,\n- `Active Image Classification via Self-supervised Learning <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/05_pool_al_with_self_supervised_learning.html>`_,\n- `Multi-annotator Pool-based Active Learning - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/10_multiple_annotators_getting_started.html>`_,\n- `Stream-based Active Learning - Getting Started <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/20_stream_getting_started.html>`_,\n- `Batch Stream-based Active Learning with Pool Query Strategies <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/21_stream_batch_with_pool_al.html>`_,\n- and `Stream-based Active Learning With River <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/tutorials/22_river_classifier.html>`_.\n\nTwo simple code snippets illustrating the straightforwardness of implementing active learning cycles with our Python package ``skactiveml`` are given in the following.\n\nPool-based Active Learning\n##########################\n\nThe following code snippet implements an active learning cycle with 20 iterations using a Gaussian process\nclassifier and uncertainty sampling. To use other classifiers, you can simply wrap classifiers from\n``sklearn`` or use classifiers provided by ``skactiveml``. Note that the main difficulty using\nactive learning with ``sklearn`` is the ability to handle unlabeled data, which we denote as a specific value\n(``MISSING_LABEL``) in the label vector ``y``. More query strategies can be found in the documentation.\n\n.. code-block:: python\n\n    import numpy as np\n    from sklearn.gaussian_process import GaussianProcessClassifier\n    from sklearn.datasets import make_blobs\n    from skactiveml.pool import UncertaintySampling\n    from skactiveml.utils import unlabeled_indices, MISSING_LABEL\n    from skactiveml.classifier import SklearnClassifier\n\n    # Generate data set.\n    X, y_true = make_blobs(n_samples=200, centers=4, random_state=0)\n    y = np.full(shape=y_true.shape, fill_value=MISSING_LABEL)\n\n    # Use the first 10 instances as initial training data.\n    y[:10] = y_true[:10]\n\n    # Create classifier and query strategy.\n    clf = SklearnClassifier(\n        GaussianProcessClassifier(random_state=0),\n        classes=np.unique(y_true),\n        random_state=0\n    )\n    qs = UncertaintySampling(method='entropy')\n\n    # Execute active learning cycle.\n    n_cycles = 20\n    for c in range(n_cycles):\n        query_idx = qs.query(X=X, y=y, clf=clf)\n        y[query_idx] = y_true[query_idx]\n\n    # Fit final classifier.\n    clf.fit(X, y)\n\nAs a result, we obtain an actively trained Gaussian process classifier.\nA corresponding visualization of its decision boundary (black line) and the\nsample utilities (greenish contours) is given below.\n\n.. image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/pal-example-output.png\n   :width: 400\n\nStream-based Active Learning\n############################\n\nThe following code snippet implements an active learning cycle with 200 data points and\nthe default budget of 10% using a pwc classifier and split uncertainty sampling.\nLike in the pool-based example you can wrap other classifiers from ``sklearn``,\n``sklearn`` compatible classifiers or like the example classifiers provided by ``skactiveml``.\n\n.. code-block:: python\n\n    import numpy as np\n    from sklearn.datasets import make_blobs\n    from skactiveml.classifier import ParzenWindowClassifier\n    from skactiveml.stream import Split\n    from skactiveml.utils import MISSING_LABEL\n\n    # Generate data set.\n    X, y_true = make_blobs(n_samples=200, centers=4, random_state=0)\n\n    # Create classifier and query strategy.\n    clf = ParzenWindowClassifier(random_state=0, classes=np.unique(y_true))\n    qs = Split(random_state=0)\n\n    # Initializing the training data as an empty array.\n    X_train = []\n    y_train = []\n\n    # Initialize the list that stores the result of the classifier's prediction.\n    correct_classifications = []\n\n    # Execute active learning cycle.\n    for x_t, y_t in zip(X, y_true):\n        X_cand = x_t.reshape([1, -1])\n        y_cand = y_t\n        clf.fit(X_train, y_train)\n        correct_classifications.append(clf.predict(X_cand)[0] == y_cand)\n        sampled_indices = qs.query(candidates=X_cand, clf=clf)\n        qs.update(candidates=X_cand, queried_indices=sampled_indices)\n        X_train.append(x_t)\n        y_train.append(y_cand if len(sampled_indices) > 0 else MISSING_LABEL)\n\nAs a result, we obtain an actively trained Parzen window classifier.\nA corresponding visualization of its accuracy curve accross the active learning\ncycle is given below.\n\n.. image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/stream-example-output.png\n   :width: 400\n\nQuery Strategy Overview\n#######################\n\nFor better orientation, we provide an `overview <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/strategy_overview.html>`_\n(incl. paper references and `visual examples <https://scikit-activeml.github.io/scikit-activeml-docs/latest/generated/sphinx_gallery_examples/index.html>`_)\nof the query strategies implemented by ``skactiveml``.\n\n|Overview| |Visualization|\n\n.. |Overview| image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/strategy-overview.gif\n   :width: 365\n\n.. |Visualization| image:: https://raw.githubusercontent.com/scikit-activeml/scikit-activeml/master/docs/logos/example-overview.gif\n   :width: 365\n\n.. examples_end\n\n.. citing_start\n\nCiting\n======\nIf you use ``skactiveml`` in one of your research projects and find it helpful,\nplease cite the following:\n\n::\n\n    @article{skactiveml2021,\n        title={scikit-activeml: {A} {L}ibrary and {T}oolbox for {A}ctive {L}earning {A}lgorithms},\n        author={Daniel Kottke and Marek Herde and Tuan Pham Minh and Alexander Benz and Pascal Mergard and Atal Roghman and Christoph Sandrock and Bernhard Sick},\n        journal={Preprints},\n        doi={10.20944/preprints202103.0194.v1},\n        year={2021},\n        url={https://github.com/scikit-activeml/scikit-activeml}\n    }\n\n.. citing_end\n\n\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Our package scikit-activeml is a Python library for active learning on top of SciPy and scikit-learn.",
    "version": "0.5.2",
    "project_urls": {
        "Homepage": "https://github.com/scikit-activeml/scikit-activeml"
    },
    "split_keywords": [
        "active learning",
        " machine learning",
        " semi-supervised learning",
        " data mining",
        " pattern recognition",
        " artificial intelligence"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f73b911fa38b509aaff15fa8670226404a77488d1e58a0e436e894a02351f0f",
                "md5": "cd22836f12a5442aef8589aae32b69c9",
                "sha256": "bee568e3627e8b82c0a6059b72e8b6a6cfd6ab75375bf4d0908f3b05bed82fbb"
            },
            "downloads": -1,
            "filename": "scikit_activeml-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd22836f12a5442aef8589aae32b69c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 303975,
            "upload_time": "2024-08-28T16:01:23",
            "upload_time_iso_8601": "2024-08-28T16:01:23.346114Z",
            "url": "https://files.pythonhosted.org/packages/7f/73/b911fa38b509aaff15fa8670226404a77488d1e58a0e436e894a02351f0f/scikit_activeml-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1efa707f9b62991d3abba5098aa14e501696a3f5f426745bedadc0c230ef1886",
                "md5": "23525ab01534fad7182fa46a4add54ba",
                "sha256": "62f82f6bef22d7873aeb264b22be4c2a0040ec923fd25ad43e0ef2a5e78eaa61"
            },
            "downloads": -1,
            "filename": "scikit-activeml-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "23525ab01534fad7182fa46a4add54ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 212790,
            "upload_time": "2024-08-28T16:01:25",
            "upload_time_iso_8601": "2024-08-28T16:01:25.378818Z",
            "url": "https://files.pythonhosted.org/packages/1e/fa/707f9b62991d3abba5098aa14e501696a3f5f426745bedadc0c230ef1886/scikit-activeml-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-28 16:01:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "scikit-activeml",
    "github_project": "scikit-activeml",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "scikit-activeml"
}
        
Elapsed time: 0.73452s