Ta strona nie została jeszcze przetłumaczona na język polski. Oglądasz oryginalną wersję angielską.
Singularity Machine Learning - Classification: A Qiskit Function by Multiverse Computing
- Qiskit Functions are an experimental feature available only to IBM Quantum® Premium Plan, Flex Plan, and On-Prem (via IBM Quantum Platform API) Plan users. They are in preview release status and subject to change.
Overview
With the "Singularity Machine Learning - Classification" function, you can solve real-world machine learning problems on quantum hardware without requiring quantum expertise. This Application function, based on ensemble methods, is a hybrid classifier. It leverages classical methods like boosting, bagging, and stacking for initial ensemble training. Subsequently, quantum algorithms such as variational quantum eigensolver (VQE) and quantum approximate optimization algorithm (QAOA) are employed to enhance the trained ensemble's diversity, generalization capabilities, and overall complexity.
Unlike other quantum machine learning solutions, this function is capable of handling large-scale datasets with millions of examples and features without being limited by the number of qubits in the target QPU. The number of qubits only determines the size of the ensemble that can be trained. It is also highly flexible, and can be used to solve classification problems across a wide range of domains, including finance, healthcare, and cybersecurity.
It consistently achieves high accuracies on classically challenging problems involving high-dimensional, noisy, and imbalanced datasets.
It is built for:
- Engineers and data scientists at companies seeking to enhance their tech offerings by integrating quantum machine learning into their products and services,
- Researchers at quantum research labs exploring quantum machine learning applications and looking to leverage quantum computing for classification tasks, and
- Students and teachers at educational institutions in courses like machine learning, and who are looking to demonstrate the advantages of quantum computing.
The following example showcases its various functionalities, including create, list, fit, and predict, and demonstrates its usage in a synthetic problem comprising two interleaving half circles, a notoriously challenging problem due to its nonlinear decision boundary.
Function description
This Qiskit Function allows users to solve binary classification problems using Singularity's quantum-enhanced ensemble classifier. Behind the scenes, it uses a hybrid approach to classically train an ensemble of classifiers on the labeled dataset, and then optimize it for maximum diversity and generalization using the Quantum Approximate Optimization Algorithm (QAOA) on IBM® QPUs. Through a user-friendly interface, users can configure a classifier according to their requirements, train it on the dataset of their choice, and use it to make predictions on a previously unseen dataset.
To solve a generic classification problem:
- Preprocess the dataset, and split it into training and testing sets. Optionally, you can further split the training set into training and validation sets. This can be achieved using scikit-learn.
- If the training set is imbalanced, you can resample it to balance the classes using imbalanced-learn.
- Upload the training, validation, and test sets separately to the function's storage using the catalog's
file_uploadmethod, passing it the relevant path each time. - Initialize the quantum classifier by using the function's
createaction, which accepts hyperparameters such as the number and types of learners, the regularization (lambda value), and optimization options including the number of layers, the type of classical optimizer, the quantum backend, and so on. - Train the quantum classifier on the training set using the function's
fitaction, passing it the labeled training set, and the validation set if applicable. - Make predictions on the previously unseen test set using the function's
predictaction.
Action-based approach
The function uses an action-based approach. You can think of it as a virtual environment where you use actions to perform tasks or change its state. Currently, it offers the following actions: list, create, delete, fit, predict, fit_predict, and create_fit_predict. The following example demonstrates the create_fit_predict action.
# Added by doQumentation — required packages for this notebook
!pip install -q numpy qiskit-ibm-catalog scikit-learn
# Import QiskitFunctionsCatalog to load the
# "Singularity Machine Learning - Classification" function by Multiverse Computing
from qiskit_ibm_catalog import QiskitFunctionsCatalog
# Import the make_moons and the train_test_split functions from scikit-learn
# to create a synthetic dataset and split it into training and test datasets
from sklearn.datasets import make_moons
from sklearn.model_selection import train_test_split
# authentication
# If you have not previously saved your credentials, follow instructions at
# /docs/guides/functions
# to authenticate with your API key.
catalog = QiskitFunctionsCatalog(channel="ibm_quantum_platform")
# load "Singularity Machine Learning - Classification" function by Multiverse Computing
singularity = catalog.load("multiverse/singularity")
# generate the synthetic dataset
X, y = make_moons(n_samples=1000)
# split the data into training and test datasets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
job = singularity.run(
action="create_fit_predict",
num_learners=10,
regularization=0.01,
optimizer_options={"simulator": True},
X_train=X_train,
y_train=y_train,
X_test=X_test,
options={"save": False},
)
# get job status and result
status = job.status()
result = job.result()
print("Job status: ", status)
print("Action result status: ", result["status"])
print("Action result message: ", result["message"])
print("Predictions (first five results): ", result["data"]["predictions"][:5])
print(
"Probabilities (first five results): ",
result["data"]["probabilities"][:5],
)
print("Usage metadata: ", result["metadata"]["resource_usage"])
Job status: QUEUED
Action result status: ok
Action result message: Classifier created, fitted, and predicted.
Predictions (first five results): [1, 0, 0, 1, 0]
Probabilities (first five results): [[0.16849563539001172, 0.8315043646099888], [0.8726393386620336, 0.12736066133796647], [0.795344837290717, 0.20465516270928288], [0.36822585748882725, 0.6317741425111725], [0.6656662698604361, 0.3343337301395641]]
Usage metadata: {'RUNNING: MAPPING': {'CPU_TIME': 7.945035696029663}, 'RUNNING: WAITING_QPU': {'CPU_TIME': 82.41029238700867}, 'RUNNING: POST_PROCESSING': {'CPU_TIME': 77.3459484577179}, 'RUNNING: EXECUTING_QPU': {'QPU_TIME': 71.27004957199097}}
1. List
The list action retrieves all stored classifiers in *.pkl.tar format from the shared data directory. You can also access the contents of this directory by using the catalog.files() method. In general, the list action searches for files with the *.pkl.tar extension in the shared data directory and returns them in a list format.
Inputs
| Name | Type | Description | Required |
|---|---|---|---|
action | str | The name of the action from among create, list, fit, predict, fit_predict, create_fit_predict and delete. | Yes |
Usage
job = singularity.run(action="list")
2. Create
The create action creates a classifier of the specified quantum_classifier type by using the provided parameters, and saves it in the shared data directory.
The function currently supports only the QuantumEnhancedEnsembleClassifier.