Quantum Classification for Machine Learning

Forge provides the beginnings of quantum machine learning in the form of classification algorithms for fitting data points to a classification model, and predicting the classification of further data points in a unified function.

qcware.forge.qml.fit_and_predict(X: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], model: str, y: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]] = None, T: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]] = None, parameters: dict = {'num_measurements': 100}, backend: str = 'qcware/cpu_simulator')

This function combines both the fitting of data to a quantum model for the purposes of classification and also the use of that trained model for classifying new data. The interface and use are similar to scikit-learn’s fit and predict functions. At the present time, since the fit data comprises (in many cases) both classical and quantum data difficult to serialize, the fitting and prediction are done in a single step. We are looking to separate them into separate fit and predict steps in the future. Four clustering models are implemented at this time (see parameter model)

Arguments:

Parameters
  • X (numpy.typing.ArrayLike) – Training data: \((N\times d)\) array containing training data

  • model (str) – String for the clustering model; one of [‘QNearestCentroid’, ‘QNeighborsClassifier’, ‘QNeighborsRegressor’, ‘QMeans’]

  • y (numpy.typing.ArrayLike) – Label vector: length \(d\) array containing respective labels of each data, defaults to None

  • T (numpy.typing.ArrayLike) – Test data: \((M\times d)\) array containing test data, defaults to None

  • parameters (dict) – Dictionary containing parameters for the model, defaults to {‘num_measurements’: 100}

  • backend (str) – String describing the backend to use, defaults to qcware/cpu_simulator

Returns

A numpy array the length of the test data T containing fit labels

Return type

numpy.array