"# Classification with SVM on the D-Wave Advantage Qauntum Annealer"
"# Classification with SVM on the D-Wave Advantage Quantum Annealer"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Classification with SVM on the D-Wave Advantage Qauntum Annealer
# Classification with SVM on the D-Wave Advantage Quantum Annealer
%% Cell type:markdown id: tags:
#### This notebook performs the evaluation and visualization of the results returned from the quantum annealer. The results have to be obtained with another script (e.g. submit_experiments.sh).
The classification map that is reported in the paper is the one obtained with the following parameters:
- B = 3
- K = 2
- gamma = -1
- xi = 5
- E = 0
- embedding 2
- annealing time = 100
- rel. chain strength = 0.5
- Energy -45.506845443310596
On test data
- Overal accuracy 0.873516
- F1 score 0.7344402173456618
%% Cell type:markdown id: tags:
## Import Packages
%% Cell type:code id: tags:
``` python
import numpy as np
import glob
from utils import *
import matplotlib.pyplot as plt
from matplotlib import colors
from sklearn import preprocessing
from sklearn.metrics import accuracy_score
from sklearn.metrics import f1_score
from quantum_SVM import * # QA SVM
```
%% Cell type:markdown id: tags:
## Load the training and test sets
%% Cell type:code id: tags:
``` python
# Load training set
key='_tiny'
X_train=np.load('X_train_tile_4'+key+'.npy')
Y_train=np.load('Y_train_tile_4'+key+'.npy')
print('X_train',X_train.shape)
print('Y_train',Y_train.shape)
# Load test set
X_test=np.load('X_test_tile_8_subregion.npy')
Y_test=np.load('Y_test_tile_8_subregion.npy')
print('X_test',X_test.shape)
print('Y_test',Y_test.shape)
# for training, the labels have to be -1,+1; i.e., replace 0 -> -1
Y_train=np.where(Y_train==0,-1,Y_train)
groundtruth=np.reshape(Y_test,(500,500))
plt.title('Groundtruth')
cmap = colors.ListedColormap(['black', 'red'])
plt.rcParams["figure.figsize"] = (5,5)
view=plt.imshow(groundtruth,cmap=cmap)
```
%% Output
X_train (50, 8)
Y_train (50,)
X_test (250000, 8)
Y_test (250000,)
%% Cell type:markdown id: tags:
## QSVM
%% Cell type:markdown id: tags:
### Parameters
%% Cell type:code id: tags:
``` python
outputpath='output/run_calibtrain'+key
maxalphas=20 # the 20 lowest-energy results returned by the quantum annealer are stored, but for the evaluation, we can consider less and compare
# Parameters
Bs=[2,3] #[2,3,5,10] Base
Ks=[2] #[2,3] Number of qubits
xis=[0,1,5] #[0,1,5] Strength to consider the constraint