-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make VQC & QNN Scikit-learn compliant #494
Comments
There is a guide how to develop scikit learn compatible estimators: https://scikit-learn.org/stable/developers/develop.html |
class VQC_Sklearn(VQC, NeuralNetworkClassifier, BaseEstimator, ClassifierMixin):
def get_params(self, deep=True):
out = dict()
for key in self._get_param_names():
## The if statement is to bypass "callback" and "quantum_instance" attribute not defined
if (key != "callback" and key != "quantum_instance"):
value = getattr(self, key)
if deep and hasattr(value, "get_params") and not isinstance(value, type):
deep_items = value.get_params().items()
out.update((key + "__" + k, val) for k, val in deep_items)
out[key] = value
return out However, I still get the AttributeError: can't set attribute |
I guess, |
Finally, thanks a lot to [email protected], the solution below worked for me:
|
If you don't mind, I'd keep this issue open as it is not resolved in the QML code. |
I have an opinion on this, we can try some approaches to fix this issue.
|
@GayatriVadaparty Let me know if you want to work on this Issue as a collaboration |
@AbdullahKazi500 Yes, I wanted to work on this issue. I have recently got to understand all the approaches you mentioned above. |
@adekusar-drl
|
It seems that the ZZFeatureMap class in Qiskit is not compatible with scikit-learn's GridSearchCV due to the dynamic nature of the circuit construction. To work around this issue, I have manually loop over the parameter grid and perform the grid search without relying on scikit-learn's GridSearchCV |
@GayatriVadaparty Great contact me on discord |
To perform hyperparameter tuning using Bayesian optimization with the Qiskit Machine Learning package, we can use the BayesianOptimization class provided by the skopt library, which is compatible with scikit-learn's GridSearchCV and RandomizedSearchCV In this code, I have first define the parameter search space using a dictionary called param_space, which includes the possible values for the hyperparameters. Then, define the feature map, create the VQC estimator, and instantiate the BayesSearchCV object, providing the VQC estimator and the parameter search space. We set the number of iterations (n_iter) and the number of cross-validation folds (cv). Next, we call the fit method of the search object, passing the training data. The search object performs Bayesian optimization to find the best hyperparameters based on the specified search space. After the hyperparameter tuning is complete, we can access the best hyperparameters using the best_params_ attribute of the search object and the corresponding best score using the best_score_ attribute. Finally, we set the best hyperparameters to the VQC estimator, fit the model on the training data, predict on the test set, and calculate the accuracy score. I had some problems working on the TQDM part here |
That's interesting, but it is unrelated to the original issue. Originally, the intention was to make QML algorithms scikit-learn compliant. |
@adekusar-drl exactly which QML Algorithms is not mentioned I guess every algorithm or only VQC or QNN |
At least algorithms in |
@adekusar-drl my_package/ |
Basically by adding a new folder and corresponding files in it. |
@adekusar-drl Do I Make a pull request with the Ipynb or you want to see it first |
In this issue I don't see a place where a notebook would be required, honestly. So, if you have only a notebook, then please convert it to the code that will make the algorithm scikit-learn compatible. |
@adekusar-drl Okay I have the code so how can we add this as a feature |
|
What is the expected enhancement?
VQC & QNN does not allow to implement Sklearn BaseEstimator to be inherited. Hence, we are unable to use Sklearn Gridsearch on VQC & QNN estimators for hyperparameter tuning.
The text was updated successfully, but these errors were encountered: