In this lab, we will:
Load and preprocess the slope_stability_dataset
Implement classical LR using scikit-learn
Implement VQC in PennyLane
Compare LR and VQC in terms of accuracy
Step 1: Install and import libraries
We can download the dataset and upload it to the Google Drive.
The path to load the dataset is drive-Mydrive-Your folder 1(optional)-Your folder 2(optional)- name of the datasets.csv
Before the training, we have to preprocess the dataset so it can be trained on our machine learning model.
Usually, we will drop the empty rows and standardize the data.
If we have a multidimensional feature space, PCA is used to condense the information and make the training easier. Since we have only 7 features here, we can consider all the features here in our models.
Besides, if we want to train on the quantum model, we should scale the data because we are using angle embeddings, so angles outside the range [-π, π] will be mapped back into this interval.
We can directly load the dataset into our classical model. They are already built in the scikit-learn library.
The first part of our quantum computing is setting up the number of qubits. Usually, it equals the dimensions of the features.
Then we load the data into our quantum model.
Firstly, we use a Hadamard gate to map the initial states |0> into a superposition for later data embedding.
Then we use rotation gates to inject data.
We can also use CNOT/CZ gates to strengthen the connections between features.
In our VQC, it is similar to the CNN. We can build up many layers to train the parameters.
In each layer, we can load the data again in our qubits and use the parameter to do a minor spin.
For the loss function and optimizer, we use the binary cross-entropy to be the loss function, and use the Adam optimizer to train the parameters.