qxmt.models.qrigge module#
- class qxmt.models.qrigge.QRiggeRegressor(kernel, n_jobs=2, 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)
n_jobs (int)
alpha (float)
kwargs (Any)
- __init__(kernel, n_jobs=2, alpha=1.0, **kwargs)#
Initialize the QRiggeRegressor model.
- Parameters:
kernel (BaseKernel) – kernel instance of BaseKernel class
n_jobs (int) – number of jobs for parallel computation
alpha (float) – Regularization strength; must be a positive float
kwargs (Any)
- Return type:
None
- cross_val_score(X, y, **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
**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
- hyperparameter_search(X, y, sampler_type, search_space, search_args, objective=None, refit=True)#
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
sampler_type (str) – sampler 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:
- 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