GA-Optimized Decision Trees¶
82%
Max size reduction
p > 0.05
Accuracy parity
3
Benchmark datasets
20‑CV
Fold validation
🚀 Quick Start¶
```bash
git clone https://github.com/ibrah5em/ga-optimized-trees.git
cd ga-optimized-trees
python -m venv venv && source venv/bin/activate
pip install -e . # core only
pip install -e .[all] # all features
```
```python
from ga_trees import GAEngine, GAConfig, TreeInitializer, FitnessCalculator, Mutation
from ga_trees.data import DatasetLoader
from ga_trees.fitness import TreePredictor
import numpy as np
data = DatasetLoader().load_dataset("iris", test_size=0.2)
X_train, y_train = data["X_train"], data["y_train"]
config = GAConfig(population_size=80, n_generations=40)
init = TreeInitializer(X_train.shape[1], len(np.unique(y_train)), max_depth=6)
fitness = FitnessCalculator(accuracy_weight=0.68, interpretability_weight=0.32)
mutation = Mutation(X_train.shape[1], {i: (X_train[:,i].min(), X_train[:,i].max())
for i in range(X_train.shape[1])})
engine = GAEngine(config, init, fitness.calculate_fitness, mutation)
best = engine.evolve(X_train, y_train, verbose=True)
print(f"Tree: {best.get_num_nodes()} nodes, depth {best.get_depth()}")
```
📚 Documentation¶
📈 Benchmark Results¶
| Dataset | GA Accuracy | CART Accuracy | GA Nodes | CART Nodes | Size Reduction |
|---|---|---|---|---|---|
| Iris | 94.55 ± 8.07% | 92.41 ± 10.43% | 7.4 | 16.4 | 55% |
| Wine | 88.19 ± 10.39% | 87.22 ± 10.70% | 10.7 | 20.7 | 48% |
| Breast Cancer | 91.05 ± 5.60% | 91.57 ± 3.92% | 6.5 | 35.5 | 82% |
All p-values > 0.05 — accuracy difference is not statistically significant.
🆚 How It Compares¶
| Aspect | CART | Random Forest | GA-Optimized |
|---|---|---|---|
| Optimization | Greedy (local) | Ensemble | Global (evolutionary) |
| Objectives | Accuracy only | Accuracy only | Multi-objective |
| Interpretability | No control | Black box | Explicit control ✓ |
| Tree size | Often large | N/A | Controllable ✓ |
🔗 Links¶
v1.0.0 Python 3.8+ MIT License
- GitHub: ibrah5em/ga-optimized-trees
- Issues: github.com/ibrah5em/ga-optimized-trees/issues
- Discussions: github.com/ibrah5em/ga-optimized-trees/discussions