qxmt.models.base module#
- class qxmt.models.base.BaseKernelModel(kernel, n_jobs=2)
Bases:
BaseMLModel
Base class for kernel-based quantum machine learning models. This class is an abstract class for kernel-based quantum machine learning models. If you want to implement a new kernel-based quantum machine learning model, you should inherit this class. This class requires a kernel instance of BaseKernel class. The user can use any Feature Map or Kernel to be used, as long as it follows the interface of the BaseKernel class.
- Parameters:
kernel (BaseKernel)
n_jobs (int)
- __init__(kernel, n_jobs=2)
Initialize the kernel model.
- Parameters:
kernel (BaseKernel) – kernel instance of BaseKernel class
n_jobs (int)
- Return type:
None
- get_feature_map()
Get the feature map of the model.
- Returns:
feature map instance
- Return type:
BaseFeatureMap
- get_kernel_matrix(x_array_1, x_array_2)
Get the kernel matrix of the given data. This method is alias of kernel.compute_matrix().
- Parameters:
x_array_1 (np.ndarray) – array of samples (ex: training data)
x_array_2 (np.ndarray) – array of samples (ex: test data)
- Returns:
kernel matrix
- Return type:
np.ndarray
- plot_kernel_matrix(x_array_1, x_array_2)
Plot the kernel matrix of the given data. This method is alias of kernel.plot_matrix().
- Parameters:
x_array_1 (np.ndarray) – array of samples (ex: training data)
x_array_2 (np.ndarray) – array of samples (ex: test data)
- Return type:
None
- plot_train_test_kernel_matrix(x_train, x_test)
Plot the kernel matrix of training and testing data. This method is alias of kernel.plot_train_test_matrix().
- Parameters:
x_train (np.ndarray) – array of training samples
x_test (np.ndarray) – array of testing samples
- Return type:
None
- class qxmt.models.base.BaseMLModel
Bases:
ABC
Base class for quantum machine learning models. This class is an abstract class for qunatum machine learning models. If you want to implement a new quantum machine learning model, you should inherit this class. For compatibility with QXMT framework, you should implement some methods such as fit, predict, save, load, get_params, and set_params.
- abstract fit(X, y, **kwargs)
Fit the model with given data.
- Parameters:
X (np.ndarray) – array of features
y (np.ndarray) – array of target value
kwargs (Any)
- Return type:
None
- abstract get_params()
Get the parameters of the model.
- Returns:
dictionary of parameters
- Return type:
dict
- abstract load(path)
Load the model from the given path. [TODO]: standardize the save/load method using same library
- Parameters:
path (str | Path) – path to load the model
- Return type:
BaseMLModel
- abstract predict(X)
Predict the target value with given features.
- Parameters:
X (np.ndarray) – array of features
- Returns:
array of predicted value
- Return type:
np.ndarray
- abstract save(path)
Save the model to the given path. [TODO]: standardize the save/load method using same library
- Parameters:
path (str | Path) – path to save the model
- Return type:
None
- abstract set_params(params)
Set the parameters of the model.
- Parameters:
params (dict) – dictionary of parameters
- Return type:
None