A hands-on implementation of feature encoding and scaling techniques for machine learning preprocessing, using the Breast Cancer dataset and scikit-learn.
🔗 Repository: github.com/FathimaNufla2000/data-transforms-encoding-scaling
This project demonstrates how to properly transform raw categorical and numerical features into a machine-learning-ready format. It covers encoding techniques for nominal, ordinal, and boolean features, along with feature scaling methods — all while correctly preventing data leakage by fitting transformers only on the training set.
- 🚫 Data Leakage Prevention:
fit_transform()applied only on the training set,transform()only on the test set - 🔢 One-Hot Encoding: Converts nominal categorical features into binary columns
- 🎯 Ordinal Encoding: Encodes ordered categorical features (age groups, tumor size, malignancy degree) respecting their natural order
- 🏷️ Label Encoding: Encodes the target variable (
class) into numeric labels - ✅ Boolean Feature Handling: Converts boolean columns into numeric (0/1) format
- 🧩 Column Transformer Pipeline: Combines encoding for nominal and ordinal features with
remainder='passthrough'for numeric/boolean columns - 📏 Feature Scaling:
- Standardization using
StandardScaler() - Normalization using
MinMaxScaler()
- Standardization using
- ⚙️ Unified Preprocessing Pipeline: Combines encoding and scaling together for mixed-type datasets
- Language: Python 3
- Libraries: scikit-learn, Pandas, NumPy
- Environment: Jupyter Notebook
data-transforms-encoding-scaling/
├── Data_Transforms_code.ipynb # Main notebook
├── breast-cancer-1.csv # Breast cancer dataset
└── README.md
The dataset (breast-cancer-1.csv) contains breast cancer patient records with the following features:
- Ordinal features:
age,tumor-size,deg-malig - Nominal features:
menopause,breast,breast-quad - Boolean features:
node-caps,irradiat - Target variable:
class(recurrence-events / false-recurrence-events)
- Python 3.x
- Jupyter Notebook
- scikit-learn, Pandas, NumPy
git clone https://github.com/FathimaNufla2000/data-transforms-encoding-scaling.git
cd data-transforms-encoding-scaling
pip install pandas numpy scikit-learn jupyter
jupyter notebook Data_Transforms_code.ipynbMake sure breast-cancer-1.csv is in the same folder as the notebook before running.
- Open the project folder in VS Code
- Install the Jupyter extension
- Open the notebook file
- Select a Python kernel and run cells sequentially
- OneHotEncoder: Best for nominal (unordered) categorical features;
sparse_output=Falsereturns a dense array instead of a sparse matrix - OrdinalEncoder: Requires an explicit category order (e.g.
age_order,tumor_size_order) so numeric values reflect the true ranking - LabelEncoder: Used specifically for encoding the target variable, not input features
- ColumnTransformer: Applies different transformations to different columns in a single step, keeping numeric/boolean columns untouched via
remainder='passthrough' - StandardScaler vs MinMaxScaler: StandardScaler centers data around mean 0 with unit variance; MinMaxScaler rescales values into a fixed [0,1] range
FileNotFoundError: breast-cancer-1.csv → Ensure the CSV is in the same directory as the notebook.
ModuleNotFoundError: No module named 'sklearn' → Run pip install scikit-learn.
ValueError from OrdinalEncoder → Ensure all values in the dataset match exactly one of the categories defined in the order list (check for typos/case mismatches).
- Wrap the full preprocessing pipeline using
Pipelinefrom scikit-learn - Add a classification model (Logistic Regression / Decision Tree) after preprocessing
- Cross-validation and model evaluation
- Feature importance analysis after encoding
Fathima Nufla GitHub · LinkedIn
This project was developed for educational and academic purposes.