0% found this document useful (0 votes)
103 views19 pages

Quantum Computing Report

This project report presents a hybrid quantum-classical approach for breast cancer classification using Quantum Support Vector Machines (QSVM). The study aims to enhance traditional SVM methods by leveraging quantum computing to improve classification accuracy and efficiency, particularly for high-dimensional data. The project includes the development of a user-friendly interface for healthcare professionals and explores the potential of quantum machine learning in medical diagnostics.

Uploaded by

AYUSH PAREEK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views19 pages

Quantum Computing Report

This project report presents a hybrid quantum-classical approach for breast cancer classification using Quantum Support Vector Machines (QSVM). The study aims to enhance traditional SVM methods by leveraging quantum computing to improve classification accuracy and efficiency, particularly for high-dimensional data. The project includes the development of a user-friendly interface for healthcare professionals and explores the potential of quantum machine learning in medical diagnostics.

Uploaded by

AYUSH PAREEK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Quantum SVM for Breast Cancer

Classification:
A Hybrid Quantum-Classical
Approach

Ayush Pareek (22BDS011)


Ayush Singh (22BDS012)
Hitesh Sharma (22BDS028)
Pathak Ayush Dilip (22BDS044)
Sanchay Awana (22BCS109)

Under the guidance of


Dr. Aswath Babu

Department of Computer Science and Engineering & Data Science and


Artificial Intelligence
Indian Institute of Information Technology Dharwad
{22bds011, 22bds012, 22bds028, 22bds044, 22bcs109}@iiitdwd.ac.in

April 2025
Mini Project Report Quantum SVM Breast Cancer Classification

Certificate

This is to certify that the project entitled

Quantum SVM for Breast Cancer Classification

is a bonafide record of the mini project coursework presented by the


students listed below during the academic year 2024–2025 in partial
fulfilment of the requirements for the degree of Bachelor of Technology in
Computer Science and Engineering & Data Science and Artificial
Intelligence.

22BDS011 Ayush Pareek


22BDS012 Ayush Singh
22BDS028 Hitesh Sharma
22BDS044 Pathak Ayush Dilip
22BCS109 Sanchay Awana

Dr. Aswath Babu


(Project Supervisor)

Page 1
Mini Project Report Quantum SVM Breast Cancer Classification

Acknowledgements

We would like to express our sincere gratitude to our project supervisor,


Dr. Aswath Babu, for his invaluable guidance, support, and encourage-
ment throughout this project. His expertise in quantum computing and
machine learning has been instrumental in shaping our understanding and
approach to this research.
We extend our thanks to the Department of Computer Science & Data
Science and Artificial Intelligence and Engineering at Indian Institute of
Information Technology Dharwad for providing the necessary resources
and infrastructure to conduct this research. We also acknowledge the
continuous support from our faculty members who have been a source of
inspiration and knowledge.
Our appreciation goes to the open-source communities behind Penny-
lane, Qiskit, and scikit-learn, whose tools and libraries made this project
possible. We are also grateful to the creators of the Breast Cancer Wis-
consin dataset for making this valuable resource available for research.
Finally, we would like to thank our families and friends for their unwa-
vering support and encouragement throughout our academic journey.

Page 2
Mini Project Report Quantum SVM Breast Cancer Classification

Contents
1 Introduction 4
1.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Significance . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Background and Related Work 7


2.1 Classical Machine Learning for Cancer Classification . . . 7
2.2 Quantum Computing Fundamentals . . . . . . . . . . . . . 7
2.3 Quantum Machine Learning . . . . . . . . . . . . . . . . . 8
2.4 Quantum Support Vector Machines . . . . . . . . . . . . . 8
2.5 Recent Applications in Healthcare . . . . . . . . . . . . . . 9
2.6 Quantum Computing Platforms . . . . . . . . . . . . . . . 10

3 Data and Methods 10


3.1 Wisconsin Breast Cancer Dataset . . . . . . . . . . . . . . 10
3.2 Data Preprocessing . . . . . . . . . . . . . . . . . . . . . . 11
3.2.1 Data Cleaning and Standardization . . . . . . . . . 11
3.2.2 Dimensionality Reduction . . . . . . . . . . . . . . 12
3.3 Quantum Kernel Implementation . . . . . . . . . . . . . . 12
3.3.1 Feature Mapping . . . . . . . . . . . . . . . . . . . 12
3.3.2 Circuit Design . . . . . . . . . . . . . . . . . . . . . 13
3.3.3 Kernel Matrix Computation . . . . . . . . . . . . . 13
3.4 Classical SVM with Quantum Kernel . . . . . . . . . . . . 14
3.5 Classical Baselines . . . . . . . . . . . . . . . . . . . . . . 15
3.6 Image Feature Extraction . . . . . . . . . . . . . . . . . . 15
3.6.1 Image Preprocessing . . . . . . . . . . . . . . . . . 15
3.6.2 Feature Extraction Techniques . . . . . . . . . . . . 15

A Source Code Excerpts 18

Page 3
Mini Project Report Quantum SVM Breast Cancer Classification

1 Introduction
Breast cancer remains one of the most prevalent forms of cancer and a
leading cause of cancer-related deaths among women globally. According
to the World Health Organization, approximately 2.3 million women were
diagnosed with breast cancer in 2023, with over 685,000 deaths world-
wide. Early detection and accurate classification of breast tumors as be-
nign or malignant can significantly enhance treatment outcomes and sur-
vival rates. This critical healthcare challenge has prompted researchers
to develop increasingly sophisticated computational methods for cancer
detection and classification.
Traditionally, machine learning methods such as Support Vector Ma-
chines (SVMs), Decision Trees, Random Forests, and Neural Networks
have been applied successfully to this classification problem. However,
with the advent of quantum computing technology, there is a unique op-
portunity to leverage quantum-enhanced algorithms for solving classical
problems more efficiently and potentially with higher accuracy.
Quantum computing utilizes quantum mechanical phenomena such as
superposition and entanglement to perform computational tasks. These
properties enable quantum computers to process information in ways that
classical computers cannot, potentially providing exponential speedups for
certain problems. Quantum machine learning (QML) sits at the inter-
section of quantum computing and machine learning, aiming to harness
quantum advantages for learning tasks.
In this project, we focus on Quantum Support Vector Machine (QSVM),
which utilizes the power of quantum kernel estimation and quantum en-
tanglement to map data into a higher-dimensional Hilbert space, poten-
tially enabling better separability between classes. The core idea is to
perform the kernel calculation, which can be computationally intensive
on classical hardware, using quantum circuits that naturally operate in
high-dimensional spaces.

1.1 Problem Statement


The primary objective of this project is to develop and evaluate a hybrid
quantum-classical approach for breast cancer classification using quantum-
enhanced Support Vector Machines. Specifically, we address the following
questions:
1. How can quantum computing enhance traditional SVM classification

Page 4
Mini Project Report Quantum SVM Breast Cancer Classification

for breast cancer detection?


2. Can quantum kernels provide any advantages over classical kernels in
terms of classification accuracy or computational efficiency?
3. How do quantum-enhanced approaches compare to traditional ma-
chine learning methods for medical image classification?
4. Can we develop a user-friendly interface for healthcare professionals to
utilize quantum-enhanced classification tools without requiring knowl-
edge of quantum computing?

1.2 Objectives
The specific objectives of this project are:
• To explore quantum-enhanced machine learning approaches for health-
care applications, focusing on breast cancer classification.
• To implement a Quantum Support Vector Machine (QSVM) using
Pennylane and integrate it with the classical SVM framework from
scikit-learn.
• To compare the performance of quantum-enhanced models with clas-
sical machine learning approaches on the Breast Cancer Wisconsin
dataset.
• To develop feature extraction techniques for processing breast cancer
histopathological images.
• To create an interactive dashboard using Streamlit for data visualiza-
tion and real-time classification.
• To enable real-time image-based detection using a webcam or image
uploader for potential clinical applications.
• To investigate the scalability and practicality of quantum machine
learning models for healthcare diagnostics.

1.3 Motivation
Several factors motivated our exploration of quantum-enhanced approaches
for breast cancer classification:
1. Limitations of Classical Computation: Classical SVMs face chal-
lenges when dealing with high-dimensional data and complex feature

Page 5
Mini Project Report Quantum SVM Breast Cancer Classification

spaces. The kernel trick, while powerful, can become computation-


ally intensive as datasets grow. Quantum approaches offer potential
advantages in handling high-dimensional feature spaces naturally.
2. Quantum Advantage in Kernel Methods: Recent research sug-
gests that quantum kernels might provide advantages for certain types
of data where classical kernels struggle to find optimal separating hy-
perplanes. The ability to access exponentially large feature spaces
through relatively simple quantum circuits is particularly promising.
3. Need for Novel Approaches in Healthcare: Despite advances in
machine learning for healthcare, there remains room for improvement
in classification accuracy for complex medical conditions like cancer.
Quantum-enhanced models represent a novel direction that could po-
tentially lead to improved diagnostic tools.
4. Bridge Between Theory and Practice: Quantum machine learn-
ing is an emerging field with significant theoretical development but
limited practical applications. This project aims to bridge the gap
between quantum theory and practical applications in healthcare di-
agnostics.
5. Development of Accessible Tools: Making quantum computing
advantages accessible to healthcare professionals without requiring
specialized knowledge is crucial for the adoption of these technologies
in clinical settings.

1.4 Significance
This project contributes to the growing field of quantum machine learn-
ing by demonstrating a practical application in healthcare diagnostics. By
developing a hybrid quantum-classical approach for breast cancer classifi-
cation, we aim to:
• Advance the understanding of quantum kernel methods for real-world
classification tasks
• Provide insights into the potential advantages and limitations of quantum-
enhanced approaches compared to classical methods
• Create accessible tools that enable healthcare professionals to bene-
fit from quantum computing advances without requiring specialized
knowledge

Page 6
Mini Project Report Quantum SVM Breast Cancer Classification

• Contribute to the development of more accurate and efficient diagnos-


tic tools for breast cancer detection

2 Background and Related Work


2.1 Classical Machine Learning for Cancer Classification
Machine learning has been extensively applied to cancer detection and
classification problems over the past few decades. Among these methods,
Support Vector Machines (SVMs) have demonstrated particularly strong
performance due to their ability to find optimal separating hyperplanes in
high-dimensional spaces.
SVMs work by constructing a hyperplane or set of hyperplanes in a
high-dimensional space to separate data points of different classes. The
algorithm seeks to maximize the margin between the hyperplane and the
nearest training data points of any class, which helps improve generaliza-
tion performance. For non-linearly separable data, SVMs employ the ”ker-
nel trick,” which implicitly maps the input features to a higher-dimensional
space where a linear separation might be possible.
Several studies have applied SVMs to breast cancer classification with
impressive results. For instance, Wang et al. (2018) achieved 97.38%
accuracy using SVM with radial basis function (RBF) kernel on the Breast
Cancer Wisconsin dataset. Similarly, Asri et al. (2016) compared several
machine learning algorithms and found that SVM achieved the highest
accuracy (97.13%) among the tested algorithms.
Despite these successes, classical SVMs face limitations in handling ex-
tremely high-dimensional data or complex feature relationships that can-
not be effectively captured by standard kernel functions. Additionally,
the computational complexity of kernel calculations grows quadratically
with the number of training examples, which can be prohibitive for large
datasets.

2.2 Quantum Computing Fundamentals


Quantum computing leverages the principles of quantum mechanics to
perform computation. Unlike classical bits, which can be either 0 or 1,
quantum bits or qubits can exist in a superposition of states, represented
as:

|ψ⟩ = α|0⟩ + β|1⟩ (1)

Page 7
Mini Project Report Quantum SVM Breast Cancer Classification

where α and β are complex numbers satisfying |α|2 + |β|2 = 1, and |0⟩
and |1⟩ are the computational basis states.
Another key principle is entanglement, where the state of a qubit cannot
be described independently of the state of other qubits in the system. This
property allows quantum systems to represent and process information in
ways that classical systems cannot.
Quantum circuits consist of a sequence of quantum gates that manipu-
late qubits. Common gates include:
• Hadamard gate (H): Creates superposition
• Pauli gates (X, Y, Z): Perform rotations around different axes
• CNOT gate: Performs controlled-NOT operation, crucial for creating
entanglement
• Rotation gates (RX, RY, RZ): Rotate qubits by specified angles
Quantum measurement collapses the quantum state to a classical out-
come, with probabilities determined by the amplitudes of the state vector.

2.3 Quantum Machine Learning


Quantum Machine Learning (QML) combines quantum computing prin-
ciples with machine learning algorithms to potentially enhance learning
capabilities. Several approaches exist within QML:
• Variational Quantum Circuits (VQCs): Parameterized quantum
circuits trained using classical optimization methods
• Quantum Neural Networks (QNNs): Neural network architec-
tures implemented on quantum hardware
• Quantum Kernel Methods: Using quantum circuits to compute
kernel functions for classical machine learning algorithms
• Quantum Feature Maps: Encoding classical data into quantum
states to exploit higher-dimensional Hilbert spaces
Our focus in this project is on quantum kernel methods, particularly
Quantum Support Vector Machines (QSVMs).

2.4 Quantum Support Vector Machines


The concept of Quantum Support Vector Machines extends classical SVMs
by leveraging quantum computing to calculate kernel functions. In a

Page 8
Mini Project Report Quantum SVM Breast Cancer Classification

QSVM, classical data is first mapped to quantum states using a quan-


tum feature map. The inner product between these quantum states forms
the kernel matrix, which is then used by a classical SVM algorithm for
classification.
Mathematically, a quantum kernel K(xi , xj ) can be defined as:

K(xi , xj ) = |⟨ϕ(xi )|ϕ(xj )⟩|2 (2)


where |ϕ(x)⟩ represents the quantum state prepared by the feature map
for input vector x.
Havlı́ček et al. (2019) introduced a method for quantum kernel estima-
tion using superconducting circuits. Their approach demonstrated that
certain datasets could be more effectively classified using quantum kernels
than with classical kernels. The authors showed that for specific artifi-
cially constructed datasets, quantum kernels could provide an exponential
advantage over classical kernels.
Schuld and Killoran (2019) proposed a framework using variational
quantum circuits for classification. Their work established theoretical
foundations for encoding classical data into quantum states and leveraging
quantum operations for machine learning tasks.
These advancements form the foundation for our QSVM implementation
in this project.

2.5 Recent Applications in Healthcare


Several recent studies have explored the application of quantum machine
learning to healthcare problems:
• Li et al. (2020) applied quantum-enhanced SVM to electrocardiogram
(ECG) classification, demonstrating comparable performance to clas-
sical methods with potential for scalability advantages.
• Nguyen et al. (2021) used variational quantum circuits for COVID-19
X-ray image classification, achieving 85% accuracy with a relatively
small number of qubits.
• Chen et al. (2022) implemented a quantum kernel estimator for cancer
genomics data, showing modest improvements over classical kernels for
certain cancer subtypes.
Despite these explorations, the application of quantum machine learning
to breast cancer classification remains relatively unexplored, particularly

Page 9
Mini Project Report Quantum SVM Breast Cancer Classification

with respect to integrating image-based feature extraction with quantum


kernel methods.

2.6 Quantum Computing Platforms


Various platforms exist for implementing quantum algorithms, including:
• IBM Qiskit: An open-source SDK for working with quantum com-
puters at the level of pulses, circuits, and algorithms
• Pennylane: A cross-platform Python library for differentiable pro-
gramming of quantum computers
• Google Cirq: A Python framework for creating, editing, and invoking
Noisy Intermediate Scale Quantum (NISQ) circuits
• Microsoft Q#: A domain-specific programming language for ex-
pressing quantum algorithms
For this project, we chose Pennylane due to its seamless integration with
classical machine learning frameworks like PyTorch and scikit-learn, and
its strong support for hybrid quantum-classical models.

3 Data and Methods


3.1 Wisconsin Breast Cancer Dataset
The Breast Cancer Wisconsin (Diagnostic) dataset is a well-established
dataset for evaluating machine learning algorithms for breast cancer clas-
sification. It contains features computed from digitized images of fine
needle aspirate (FNA) of breast masses. The dataset consists of 569 sam-
ples, with 357 benign cases and 212 malignant cases. Each sample has 30
numerical features describing characteristics of the cell nuclei present in
the image.
The features include:
• Radius: Mean of distances from center to points on the perimeter
• Texture: Standard deviation of gray-scale values
• Perimeter: Perimeter of the cell nucleus
• Area: Area of the cell nucleus
• Smoothness: Local variation in radius lengths

Page 10
Mini Project Report Quantum SVM Breast Cancer Classification

• Compactness: Perimeter² / area - 1.0


• Concavity: Severity of concave portions of the contour
• Concave points: Number of concave portions of the contour
• Symmetry: Symmetry of the cell nucleus
• Fractal dimension: ”Coastline approximation” - 1
For each feature, the dataset provides the mean, standard error, and
”worst” (mean of the three largest values) value, resulting in 30 features
total (10 features × 3 measurements).
Feature Category Mean Standard Error ”Worst”
Radius radius mean radius se radius worst
Texture texture mean texture se texture worst
Perimeter perimeter mean perimeter se perimeter worst
Area area mean area se area worst
Smoothness smoothness mean smoothness se smoothness worst
Compactness compactness mean compactness se compactness worst
Concavity concavity mean concavity se concavity worst
Concave points concave points mean concave points se concave points worst
Symmetry symmetry mean symmetry se symmetry worst
Fractal dimension fractal dimension mean fractal dimension se fractal dimension worst

Table 1: Features in the Wisconsin Breast Cancer Dataset

3.2 Data Preprocessing


3.2.1 Data Cleaning and Standardization

The dataset was inspected for missing values, though none were found. To
prepare the data for machine learning algorithms, we applied the following
preprocessing steps:
1. Feature Scaling: We used the StandardScaler from sklearn to stan-
dardize all features to have zero mean and unit variance. This step is
crucial for SVM algorithms, as they are sensitive to the scale of input
features.

x−µ
xscaled = (3)
σ
where µ is the mean and σ is the standard deviation of the feature.
2. Train-Test Split: The dataset was split into training (80%) and
testing (20%) sets using stratified sampling to maintain the class dis-
tribution in both sets.

Page 11
Mini Project Report Quantum SVM Breast Cancer Classification

3. Class Encoding: The target variable (diagnosis) was encoded as 0


for benign and 1 for malignant.
3.2.2 Dimensionality Reduction

Given the constraints of current quantum hardware and simulators, we em-


ployed Principal Component Analysis (PCA) to reduce the dimensionality
of the data while preserving as much variance as possible.

Xreduced = X · W (4)
where X is the standardized data matrix and W is the matrix of prin-
cipal component loadings.
We evaluated different numbers of principal components and selected
8 components, which retained approximately 95% of the variance in the
data. This dimensionality reduction served two purposes:
1. It reduced the computational resources required for quantum simula-
tion
2. It facilitated visualization of the data in lower-dimensional spaces
The explained variance ratio for each principal component is shown in
Table 2.
Principal Component Explained Variance Ratio
1 44.27%
2 19.02%
3 13.20%
4 6.14%
5 4.24%
6 3.04%
7 2.86%
8 2.30%

Table 2: Explained variance ratio for each principal component

3.3 Quantum Kernel Implementation


3.3.1 Feature Mapping

The core of our QSVM approach lies in the quantum feature map, which
encodes classical data into quantum states. We implemented an angle em-
bedding feature map using Pennylane, where each feature value is encoded
as a rotation angle in the quantum circuit.
For a feature vector x ∈ Rn , the angle embedding prepares the quantum
state:

Page 12
Mini Project Report Quantum SVM Breast Cancer Classification

n
O
|ϕ(x)⟩ = (cos(xi )|0⟩ + sin(xi )|1⟩) (5)
i=1
This approach maps each feature to a separate qubit, requiring n qubits
for an n-dimensional feature vector.
3.3.2 Circuit Design

Our quantum kernel implementation consists of the following components:


1. State Preparation: Using AngleEmbedding to encode classical data
into quantum states
2. Feature Interaction: Applying entangling gates (CNOT) between
adjacent qubits to capture feature interactions
3. Non-linearity: Adding RZ and RY rotations to introduce non-linearity
4. Measurement: Computing the fidelity between quantum states as
the kernel value
3.3.3 Kernel Matrix Computation

The quantum kernel function computes the similarity between two data
points xi and xj as:

K(xi , xj ) = |⟨ϕ(xi )|ϕ(xj )⟩|2 (6)


This represents the probability of observing the state |ϕ(xi )⟩ when mea-
suring the state |ϕ(xj )⟩.
We implemented this using Pennylane’s quantum node:
@qml . qnode ( dev )
def quantum_kernel ( x1 , x2 ) :
# Embed first data point
qml . AngleEmbedding ( x1 , wires = range ( n_qubits ) )

# Apply feature interaction layer


for i in range ( n_qubits - 1) :
qml . CNOT ( wires =[ i , i + 1])

# Add non - linearity


for i in range ( n_qubits ) :
qml . RZ ( np . pi /4 , wires = i )

# Embed second data point ( with inverse operations )


for i in range ( n_qubits ) :
qml . RZ ( - np . pi /4 , wires = i )

for i in range ( n_qubits - 1 , 0 , -1) :


qml . CNOT ( wires =[ i -1 , i ])

qml . AngleEmbedding ( x2 , wires = range ( n_qubits ) , rotation = ’Y ’)

Page 13
Mini Project Report Quantum SVM Breast Cancer Classification

# Return probability of observing all qubits in state |0 >


return qml . probs ( wires = range ( n_qubits ) )

The kernel matrix Kij = K(xi , xj ) is computed for all pairs of training
samples and then used as input to a classical SVM classifier.

3.4 Classical SVM with Quantum Kernel


We integrated our quantum kernel with sklearn’s SVM implementation
using the following approach:
1. Compute the quantum kernel matrix for all pairs of training samples
2. Pass this precomputed kernel matrix to sklearn’s SVC (Support Vector
Classification) algorithm
3. Train the SVM using this kernel matrix and the corresponding class
labels
4. For prediction, compute the kernel values between the test samples
and all training samples
The mathematical formulation of the SVM optimization problem with
a precomputed kernel is:
m
1 X
min ∥w∥2 + C ξi
w,b,ξ 2 i=1
(7)
subject to yi (wT ϕ(xi ) + b) ≥ 1 − ξi , i = 1, . . . , m
ξi ≥ 0, i = 1, . . . , m
where C is the regularization parameter, ξi are slack variables, and ϕ(xi )
is the quantum feature map.
In the dual form, this becomes:
m m
X 1X
max αi − αi αj yi yj K(xi , xj )
α
i=1
2 i,j=1
subject to 0 ≤ αi ≤ C, i = 1, . . . , m (8)
Xm
αi y i = 0
i=1
where K(xi , xj ) is our quantum kernel function.

Page 14
Mini Project Report Quantum SVM Breast Cancer Classification

3.5 Classical Baselines


For comparison, we implemented several classical machine learning base-
lines:
1. Linear SVM: SVM with a linear kernel
2. RBF SVM: SVM with a radial basis function kernel
3. Random Forest: An ensemble of decision trees
4. Gradient Boosting: A boosting algorithm using decision trees as
base learners
All baseline models were implemented using sklearn and trained on the
same preprocessed data as the QSVM.

3.6 Image Feature Extraction


To extend our approach to direct image-based classification, we imple-
mented a feature extraction pipeline for histopathological images. The
pipeline consists of the following steps:
3.6.1 Image Preprocessing

1. Resize images to a standard size (224 × 224 pixels)


2. Convert to grayscale
3. Apply histogram equalization to enhance contrast
4. Apply Gaussian blur to reduce noise
3.6.2 Feature Extraction Techniques

We extracted three types of features from the preprocessed images:


1. Gray Level Co-occurrence Matrix (GLCM): GLCM captures
the spatial relationship between pixels by calculating how often pairs
of pixels with specific values occur in a specified spatial relationship.
From the GLCM, we extracted statistical properties:
• Contrast
• Correlation
• Energy
• Homogeneity
• Dissimilarity

Page 15
Mini Project Report Quantum SVM Breast Cancer Classification

Figure 1: Example of a grayscale image used for GLCM analysis

2. Histogram of Oriented Gradients (HOG): HOG counts occur-


rences of gradient orientations in localized portions of an image. It is
particularly useful for capturing edge structures.

Figure 2: HOG visualization showing oriented gradients

3. Histogram features: We computed a histogram of pixel intensities


with 32 bins and extracted statistical measures:
• Mean
• Standard deviation
• Skewness

Page 16
Mini Project Report Quantum SVM Breast Cancer Classification

• Kurtosis
• Energy
• Entropy
The extracted features were concatenated into a single feature vector
and then reduced using PCA to maintain compatibility with our quantum
kernel approach.
def extract_features ( image ) :
# Preprocess image
img_resized = cv2 . resize ( image , (224 , 224) )
img_gray = cv2 . cvtColor ( img_resized , cv2 . COLOR_BGR2GRAY )
img_eq = cv2 . equalizeHist ( img_gray )
img_blur = cv2 . GaussianBlur ( img_eq , (5 , 5) , 0)

# GLCM features
glcm = greycomatrix ( img_blur , [1] , [0 , np . pi /4 , np . pi /2 , 3* np . pi /4] , levels
=256 , symmetric = True , normed = True )
contrast = greycoprops ( glcm , ’ contrast ’)
dissimilarity = greycoprops ( glcm , ’ dissimilarity ’)
homogeneity = greycoprops ( glcm , ’ homogeneity ’)
energy = greycoprops ( glcm , ’ energy ’)
correlation = greycoprops ( glcm , ’ correlation ’)

glcm_props = np . hstack ([ contrast . flatten () , dissimilarity . flatten () ,


homogeneity . flatten () , energy . flatten () ,
correlation . flatten () ])

# Histogram features
hist , _ = np . histogram ( img_blur , bins =32 , range =(0 , 256) )
hist = hist / np . sum ( hist ) # Normalize

# Statistical features from histogram


mean = np . mean ( hist )
std = np . std ( hist )
skewness = skew ( hist )
kurt = kurtosis ( hist )
energy_hist = np . sum ( hist **2)
entropy = - np . sum ( hist * np . log2 ( hist + 1e -10) )

hist_stats = np . array ([ mean , std , skewness , kurt , energy_hist , entropy ])

# HOG features
hog_features = hog ( img_blur , orientations =9 , pixels_per_cell =(10 , 10) ,
cells_per_block =(2 , 2) , visualize = False )

# Combine all features


com bined_features = np . concatenate ([ glcm_props , hist_stats , hog_features ])

return combined_features

Page 17
Mini Project Report Quantum SVM Breast Cancer Classification

A Source Code Excerpts


# Quantum Kernel Definition
@qml . qnode ( dev )
def quantum_kernel ( x1 , x2 ) :
qml . AngleEmbedding ( x1 , wires = range ( n_qubits ) )
qml . AngleEmbedding ( x2 , wires = range ( n_qubits ) )
return qml . probs ( wires = range ( n_qubits ) )

# Feature Extraction from Image


hog_features = hog ( img , pixels_per_cell =(10 ,10) , ...)
com bined_features = np . concatenate ([ glcm_props , hist , hog_features ])

Project Deployment
You can access the deployed project at: Click here to view the deployed
project

References
1. Havlı́ček, V. et al., ”Supervised learning with quantum-enhanced fea-
ture spaces,” Nature (2019).
2. Schuld, M. and Killoran, N., ”Quantum Machine Learning in Feature
Hilbert Spaces,” PRL (2019).
3. Pennylane: https://pennylane.ai
4. Qiskit: https://qiskit.org
5. Breast Cancer Dataset - Sklearn: https://scikit-learn.org

Page 18

You might also like