In this module, Naive Bayes, Hybrid Quantum Naive Bayes, and Quantum Machine Learning will be applied to predict Maintenance Action Recommendations.
Install required libraries
Import required libraries
Mount the drive and read the dataset.
Preprocessing the dataset by encoding categorical data, standardizing numerical features, splitting the data into features (X) and target (y), and performing a train-test split.
Initializing and training a Gaussian Naive Bayes model on training data, making predictions on test data, and calculating the model's accuracy using the test set.
Evaluating the predictive power of each numerical feature using a Naive Bayes model, selecting the top three features based on their scores, and extracting these features for further analysis or modeling.
Defining a quantum circuit using PennyLane, which applies a quantum feature map with input data, introducing entanglement through controlled gates, and performing additional rotations with trainable weights, ultimately returning the expectation value of the Pauli-Z operator on the first qubit.
Defining a quantum circuit that embeds classical inputs using angle embedding, applying multiple layers of entangling operations and trainable rotations, introduces controlled entanglement between qubits, and returns the expectation value of the Pauli-Z operator on the first qubit.
Initializing random weights for two quantum circuits: one is a hybrid quantum-classical circuit, and one is a pure quantum circuit. These weights are used for parameterized gates like RX, RY, RZ, CRZ, and entangling layers in the respective circuits.
Training a hybrid quantum-classical machine learning model using the Adam optimizer, minimizing a mean squared error cost function over multiple epochs with early stopping criteria to prevent overfitting.
Implementing a training loop for a pure quantum machine learning model using the Adam optimizer, where batches of data are randomly sampled, the mean squared error is calculated as the cost function, and weights are updated iteratively over epochs.
Evaluating the performance of two models, a hybrid quantum-classical model, and a pure quantum model, by generating predictions on the test set and calculating their accuracies using the accuracy_score metric.
Printing the final accuracy results for three models: a classical Naive Bayes model, a hybrid quantum-classical machine learning model, and a pure quantum machine learning model.
Visualizing the performance of three models—Classical Naive Bayes, Hybrid QML, and Pure QML—by creating a bar chart that compares their accuracies.
Results: