dwave-scikit-learn-plugin


Namedwave-scikit-learn-plugin JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryA plugin to scikit-learn for quantum-classical hybrid solving.
upload_time2025-08-15 18:15:46
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements dimod dwave-optimization dwave-system numpy scikit-learn reno
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI](https://img.shields.io/pypi/v/dwave-scikit-learn-plugin.svg)](https://pypi.python.org/pypi/dwave-scikit-learn-plugin)
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/dwavesystems/dwave-scikit-learn-plugin/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/dwavesystems/dwave-scikit-learn-plugin)

# D-Wave `scikit-learn` Plugin

This package provides a [scikit-learn](https://scikit-learn.org/) transformer for 
[feature selection](https://en.wikipedia.org/wiki/Feature_selection) using a
quantum-classical [hybrid solver](https://docs.ocean.dwavesys.com/en/stable/concepts/hybrid.html).

This plugin makes use of a Leap™ quantum-classical hybrid solver. Developers can get started by
[signing up](https://cloud.dwavesys.com/leap/signup/) for the Leap quantum cloud service for free.
Those seeking a more collaborative approach and assistance with building a production application can
reach out to D-Wave [directly](https://www.dwavesys.com/solutions-and-products/professional-services/) and also explore the feature selection [offering](https://aws.amazon.com/marketplace/pp/prodview-bsrc3yuwgjbo4) in AWS Marketplace.

The package's main class, `SelectFromQuadraticModel`, can be used in any existing `sklearn` pipeline.
For an introduction to hybrid methods for feature selection, see the [Feature Selection for CQM](https://github.com/dwave-examples/feature-selection-cqm).

## Examples

### Basic Usage

A minimal example of using the plugin to select 20 of 30 features of an `sklearn` dataset: 

```python
>>> from sklearn.datasets import load_breast_cancer
>>> from dwave.plugins.sklearn import SelectFromQuadraticModel
... 
>>> X, y = load_breast_cancer(return_X_y=True)
>>> X.shape
(569, 30)
>>> # solver can also be equal to "cqm"
>>> X_new = SelectFromQuadraticModel(num_features=20, solver="nl").fit_transform(X, y)
>>> X_new.shape
(569, 20)
```

For large problems, the default runtime may be insufficient. You can use the CQM solver's [`time_limit`](https://docs.dwavequantum.com/en/latest/industrial_optimization/solver_cqm_parameters.html#time-limit) or Nonlinear (NL) solver's
[`time_limit`](https://docs.dwavequantum.com/en/latest/industrial_optimization/solver_nl_parameters.html#time-limit)
method to find the minimum accepted runtime for your problem; alternatively, simply submit as above 
and check the returned error message for the required runtime. 

The feature selector can be re-instantiated with a longer time limit.

```python
>>> # solver can also be equal to "nl"
>>> X_new = SelectFromQuadraticModel(num_features=20, time_limit=200, solver="cqm").fit_transform(X, y)
```

### Tuning

You can use `SelectFromQuadraticModel` with scikit-learn's
[hyper-parameter optimizers](https://scikit-learn.org/stable/modules/classes.html#hyper-parameter-optimizers).

For example, the number of features can be tuned using a grid search. **Please note that this will
submit many problems to the hybrid solver.**

```python
>>> import numpy as np
...
>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.model_selection import GridSearchCV
>>> from sklearn.pipeline import Pipeline
>>> from dwave.plugins.sklearn import SelectFromQuadraticModel
...
>>> X, y = load_breast_cancer(return_X_y=True)
...
>>> num_features = X.shape[1]
>>> searchspace = np.linspace(1, num_features, num=5, dtype=int, endpoint=True)
...
>>> # solver can also be equal to "cqm"
>>> pipe = Pipeline([
>>>   ('feature_selection', SelectFromQuadraticModel(solver="nl")),
>>>   ('classification', RandomForestClassifier())
>>> ])
...
>>> clf = GridSearchCV(pipe, param_grid=dict(feature_selection__num_features=searchspace))
>>> search = clf.fit(X, y)
>>> print(search.best_params_)
{'feature_selection__num_features': 22}
```

## Installation

To install the core package:

```bash
pip install dwave-scikit-learn-plugin
```

## License

Released under the Apache License 2.0

## Contributing

Ocean's [contributing guide](https://docs.ocean.dwavesys.com/en/stable/contributing.html)
has guidelines for contributing to Ocean packages.

### Release Notes

**dwave-scikit-learn-plugin** makes use of [reno](https://docs.openstack.org/reno/) to manage its
release notes.

When making a contribution to **dwave-scikit-learn-plugin** that will affect users, create a new
release note file by running

```bash
reno new your-short-descriptor-here
```

You can then edit the file created under ``releasenotes/notes/``.
Remove any sections not relevant to your changes.
Commit the file along with your changes.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dwave-scikit-learn-plugin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "\"D-Wave Inc.\" <tools@dwavesys.com>",
    "download_url": "https://files.pythonhosted.org/packages/04/08/4eb091c429b4ecdf92b7b435df209938a70c9aecda1d86e0bc216422d3b6/dwave_scikit_learn_plugin-0.2.0.tar.gz",
    "platform": null,
    "description": "[![PyPI](https://img.shields.io/pypi/v/dwave-scikit-learn-plugin.svg)](https://pypi.python.org/pypi/dwave-scikit-learn-plugin)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/dwavesystems/dwave-scikit-learn-plugin/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/dwavesystems/dwave-scikit-learn-plugin)\n\n# D-Wave `scikit-learn` Plugin\n\nThis package provides a [scikit-learn](https://scikit-learn.org/) transformer for \n[feature selection](https://en.wikipedia.org/wiki/Feature_selection) using a\nquantum-classical [hybrid solver](https://docs.ocean.dwavesys.com/en/stable/concepts/hybrid.html).\n\nThis plugin makes use of a Leap\u2122 quantum-classical hybrid solver. Developers can get started by\n[signing up](https://cloud.dwavesys.com/leap/signup/) for the Leap quantum cloud service for free.\nThose seeking a more collaborative approach and assistance with building a production application can\nreach out to D-Wave [directly](https://www.dwavesys.com/solutions-and-products/professional-services/) and also explore the feature selection [offering](https://aws.amazon.com/marketplace/pp/prodview-bsrc3yuwgjbo4) in AWS Marketplace.\n\nThe package's main class, `SelectFromQuadraticModel`, can be used in any existing `sklearn` pipeline.\nFor an introduction to hybrid methods for feature selection, see the [Feature Selection for CQM](https://github.com/dwave-examples/feature-selection-cqm).\n\n## Examples\n\n### Basic Usage\n\nA minimal example of using the plugin to select 20 of 30 features of an `sklearn` dataset: \n\n```python\n>>> from sklearn.datasets import load_breast_cancer\n>>> from dwave.plugins.sklearn import SelectFromQuadraticModel\n... \n>>> X, y = load_breast_cancer(return_X_y=True)\n>>> X.shape\n(569, 30)\n>>> # solver can also be equal to \"cqm\"\n>>> X_new = SelectFromQuadraticModel(num_features=20, solver=\"nl\").fit_transform(X, y)\n>>> X_new.shape\n(569, 20)\n```\n\nFor large problems, the default runtime may be insufficient. You can use the CQM solver's [`time_limit`](https://docs.dwavequantum.com/en/latest/industrial_optimization/solver_cqm_parameters.html#time-limit) or Nonlinear (NL) solver's\n[`time_limit`](https://docs.dwavequantum.com/en/latest/industrial_optimization/solver_nl_parameters.html#time-limit)\nmethod to find the minimum accepted runtime for your problem; alternatively, simply submit as above \nand check the returned error message for the required runtime. \n\nThe feature selector can be re-instantiated with a longer time limit.\n\n```python\n>>> # solver can also be equal to \"nl\"\n>>> X_new = SelectFromQuadraticModel(num_features=20, time_limit=200, solver=\"cqm\").fit_transform(X, y)\n```\n\n### Tuning\n\nYou can use `SelectFromQuadraticModel` with scikit-learn's\n[hyper-parameter optimizers](https://scikit-learn.org/stable/modules/classes.html#hyper-parameter-optimizers).\n\nFor example, the number of features can be tuned using a grid search. **Please note that this will\nsubmit many problems to the hybrid solver.**\n\n```python\n>>> import numpy as np\n...\n>>> from sklearn.datasets import load_breast_cancer\n>>> from sklearn.ensemble import RandomForestClassifier\n>>> from sklearn.model_selection import GridSearchCV\n>>> from sklearn.pipeline import Pipeline\n>>> from dwave.plugins.sklearn import SelectFromQuadraticModel\n...\n>>> X, y = load_breast_cancer(return_X_y=True)\n...\n>>> num_features = X.shape[1]\n>>> searchspace = np.linspace(1, num_features, num=5, dtype=int, endpoint=True)\n...\n>>> # solver can also be equal to \"cqm\"\n>>> pipe = Pipeline([\n>>>   ('feature_selection', SelectFromQuadraticModel(solver=\"nl\")),\n>>>   ('classification', RandomForestClassifier())\n>>> ])\n...\n>>> clf = GridSearchCV(pipe, param_grid=dict(feature_selection__num_features=searchspace))\n>>> search = clf.fit(X, y)\n>>> print(search.best_params_)\n{'feature_selection__num_features': 22}\n```\n\n## Installation\n\nTo install the core package:\n\n```bash\npip install dwave-scikit-learn-plugin\n```\n\n## License\n\nReleased under the Apache License 2.0\n\n## Contributing\n\nOcean's [contributing guide](https://docs.ocean.dwavesys.com/en/stable/contributing.html)\nhas guidelines for contributing to Ocean packages.\n\n### Release Notes\n\n**dwave-scikit-learn-plugin** makes use of [reno](https://docs.openstack.org/reno/) to manage its\nrelease notes.\n\nWhen making a contribution to **dwave-scikit-learn-plugin** that will affect users, create a new\nrelease note file by running\n\n```bash\nreno new your-short-descriptor-here\n```\n\nYou can then edit the file created under ``releasenotes/notes/``.\nRemove any sections not relevant to your changes.\nCommit the file along with your changes.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A plugin to scikit-learn for quantum-classical hybrid solving.",
    "version": "0.2.0",
    "project_urls": {
        "Download": "https://github.com/dwavesystems/dwave-scikit-learn-plugin/releases",
        "Homepage": "https://github.com/dwavesystems/dwave-scikit-learn-plugin"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "910f7518d9973ebcf1c50fe56ba2ece1b1937566a39f2ee9ff5b1a0b99b4e08f",
                "md5": "158beb842e6237511c9ed2347c33749e",
                "sha256": "5b63e2c0aa8e1940c9ce56bbaf259dd2b1fa46b8b82fd5448175a0942ade9832"
            },
            "downloads": -1,
            "filename": "dwave_scikit_learn_plugin-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "158beb842e6237511c9ed2347c33749e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 16643,
            "upload_time": "2025-08-15T18:15:45",
            "upload_time_iso_8601": "2025-08-15T18:15:45.611072Z",
            "url": "https://files.pythonhosted.org/packages/91/0f/7518d9973ebcf1c50fe56ba2ece1b1937566a39f2ee9ff5b1a0b99b4e08f/dwave_scikit_learn_plugin-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "04084eb091c429b4ecdf92b7b435df209938a70c9aecda1d86e0bc216422d3b6",
                "md5": "0e0ec5c0a5f77f0c6efffb441c57598f",
                "sha256": "1976acb97c740df46e50d2452ed1a04ded892c8bec77ad18901b69ec6117d869"
            },
            "downloads": -1,
            "filename": "dwave_scikit_learn_plugin-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e0ec5c0a5f77f0c6efffb441c57598f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 20575,
            "upload_time": "2025-08-15T18:15:46",
            "upload_time_iso_8601": "2025-08-15T18:15:46.420812Z",
            "url": "https://files.pythonhosted.org/packages/04/08/4eb091c429b4ecdf92b7b435df209938a70c9aecda1d86e0bc216422d3b6/dwave_scikit_learn_plugin-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-15 18:15:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dwavesystems",
    "github_project": "dwave-scikit-learn-plugin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [
        {
            "name": "dimod",
            "specs": [
                [
                    "==",
                    "0.12.20"
                ]
            ]
        },
        {
            "name": "dwave-optimization",
            "specs": [
                [
                    "==",
                    "0.6.2"
                ]
            ]
        },
        {
            "name": "dwave-system",
            "specs": [
                [
                    "==",
                    "1.32.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "2.0.2"
                ]
            ]
        },
        {
            "name": "scikit-learn",
            "specs": [
                [
                    "==",
                    "1.6.1"
                ]
            ]
        },
        {
            "name": "reno",
            "specs": [
                [
                    "==",
                    "3.5.0"
                ]
            ]
        }
    ],
    "lcname": "dwave-scikit-learn-plugin"
}
        
Elapsed time: 0.63801s