A Machine Learning project containing two implementations of breast cancer classification using the same dataset: a Logistic Regression model in Python and a Jupyter Notebook comparing six different classification algorithms.
This repository contains two related implementations for classifying breast cancer cases as malignant or benign.
Both implementations use the same Breast Cancer Wisconsin Diagnostic dataset, but the dataset is loaded in two different ways.
The first implementation is a Python script that uses a downloaded cancer.csv file. It performs data preprocessing, feature normalization, and uses Logistic Regression for classification.
The second implementation is a Jupyter Notebook that loads the same dataset directly from Scikit-learn using load_breast_cancer(). It then compares six different Machine Learning classification algorithms.
The purpose of having both implementations in the same repository is to demonstrate different ways of working with the same dataset and comparing different Machine Learning approaches.
The first implementation is written in Python:
cancer_classification.py
This project uses the downloaded dataset:
cancer.csv
The main steps include:
- Loading the dataset from a CSV file
- Removing unnecessary columns
- Converting diagnosis labels into numerical values
- Separating features and target
- Normalizing the input features
- Splitting the dataset into training and testing sets
- Training a Logistic Regression model
- Predicting the diagnosis of test samples
- Calculating classification accuracy
The second implementation is provided as a Jupyter Notebook:
breast_cancer_classification.ipynb
Instead of reading a local CSV file, the notebook loads the dataset directly from Scikit-learn:
from sklearn import datasets
cancer = datasets.load_breast_cancer()The notebook then trains and compares six different classification algorithms:
- Support Vector Machine (SVM)
- Gaussian Naive Bayes
- Decision Tree
- Random Forest
- XGBoost
- K-Nearest Neighbors (KNN)
Each model is evaluated using the same training and testing data.
- Breast cancer classification
- Malignant and benign classification
- Data preprocessing
- Feature normalization
- Train/test data splitting
- Logistic Regression
- Support Vector Machine
- Gaussian Naive Bayes
- Decision Tree
- Random Forest
- XGBoost
- K-Nearest Neighbors
- Accuracy evaluation
- Machine Learning model comparison
- Python
- Pandas
- Scikit-learn
- XGBoost
- Jupyter Notebook
Both projects use the same Breast Cancer Wisconsin Diagnostic dataset.
The dataset contains numerical features describing characteristics of breast cancer cell nuclei and is used to classify cases into two categories:
Malignant
Benign
The Python implementation uses a downloaded copy of the dataset:
cancer.csv
The diagnosis column is converted into numerical labels:
M → 1
B → 0
The columns id and Unnamed: 32 are removed before training.
The notebook loads the dataset directly from Scikit-learn:
cancer = datasets.load_breast_cancer()This avoids manually storing the dataset as a CSV file and provides the dataset directly through the Scikit-learn library.
Therefore, both implementations work with the same dataset, but the source of the data in the code is different.
The first implementation performs the following preprocessing steps:
Load cancer.csv
↓
Remove unnecessary columns
↓
Convert diagnosis labels
↓
Separate features and target
↓
Normalize features
↓
Train/Test Split
The features are normalized using Min-Max normalization:
x_data = (x_data - x_data.min()) / (x_data.max() - x_data.min())The notebook loads the dataset directly from Scikit-learn and separates the features and target:
cancer.data
cancer.targetThe dataset is then divided into training and testing sets using a 70/30 split.
Load Dataset
↓
Data Preprocessing
↓
Feature Normalization
↓
Train/Test Split
↓
Logistic Regression
↓
Prediction
↓
Accuracy Evaluation
Downloaded Dataset
↓
Data Preprocessing
↓
Scikit-learn Dataset
↓
Train/Test Split
↓
Train Multiple Classifiers
↓
Make Predictions
↓
Calculate Accuracy
↓
Compare Models
The Python implementation uses Logistic Regression as its classification algorithm.
model = LogisticRegression()
model.fit(x_train, y_train)The trained model is used to predict the diagnosis of the test samples.
The notebook uses an SVM classifier with a linear kernel:
model_SVM = svm.SVC(kernel='linear')
model_SVM.fit(X_train, y_train)Gaussian Naive Bayes is used as another classification model:
model_GNB = GaussianNB()
model_GNB.fit(X_train, y_train)The notebook uses a Decision Tree classifier:
model_DT = DecisionTreeClassifier()
model_DT.fit(X_train, y_train)Random Forest is used as an ensemble classification algorithm:
model_RF = RandomForestClassifier()
model_RF.fit(X_train, y_train)XGBoost is included as another ensemble learning algorithm:
model_XGB = xg.XGBClassifier()
model_XGB.fit(X_train, y_train)K-Nearest Neighbors is used as the final classifier:
model_KN = KNeighborsClassifier()
model_KN.fit(X_train, y_train)The Python project trains a Logistic Regression model using the locally loaded dataset.
The Jupyter Notebook trains six different classification models using the dataset loaded from Scikit-learn.
Each model generates predictions for the test dataset, and the results are evaluated using accuracy.
The projects use accuracy to evaluate classification performance.
The Python script compares the predicted values with the actual test labels and calculates the percentage of correct predictions.
The notebook uses:
metrics.accuracy_score(y_test, y_pred)to calculate the accuracy of each classifier.
Python Project:
XX / XXX
XX.XX
Jupyter Notebook:
SVM Accuracy: XX.XX
Naive Bayes Accuracy: XX.XX
Decision Tree Accuracy: XX.XX
Random Forest Accuracy: XX.XX
XGBoost Accuracy: XX.XX
KNN Accuracy: XX.XX
The exact results may vary depending on the model configuration and train/test split.
The two implementations demonstrate different approaches to the same classification problem.
| Implementation | Data Loading | Models |
|---|---|---|
| Python Script | Local cancer.csv |
Logistic Regression |
| Jupyter Notebook | Scikit-learn load_breast_cancer() |
SVM, Naive Bayes, Decision Tree, Random Forest, XGBoost, KNN |
The dataset itself is the same; only the way it is loaded and processed in the two implementations is different.
Breast-Cancer-Classification/
│
├── cancer.csv
├── cancer_classification.py
├── breast_cancer_classification.ipynb
├── requirements.txt
├── LICENSE
└── README.md
Install the required libraries using:
pip install pandas scikit-learn xgboost jupyterYou can also install all dependencies using:
pip install -r requirements.txtRun the Python implementation:
python cancer_classification.pyThe program will load cancer.csv, preprocess the data, train the Logistic Regression model, make predictions, and display the final accuracy.
Start Jupyter Notebook:
jupyter notebookThen open:
breast_cancer_classification.ipynb
Run the notebook cells from top to bottom to train the six classification models and compare their accuracy.
The main dependencies are:
pandas
scikit-learn
xgboost
jupyter
- Add confusion matrices
- Add precision, recall, and F1-score
- Add cross-validation
- Apply feature scaling to the notebook models
- Tune model hyperparameters
- Add a model comparison visualization
- Add feature importance analysis
- Improve reproducibility with fixed random states
- Add predictions for new data
Contributions are welcome.
You can improve the preprocessing, add new classification algorithms, improve the evaluation process, or add new visualizations to the project.
This project is licensed under the MIT License.
Mohammad Reza Bakhshandeh
Electrical Engineering (Electronics) Graduate
Interested in Industrial Automation, Embedded Systems, PLC Programming, Python Development, Computer Vision, Machine Learning, and Artificial Intelligence.