Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

🔄 Data Transforms - Encoding & Scaling

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


📌 Project Overview

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.


✨ Features

  • 🚫 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()
  • ⚙️ Unified Preprocessing Pipeline: Combines encoding and scaling together for mixed-type datasets

🛠 Technology Stack

  • Language: Python 3
  • Libraries: scikit-learn, Pandas, NumPy
  • Environment: Jupyter Notebook

📂 Project Structure

data-transforms-encoding-scaling/
├── Data_Transforms_code.ipynb   # Main notebook
├── breast-cancer-1.csv                         # Breast cancer dataset
└── README.md

📊 Dataset

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)

⚙️ Prerequisites

  • Python 3.x
  • Jupyter Notebook
  • scikit-learn, Pandas, NumPy

🚀 Installation & Running Instructions

Method 1: Clone and Run Locally

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.ipynb

Make sure breast-cancer-1.csv is in the same folder as the notebook before running.

Method 2: Using an IDE (VS Code)

  1. Open the project folder in VS Code
  2. Install the Jupyter extension
  3. Open the notebook file
  4. Select a Python kernel and run cells sequentially

🔑 Key Concepts Explained

  • OneHotEncoder: Best for nominal (unordered) categorical features; sparse_output=False returns 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

🩺 Troubleshooting

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).


🚧 Future Enhancements

  • Wrap the full preprocessing pipeline using Pipeline from scikit-learn
  • Add a classification model (Logistic Regression / Decision Tree) after preprocessing
  • Cross-validation and model evaluation
  • Feature importance analysis after encoding

👩‍💻 Author

Fathima Nufla GitHub · LinkedIn


📄 License

This project was developed for educational and academic purposes.

About

Feature encoding (OneHot, Ordinal, Label) and scaling (Standardization, Normalization) techniques on the Breast Cancer dataset using scikit-learn with proper train/test data leakage prevention.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages