0% found this document useful (0 votes)
3 views17 pages

Machine Learning for PCOS Detection

This document discusses the development of machine learning models for the detection of Polycystic Ovary Syndrome (PCOS) using a dataset of 541 patient records. It outlines the preprocessing steps, including data cleaning, handling missing values, and exploratory data analysis, as well as the implementation of various models such as Logistic Regression, Neural Networks, and Support Vector Machines (SVM). The project aims to create an automated, accurate, and scalable system for early PCOS detection to assist clinicians in decision-making.

Uploaded by

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

Machine Learning for PCOS Detection

This document discusses the development of machine learning models for the detection of Polycystic Ovary Syndrome (PCOS) using a dataset of 541 patient records. It outlines the preprocessing steps, including data cleaning, handling missing values, and exploratory data analysis, as well as the implementation of various models such as Logistic Regression, Neural Networks, and Support Vector Machines (SVM). The project aims to create an automated, accurate, and scalable system for early PCOS detection to assist clinicians in decision-making.

Uploaded by

writerdolanb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Machine Learning–Based Detection of Polycystic

Ovary Syndrome (PCOS)


Group Members:
Department of Electrical & Electronic Engineering
Dedan Kimathi University of Technology
Introduction
Polycystic Ovary Syndrome (PCOS) is a common endocrine disorder affecting women
of reproductive age and is a leading cause of infertility. It is characterized by hormonal
imbalance, irregular menstrual cycles, hyperandrogenism, and polycystic ovarian mor-
phology. Despite its high prevalence, PCOS remains underdiagnosed due to overlapping
symptoms and reliance on subjective clinical judgment.
Traditional diagnostic procedures involve laboratory testing, ultrasound imaging, and
clinical assessment, which are often expensive, time-consuming, and inconsistent across
healthcare facilities. These limitations motivate the use of machine learning techniques
capable of learning complex patterns from clinical data.
Problem Statement:
There is a lack of automated, accurate, and scalable systems
for early PCOS detection using routinely collected patient data. This project seeks to
develop machine learning models that can reliably predict PCOS and assist clinicians in
decision-making
DATASET OVERVIEW
The PCOS dataset contains 541 patient records and 45 features and is designed for the
analysis and prediction of Polycystic Ovary Syndrome (PCOS). Each record represents
an individual patient and includes a wide range of demographic, clinical, lifestyle, and
gynecological attributes.
Key demographic features include age, weight, height, and body mass index (BMI).
Clinical measurements such as blood pressure (systolic and diastolic), pulse rate, and res-piratory
rate are also provided. The dataset further incorporates lifestyle-related factors,
including fast food consumption and regular exercise habits. Gynecological and medical
indicators such as follicle count and size for both ovaries, endometrium thickness, and
blood group information are included, which are clinically relevant to PCOS diagnosis.
The target variable, PCOS (Y/N), is a binary label indicating whether a patient has
PCOS (1) or not (0). The dataset contains a mix of numerical and binary categorical
variables, and some attributes include missing or irrelevant values, requiring preprocessing
before model training. Overall, this dataset is suitable for binary classification tasks
and supports the development and evaluation of machine learning models for PCOS
prediction.
PREPROCESSING
Data Cleaning After Merging
After merging the datasets, several preprocessing steps were performed to ensure data quality
and consistency. Some columns contained numeric values that were incorrectly stored as strings
due to formatting issues during Excel or CSV storage. These columns were converted to numeric
data types, and any invalid or unexpected values were automatically converted to NaN.
Additionally, column names containing leading or trailing whitespace were cleaned, and
simplified column names without spaces were assigned to facilitate easier coding and analysis.
Handling Missing Values
Missing values were addressed by replacing them with the median of the respective columns.
The median was chosen instead of the mean because it is more robust to outliers and better
represents the central tendency of skewed data. After imputation, a summary of the dataset was
generated to verify the effectiveness of the cleaning process.
Correlation Analysis and Heatmap
Correlation analysis was performed using the [Link]() function, which computes pairwise
correlation coefficients between all numerical features in the dataset. These coefficients range
from −1 to 1, where values close to 1 indicate a strong positive correlation, values near −1
indicate a strong negative correlation, and values around 0 indicate little or no linear relationship.
A heatmap was used to visualize these correlations and to identify features that show the
strongest relationship with the target variable. This analysis is particularly useful for feature
selection and for understanding which clinical and lifestyle factors are most influential in
predicting or diagnosing PCOS.
Interpretation
The correlation analysis shows that Follicle Number in the right ovary and left ovary have the
strongest positive relationships with PCOS, with correlation coefficients of 0.65 and 0.60,
respectively. This indicates that an increased number of follicles in either ovary is strongly
associated with PCOS, which aligns with clinical knowledge, as PCOS is characterized by the
presence of multiple ovarian follicles or cysts.
Other features such as skin darkening, excess hair growth, and weight gain exhibit moderate
positive correlations with PCOS (approximately 0.40–0.48). These variables represent common
clinical symptoms of PCOS and reflect the underlying hormonal imbalances associated with the
condition.
The heatmap also reveals the presence of multicollinearity among certain features. Notably,
Follicle Number (Left) and Follicle Number (Right) show a very strong correlation (0.80),
indicating that they tend to increase and decrease together. To reduce redundancy, one of these
features can be removed; preference is given to the feature with the stronger correlation to the
target variable. Similarly, Weight (kg) and BMI exhibit a high correlation (0.92), which is
expected since BMI is derived from weight and height.
Based on these observations, Right Follicle Number and BMI were removed from the dataset to
reduce multicollinearity and improve model efficiency.
EXPLORATORY DATA ANALYSIS (EDA)
The first step in our analysis involved examining the distributions of all numerical variables
using histograms. This initial visualization allowed us to identify potential irregularities in
certain features as shown below:

Upon inspection, we observed that the following variables exhibited extreme right-skewness:
Cycle Length, FSH, LH, FSH/LH ratio, PRG, and Vitamin D3. Prior to conducting further
analysis, these anomalies warranted closer investigation.
Specifically:
 Cycle Length: This feature contains values representing a number of days. Conceptually,
it is more appropriate to treat this variable as a discretized category rather than a
continuous variable. Therefore, we performed discretization to better reflect its logical
interpretation.
 FSH and LH: These variables are often considered together as a ratio. By computing the
FSH/LH ratio and using it in place of the two separate columns, we were able to reduce
dimensionality while retaining the essential information.
 Highly skewed variables: For the remaining features with extreme skewness, we applied
logarithmic transformations to normalize their distributions and mitigate the impact of
outliers.

Following these preprocessing steps, the distributions of the transformed variables were more
balanced, allowing for more reliable downstream analysis.
Principal Component Analysis (PCA)
Principal Component Analysis (PCA) is a linear algebra-based dimensionality reduction
technique that operates exclusively on numerical data, assuming continuous and scaled input
features. In this study, PCA was applied to the preprocessed dataset to explore underlying
patterns and reduce dimensionality. We initially retained 2 principal components for visualization
purposes.
The bar chart generated from the analysis illustrates the variance explained by each individual
principal component. As expected, the contribution of each subsequent component diminishes,
indicating that higher-order components capture progressively less variance. The orange line
with markers represents the cumulative variance explained as additional components are
included.
The PCA results indicate that, while some structure distinguishing PCOS from non-PCOS cases
is captured in the first two dimensions, the separation is not fully distinct. This suggests that
relevant information may reside in higher-dimensional space. Based on the cumulative variance
plot, approximately 20 principal components are required to adequately explain the majority of
variance in the dataset, highlighting the intrinsic complexity of the features.
MODELS
LOGISTIC REGRESSION
The dataset was first prepared by separating the target variable, PCOS (Y/N), from the input
features. Columns such as Sl. No and Patient File No. were removed because they serve only as
identifiers and do not provide predictive information. Categorical variables present in the dataset
were converted into numerical form using one-hot encoding. This step ensures compatibility with
machine learning algorithms and results in a clean, fully numerical feature set suitable for
modeling.
After preprocessing, the dataset was divided into training and testing subsets using a 70:30 train–
test split. Stratified sampling was applied during this split to maintain the original class
distribution of PCOS and non-PCOS cases in both subsets. This approach ensures that the
evaluation of the model is unbiased and that performance metrics accurately reflect real-world
class proportions.
Next, feature scaling was performed using StandardScaler, which standardizes each feature to
have zero mean and unit variance. Feature scaling is particularly important for Logistic
Regression because the algorithm is sensitive to the scale of input variables and relies on
gradient-based optimization. Standardization improves numerical stability, speeds up
convergence during training, and prevents features with larger magnitudes from dominating the
learning process.
The Logistic Regression model was then trained on the scaled training data. The model was
configured with an increased maximum number of iterations to ensure convergence, the lbfgs
solver for efficient optimization, and balanced class weights to address class imbalance in the
dataset. Through this training process, the model learns a linear decision boundary that estimates
the probability of a patient having PCOS based on the provided clinical and demographic
features.
MODEL EVALUATION
Model performance was evaluated on the test dataset using accuracy, ROC–AUC, and precision,
recall, and F1-score to provide a comprehensive assessment of classification quality, which is
essential in medical applications. Learning curves were generated using cross-validation to
compare training and validation accuracy and error as the training size increased, enabling
detection of underfitting or overfitting and assessment of generalization capability. A normalized
confusion matrix was used to analyze class-wise prediction performance, highlighting false
positives and false negatives and their associated clinical risks. The ROC curve was plotted to
illustrate the trade-off between true positive and false positive rates across thresholds, with the
AUC summarizing the model’s discriminative ability. Finally, feature importance was
determined from the absolute values of the Logistic Regression coefficients, with the top features
visualized to enhance model interpretability and support clinical insight.
NEURAL NETWORK
The dataset was first prepared by separating the target variable, PCOS (Y/N), from the input
features. Non-predictive identifier columns were removed, and categorical variables were
converted into numerical form using one-hot encoding. The data was then split into training and
testing sets using a 70:30 ratio, after which all features were standardized using StandardScaler
to improve neural network training stability and convergence.
A feedforward neural network was developed using TensorFlow and Keras. To optimize model
performance, Keras Tuner (Random Search) was employed to automatically select the best
hyperparameters, including the number of neurons, activation functions, optimizer type, and
network depth. The model architecture consisted of one or two hidden layers followed by a
sigmoid-activated output layer suitable for binary classification. Binary cross-entropy was used
as the loss function, and accuracy was used as the evaluation metric.
After hyperparameter tuning, the best-performing model was retrained on the training data to
obtain learning history. Model performance was evaluated on the test set using a classification
report, providing precision, recall, F1-score, and accuracy. A normalized confusion matrix was
plotted to visualize class-wise prediction performance and misclassification patterns.
Training and validation accuracy and loss curves were generated to assess learning behavior
and detect overfitting or underfitting. Finally, the model’s discriminative ability was evaluated
using the ROC curve and AUC, which summarize how well the neural network distinguishes
between PCOS and non-PCOS cases across different decision thresholds.
SVM
Data Preparation
The dataset was first processed to separate features and the target variable. Specifically, the target
column “PCOS (Y/N)” was isolated, while irrelevant identifiers such as “Sl. No” and “Patient
File No.” were removed. Categorical variables were encoded using one-hot encoding, resulting
in a fully numeric feature matrix suitable for modeling.
Feature Importance Analysis
An Extra Trees Classifier was trained on the dataset to identify the most informative features.
The top 35 features were visualized using a horizontal bar plot, highlighting the variables
contributing most to the model’s predictions. From this analysis, the top 9 features were selected
for further modeling, reducing dimensionality and focusing on the most relevant predictors.
Dataset Balancing
To address class imbalance in the dataset, a combination of ADASYN oversampling and Edited
Nearest Neighbours (ENN) undersampling was applied. This approach generated a balanced
dataset, mitigating potential bias in the classifier toward the majority class. Post-balancing
visualization confirmed an approximately equal distribution of PCOS-positive and PCOS-
negative samples.
Train-Test Split
The balanced dataset was split into training and testing sets using an 80/20 ratio. This ensured
sufficient data for model training while reserving a holdout set for unbiased evaluation.
SVM Classification and Hyperparameter Tuning
A Support Vector Machine (SVM) classifier was trained on the top 9 features. Hyperparameter
tuning was performed using GridSearchCV across a range of C, gamma, and kernel parameters,
optimizing for recall to prioritize identification of PCOS-positive cases.
Model Evaluation
The tuned SVM classifier was evaluated on the test set using multiple metrics:
 Accuracy: 0.978
 Precision: 0.9615
 Recall: 1.0
 F1 Score: 0.98
The classification report confirmed the model’s performance across both classes, while the
confusion matrix highlighted correct and misclassified predictions.
ROC and Precision-Recall Analysis
The model’s discriminative power was further assessed using:
 ROC Curve: Area Under the Curve (AUC) indicated strong separation between classes.
 Precision-Recall Curve: Demonstrated high precision for positive class detection at
varying recall thresholds, which is critical for medical diagnosis scenarios.
Permutation Feature Importance
To quantify the contribution of each feature to the SVM predictions, permutation feature
importance was computed. The top 10 features were visualized, providing insight into which
variables were most critical in predicting PCOS.

You might also like