Breast Cancer Classification using Logistic Regression
This repository contains a machine learning pipeline to classify breast tumors as Malignant (M) or Benign (B) using the Breast Cancer Wisconsin (Diagnostic) Dataset. The project is implemented in a Jupyter Notebook using Python and popular data science libraries such as pandas, scikit-learn, seaborn, and matplotlib.
📌 Project Overview
Breast cancer is one of the most common cancers among women worldwide. Early detection significantly increases the chances of survival. This project applies Logistic Regression—a robust binary classification algorithm—to predict the diagnosis based on fine-needle aspirate (FNA) image features of breast masses.
🗂️ Dataset Details
The model is trained on data.csv (typically the Wisconsin Breast Cancer Dataset), which includes:
Number of instances: 569
Number of attributes: 33 (30 real-valued input features, 1 ID, 1 target class, and 1 empty column)
Target variable (diagnosis):
M = Malignant (Cancerous)
B = Benign (Non-cancerous)
Features: 10 real-valued features computed for each cell nucleus (mean, standard error, and "worst" or largest values):
Radius (mean of distances from center to points on the perimeter)
Texture (standard deviation of gray-scale values)
Perimeter
Area
Smoothness (local variation in radius lengths)
Compactness (
p
e
r
i
m
e
t
e
r
2
/
a
r
e
a
−
1.0
)
Concavity (severity of concave portions of the contour)
Concave points (number of concave portions of the contour)
Symmetry
Fractal dimension ("coastline approximation" - 1)
🛠️ Tech Stack & Dependencies
The following libraries are required to run the project:
Data Manipulation: pandas, numpy
Data Visualization: matplotlib, seaborn
Machine Learning: scikit-learn
Preprocessing: StandardScaler
Model Selection: train_test_split
Model: LogisticRegression
Metrics: accuracy_score, classification_report
🚀 Step-by-Step Implementation Flow
Exploratory Data Analysis (EDA):
Loading the dataset and examining its structure (df.head(), df.info(), df.shape).
Descriptive statistical analysis of the features (df.describe().T).
Checking for missing values (df.isnull().sum()) and handling the empty column Unnamed: 32.
Visualizing feature correlations and class distributions.
Data Preprocessing & Feature Engineering:
Removing irrelevant features such as id and Unnamed: 32.
Encoding the target variable diagnosis (M = 1, B = 0).
Splitting the dataset into features (
X
) and target (
y
).
Standardizing the features using StandardScaler to ensure the gradient descent in Logistic Regression converges optimally.
Model Training:
Splitting the data into training and testing sets using train_test_split.
Fitting a LogisticRegression model on the scaled training data.
Evaluation:
Making predictions on the test set.
Evaluation using accuracy_score and a detailed classification_report (Precision, Recall, F1-score).
💻 How to Run This Project
1. Clone the repository
cd breast-cancer-classification