# TNO Quantum: Machine Learning - Regression - Linear regression
TNO Quantum provides generic software components aimed at facilitating the development
of quantum applications.
This package contains implementations of quantum-inspired algorithms for linear regression. It assumes a
linear system of the form `Ax=b`, where `A` is the training data, `x` is a vector of
unknown coefficients, and `b` is a vector of target values.
The class `QILinearEstimator` provides three methods:
`fit`, `predict_x`, and `predict_b`. Once the `fit` method has been called using `A` and `b`,
`predict_x` can be used to sample entries of the estimated coefficient vector. Alternatively,
`predict_b` can be used to sample entries of predictions corresponding to (un)observed
target values.
*Limitations in (end-)use: the content of this software package may solely be used for applications
that comply with international export control laws.*
## Documentation
Documentation of the linear regression package can be found [here](https://tno-
quantum.github.io/documentation/).
## Install
Easily install the `tno.quantum.ml.regression.linear_regression` package using pip:
```console
$ python -m pip install tno.quantum.ml.regression.linear_regression
```
## Example
See example below. More examples can be found in the `test` directory.
```python
import numpy as np
from sklearn.datasets import make_low_rank_matrix
from sklearn.model_selection import train_test_split
from tno.quantum.ml.regression.linear_regression import QILinearEstimator
rng = np.random.RandomState(7)
# Generate example data
m = 700
n = 100
A = make_low_rank_matrix(n_samples=m, n_features=n, effective_rank=3, random_state=rng, tail_strength=0.1)
x = rng.normal(0, 1, A.shape[1])
b = A @ x
# Create training and test datasets
A_train, A_test, b_train, b_test = train_test_split(A, b, test_size=0.3, random_state=rng)
# Fit quantum-inspired model
rank = 3
r = 100
c = 30
n_samples = 100 # for Monte Carlo methods
qi = QILinearEstimator(r, c, rank, n_samples, rng, sketcher_name="fkv")
qi = qi.fit(A_train, b_train)
# Sample from b (vector of predictions)
n_entries_b = 1000
sampled_indices_b, sampled_b = qi.predict_b(A_test, n_entries_b)
```
## Credits
The algorithms found in this repository have been developed in collaboration
with the Quantum Application Lab and have been based on:
- https://github.com/QuantumApplicationLab/quantum-inspired-algorithms
- https://github.com/XanaduAI/quantum-inspired-algorithms
- "Quantum-inspired algorithms in practice", by Juan Miguel Arrazola, Alain Delgado, Bhaskar Roy Bardhan, and Seth Lloyd. 2020-08-13, volume 4, page 307. Quantum 4, 307 (2020).
- "Quantum-inspired low-rank stochastic regression with logarithmic dependence on the dimension", by András Gilyén, Seth Lloyd, Ewin Tang. (2018). ArXiv, abs/1811.04909.
This work was supported by the Dutch National Growth Fund (NGF), as part of the Quantum Delta NL programme.
Raw data
{
"_id": null,
"home_page": null,
"name": "tno.quantum.ml.regression.linear_regression",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "TNO Quantum Code Lab <tnoquantum@tno.nl>",
"keywords": "linear regression, quantum-inspired, linear systems, machine learning",
"author": null,
"author_email": "TNO Quantum Code Lab <tnoquantum@tno.nl>",
"download_url": "https://files.pythonhosted.org/packages/9b/56/1a48942f3528bf336c857ced308860651de8de866f126c744e10e567ca43/tno_quantum_ml_regression_linear_regression-1.0.0.tar.gz",
"platform": "any",
"description": "# TNO Quantum: Machine Learning - Regression - Linear regression\r\n\r\nTNO Quantum provides generic software components aimed at facilitating the development\r\nof quantum applications.\r\n\r\nThis package contains implementations of quantum-inspired algorithms for linear regression. It assumes a \r\nlinear system of the form `Ax=b`, where `A` is the training data, `x` is a vector of\r\nunknown coefficients, and `b` is a vector of target values.\r\n\r\nThe class `QILinearEstimator` provides three methods:\r\n`fit`, `predict_x`, and `predict_b`. Once the `fit` method has been called using `A` and `b`,\r\n`predict_x` can be used to sample entries of the estimated coefficient vector. Alternatively,\r\n`predict_b` can be used to sample entries of predictions corresponding to (un)observed\r\ntarget values.\r\n\r\n*Limitations in (end-)use: the content of this software package may solely be used for applications \r\nthat comply with international export control laws.*\r\n\r\n## Documentation\r\n\r\nDocumentation of the linear regression package can be found [here](https://tno- \r\nquantum.github.io/documentation/).\r\n\r\n## Install\r\n\r\nEasily install the `tno.quantum.ml.regression.linear_regression` package using pip:\r\n\r\n```console\r\n$ python -m pip install tno.quantum.ml.regression.linear_regression\r\n```\r\n\r\n## Example\r\n\r\nSee example below. More examples can be found in the `test` directory.\r\n\r\n```python\r\nimport numpy as np\r\nfrom sklearn.datasets import make_low_rank_matrix\r\nfrom sklearn.model_selection import train_test_split\r\nfrom tno.quantum.ml.regression.linear_regression import QILinearEstimator\r\n\r\nrng = np.random.RandomState(7)\r\n\r\n# Generate example data\r\nm = 700\r\nn = 100\r\nA = make_low_rank_matrix(n_samples=m, n_features=n, effective_rank=3, random_state=rng, tail_strength=0.1)\r\nx = rng.normal(0, 1, A.shape[1])\r\nb = A @ x\r\n\r\n# Create training and test datasets\r\nA_train, A_test, b_train, b_test = train_test_split(A, b, test_size=0.3, random_state=rng)\r\n\r\n# Fit quantum-inspired model\r\nrank = 3\r\nr = 100\r\nc = 30\r\nn_samples = 100 # for Monte Carlo methods\r\nqi = QILinearEstimator(r, c, rank, n_samples, rng, sketcher_name=\"fkv\")\r\nqi = qi.fit(A_train, b_train)\r\n\r\n# Sample from b (vector of predictions)\r\nn_entries_b = 1000\r\nsampled_indices_b, sampled_b = qi.predict_b(A_test, n_entries_b)\r\n```\r\n\r\n## Credits\r\n\r\nThe algorithms found in this repository have been developed in collaboration\r\nwith the Quantum Application Lab and have been based on:\r\n\r\n- https://github.com/QuantumApplicationLab/quantum-inspired-algorithms\r\n- https://github.com/XanaduAI/quantum-inspired-algorithms\r\n- \"Quantum-inspired algorithms in practice\", by Juan Miguel Arrazola, Alain Delgado, Bhaskar Roy Bardhan, and Seth Lloyd. 2020-08-13, volume 4, page 307. Quantum 4, 307 (2020).\r\n- \"Quantum-inspired low-rank stochastic regression with logarithmic dependence on the dimension\", by Andr\u00e1s Gily\u00e9n, Seth Lloyd, Ewin Tang. (2018). ArXiv, abs/1811.04909.\r\n\r\nThis work was supported by the Dutch National Growth Fund (NGF), as part of the Quantum Delta NL programme.\r\n",
"bugtrack_url": null,
"license": "Apache License, Version 2.0",
"summary": "Quantum-inspired algorithms for linear regression.",
"version": "1.0.0",
"project_urls": {
"Documentation": "https://tno-quantum.github.io/documentation/",
"Homepage": "https://github.com/TNO-Quantum/",
"Source": "https://github.com/TNO-Quantum/ml.regression.linear_regression"
},
"split_keywords": [
"linear regression",
" quantum-inspired",
" linear systems",
" machine learning"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4daa16ec32c115e3ee9474f6668db19038ebebc8f92605c825bbb96bb805b550",
"md5": "27a04b552954d1ed38889f347a6f59b6",
"sha256": "8c6ee5a385c561d8555e90acfb82656c1695fec2db4a48647a4b7931075c194c"
},
"downloads": -1,
"filename": "tno_quantum_ml_regression_linear_regression-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "27a04b552954d1ed38889f347a6f59b6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 21469,
"upload_time": "2025-10-17T09:46:30",
"upload_time_iso_8601": "2025-10-17T09:46:30.805502Z",
"url": "https://files.pythonhosted.org/packages/4d/aa/16ec32c115e3ee9474f6668db19038ebebc8f92605c825bbb96bb805b550/tno_quantum_ml_regression_linear_regression-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9b561a48942f3528bf336c857ced308860651de8de866f126c744e10e567ca43",
"md5": "fe6ffd994a3ed6fab6602acea8c34d22",
"sha256": "f32c41a3e16502494d64d59cab78b68cfe3bbf30bcf8f818e02a9f274a4be3f2"
},
"downloads": -1,
"filename": "tno_quantum_ml_regression_linear_regression-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "fe6ffd994a3ed6fab6602acea8c34d22",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 19077,
"upload_time": "2025-10-17T09:46:32",
"upload_time_iso_8601": "2025-10-17T09:46:32.181518Z",
"url": "https://files.pythonhosted.org/packages/9b/56/1a48942f3528bf336c857ced308860651de8de866f126c744e10e567ca43/tno_quantum_ml_regression_linear_regression-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-17 09:46:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TNO-Quantum",
"github_project": "ml.regression.linear_regression",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tno.quantum.ml.regression.linear_regression"
}