Predict Survival
Learn how to predict survival using the quantum Naive Bayes classifier.
Let’s see how it performs on predicting the survival of the passengers.
We’ll apply our proven procedure of a variational quantum-classical algorithm. We’ll start with pre-processing the data to prepare a quantum state, evaluate the quantum state, and post-process the measurement.
Pre‐processing
The pre-processing is quite simple.
Press + to interact
def pre_process(passenger):return (passenger['IsChild'] == 1, passenger['Sex'] == 'female', passenger['Pclass'])
We’ll take the entry of a passenger and return a tuple of whether the value of IsChild
is 1
, the value of Sex
is female
, and the ticket-class. We’ll apply these three values in the quantum circuit.
Applying the known data on the quantum circuit
Press + to interact
def apply_known(qc, is_child, is_female, pclass):if is_child:qc.x(QPOS_ISCHILD)if is_female:qc.x(QPOS_SEX)qc.x(QPOS_FIRST if pclass == 1 else (QPOS_SECOND if pclass == 2 else QPOS_THIRD))
If the passenger is a ...