qxmt.models.qrigge module#

class qxmt.models.qrigge.QRiggeRegressor(kernel, alpha=1.0, **kwargs)#

Bases: BaseKernelModel

Quantum Rigge Regressor model.

Detail of Kernel Rigge Regressor model is refered to the sklearn.kernel_ridge.KernelRidge class. Reference: https://scikit-learn.org/stable/modules/generated/sklearn.kernel_ridge.KernelRidge.html

Parameters:
  • BaseKernelModel (_type_) – kernel instance of BaseKernel class

  • kernel (BaseKernel)

  • alpha (float)

  • kwargs (Any)

__init__(kernel, alpha=1.0, **kwargs)#

Initialize the QRiggeRegressor model.

Parameters:
  • kernel (BaseKernel) – kernel instance of BaseKernel class

  • alpha (float) – Regularization strength; must be a positive float

  • kwargs (Any)

Return type:

None

cross_val_score(X, y, n_jobs=3, **kwargs)#

Cross validation score of the Quantum Kernel Ridge Regressor model. Default to use the R^2 score.

Parameters:
  • X (np.ndarray) – numpy array of input data

  • y (np.ndarray) – numpy array of target data

  • n_jobs (int) – number of jobs to run in parallel

  • **kwargs (dict) – additional arguments

Returns:

array of scores of the estimator for each run of the cross validation

Return type:

np.ndarray

fit(X, y, save_shots_path=None)#

Fit the model with given input data and target data.

Parameters:
  • X (np.ndarray) – numpy array of input data

  • y (np.ndarray) – numpy array of target data

  • save_shots_path (Optional[Path | str], optional) – save path for the shot results. Defaults to None.

Return type:

None

get_params()#

Get the parameters of the model.

Return type:

dict

Search the best hyperparameters for the Quantum Kernel Ridge Regressor model.

Parameters:
  • X (np.ndarray) – dataset for search

  • y (np.ndarray) – target values for search

  • search_type (str) – search type for hyperparameter search (grid, random, tpe)

  • search_space (dict[str, list[Any]]) – search space for hyperparameter search

  • search_args (dict[str, Any]) – search arguments for hyperparameter search

  • objective (Optional[Callable], optional) – objective function for search. Defaults to None.

  • refit (bool, optional) – refit the model with best hyperparameters. Defaults to True.

Raises:

ValueError – Not supported search type

Returns:

best hyperparameters

Return type:

dict[str, Any]

load(path)#

Load the trained model from the given path.

Parameters:

path (str | Path) – path to load the model

Returns:

loaded QRiggeRegressor model

Return type:

QRiggeRegressor

predict(X)#

Predict target values of input data.

Parameters:

X (np.ndarray) – numpy array of input data

Returns:

numpy array of predicted target values

Return type:

np.ndarray

save(path)#

Save the model to the given path.

Parameters:

path (str | Path) – path to save the model

Return type:

None

score(X, y, sample_weight=None)#

Return the coefficient of determination R^2 of the prediction.

Parameters:
  • X (np.ndarray) – numpy array of input data

  • y (np.ndarray) – numpy array of target data

  • sample_weight (ndarray | None)

Returns:

R^2 of the prediction

Return type:

float

set_params(params)#

Set the parameters of the model.

Parameters:

params (dict)

Return type:

None