A machine learning pipeline for binary classification of gene functions, specifically predicting whether genes have cell communication capabilities. This project implements a comprehensive data preprocessing pipeline, automated model selection, and ensemble learning techniques to handle imbalanced biological datasets.
- Automated Preprocessing Optimization: Tests multiple combinations of imputation, scaling, and outlier handling methods
- Ensemble Learning: Combines K-Nearest Neighbors and Random Forest classifiers using soft voting
- Cross-Validation: 5-fold stratified cross-validation for robust model evaluation
- Hyperparameter Tuning: Grid search optimization for model parameters
- Imbalanced Data Handling: F1-score optimization for datasets with class imbalance
- Quick Start
- Installation
- Usage
- Project Structure
- Methodology
- Model Performance
- Configuration
- Contributing
# Clone and setup
git clone git@github.com:dheerajram13/gene-classifier-ml.git
cd gene-classifier-ml
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Add your data files in the Data dir (DM_project_24.csv and test_data.csv)
# Run the pipeline
python main.py
# View results in predictions.txt- Python 3.9 or higher
- pip or conda package manager
-
Clone the repository
git clone <repository-url> cd Data\ Mining
-
Create a virtual environment
Using conda:
conda create -n gene-classifier python=3.9 conda activate gene-classifier
Using venv:
python3 -m venv venv # On macOS/Linux: source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Prepare data files
Ensure the following CSV files are in the project directory:
DM_project_24.csv- Training dataset (1,600 samples, 106 features)test_data.csv- Test dataset (817 samples, 105 features)
Run the classification pipeline:
python main.pyThis will:
- Load and preprocess the training data
- Train the ensemble model
- Perform cross-validation
- Generate predictions on test data
- Save results to
predictions.txt
The predictions.txt file contains:
- One prediction per line (0 or 1) for each test sample
- Final line with model accuracy and F1-score
Example:
0,
1,
0,
...
0.892,0.745,
To enable full preprocessing optimization and model selection (slower but more thorough):
- Uncomment lines 312-314 in
main.py - This will test all preprocessing combinations and models
.
├── main.py # Main pipeline and execution
├── constants.py # Model and preprocessing configurations
├── requirements.txt # Python dependencies
├── Readme.md # Project documentation
├── DM_project_24.csv # Training data (not in repo)
├── test_data.csv # Test data (not in repo)
└── predictions.txt # Output predictions (generated)
The pipeline implements multiple preprocessing strategies:
- Mean Imputation (selected): Replaces missing values with column mean
- Median Imputation: Uses median for robust handling of outliers
- Iterative Imputation: MICE-based multivariate imputation
- StandardScaler (selected): Zero mean, unit variance normalization
- MinMaxScaler: Scales features to [0, 1] range
- RobustScaler: Uses median and IQR for outlier resistance
- None (selected): No outlier removal for final model
- Z-score method: Removes values >3 standard deviations
- IQR method: Removes values outside 1.5×IQR range
A VotingClassifier with soft voting combining:
1. K-Nearest Neighbors (KNN)
n_neighbors: 8metric: Euclidean distanceweights: Distance-weighted voting
2. Random Forest
n_estimators: 100 treesmax_depth: 10min_samples_split: 5min_samples_leaf: 2random_state: 42 (reproducibility)
Soft voting (probability averaging) for improved calibration and performance.
- Preprocessing Optimization: 5-fold CV tests all preprocessing combinations
- Hyperparameter Tuning: GridSearchCV for each model type
- Model Evaluation: F1-score and accuracy on validation folds
- Ensemble Construction: Combines best-performing models
- Primary Metric: F1-Score (harmonic mean of precision and recall)
- Secondary Metric: Accuracy
- Validation: 5-fold stratified cross-validation
F1-score is prioritized due to class imbalance (88% negative, 12% positive).
Expected performance (5-fold cross-validation):
- Accuracy: ~89-91%
- F1-Score: ~74-76%
Note: Performance may vary slightly due to cross-validation randomness.
Edit constants.py to customize:
Model configurations (model_config):
model_config = {
"knn": {
"model": KNeighborsClassifier(),
"params": {"n_neighbors": range(1, 18), ...}
},
...
}Preprocessing methods (pre_processing_config):
pre_processing_config = {
"imputation_methods": {...},
"scaling_methods": {...},
"outlier_methods": {...}
}Final configuration (final_preprocessing_config):
final_preprocessing_config = {
"imputation": ("mean", SimpleImputer()),
"scaling": ("standard", StandardScaler()),
"outlier": ("none", None),
}Core libraries:
pandas >= 2.2.3- Data manipulationnumpy >= 2.1.2- Numerical computingscikit-learn >= 1.5.2- Machine learning algorithms
See requirements.txt for complete list.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Make your changes with clear commit messages
- Add tests if applicable
- Update documentation as needed
- Submit a pull request
This project follows:
- PEP 8 style guidelines
- Type hints for function signatures
- Comprehensive docstrings (Google style)
- Dataset: Gene function classification dataset
- Built with scikit-learn machine learning library
- Developed as part of a Data Mining course project
For questions or issues, please open an issue on the GitHub repository.
Note: This is an academic project demonstrating machine learning best practices for biological data classification.