A lightweight, modular machine learning framework designed around the strategy pattern. Works with any tabular data by simply specifying feature columns and target columns, then plugging in feature mining and model training strategies.
This framework is built on clean separation of concerns:
- 🔧 Core Orchestrators: Lightweight classes that manage the ML pipeline
- 🧩 Strategy Pattern: Pluggable strategies for feature engineering and model training
- 📦 Modular Design: Concrete strategies in separate modules, core stays minimal
- 🔄 Easy Extension: Add new strategies without modifying core code
Perfect for: Any tabular data - financial markets, Kaggle competitions, weather prediction, podcast analytics, house prices, customer churn, etc.
┌─────────────────────────────────────────────────────────────┐
│ TABULAR ML FRAMEWORK │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────┐ ┌─────────────────────────────┐ │
│ │ FEATURE MINER │ │ MODEL TRAINER │ │
│ │ (Orchestrator) │ │ (Orchestrator) │ │
│ │ │ │ │ │
│ │ • Manages strategies│ │ • Manages strategies │ │
│ │ • Preprocessing │ │ • Training pipeline │ │
│ │ • Feature validation│ │ • Cross-validation │ │
│ └─────────────────────┘ └─────────────────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────┐ ┌─────────────────────────────┐ │
│ │ FEATURE STRATEGIES │ │ MODEL STRATEGIES │ │
│ │ │ │ │ │
│ │ • RollingStats │ │ • RandomForest │ │
│ │ • LagFeatures │ │ • XGBoost │ │
│ │ • Polynomial │ │ • NeuralNetworks │ │
│ │ • Interactions │ │ • Ensembles │ │
│ │ • Domain-specific │ │ • Custom models │ │
│ └─────────────────────┘ └─────────────────────────────┘ │
│ │
├─────────────────────────────────────────────────────────────┤
│ TABULAR ML (Main Orchestrator) │
└─────────────────────────────────────────────────────────────┘
import pandas as pd
from tabular_ml import TabularML
from strategies.feature_strategies.basic_features import RollingStatsStrategy
from strategies.model_strategies.sklearn_models import RandomForestStrategy
# 1. Load your data
df = pd.read_csv('your_data.csv')
# 2. Create pipeline with strategies
ml = (TabularML(df, target_col='your_target')
.add_feature_strategy(RollingStatsStrategy())
.set_model_strategy(RandomForestStrategy())
.engineer_features()
.train_model())
# 3. Get results
ml.get_feature_importance()
ml.summary()from feature_miner import FeatureStrategy
from model_trainer import ModelStrategy
# Create custom feature strategy
class MyFeatureStrategy(FeatureStrategy):
def create_features(self, df, base_features):
# Your feature engineering logic here
return df, new_feature_names
# Create custom model strategy
class MyModelStrategy(ModelStrategy):
def train(self, X_train, y_train, problem_type, random_state):
# Your model training logic here
return trained_model
def create_model(self, problem_type, random_state):
# Create fresh model instance
return model
# Use in pipeline
ml = (TabularML(df, target_col='target')
.add_feature_strategy(MyFeatureStrategy())
.set_model_strategy(MyModelStrategy())
.engineer_features()
.train_model())tabular_ml/
├── tabular_ml.py # Main pipeline orchestrator
├── feature_miner.py # Feature mining orchestrator + base strategy
├── model_trainer.py # Model training orchestrator + base strategy
├── requirements.txt # Minimal dependencies
├── strategies/
│ ├── feature_strategies/
│ │ ├── __init__.py
│ │ └── basic_features.py # Example feature strategies
│ └── model_strategies/
│ ├── __init__.py
│ └── sklearn_models.py # Example model strategies
└── README.md
- Manages the overall ML pipeline
- Coordinates feature mining and model training
- Provides unified interface for any tabular data
- Manages feature engineering strategies
- Handles preprocessing (missing values, encoding, scaling)
- Validates and tracks feature transformations
- Manages model training strategies
- Handles train/test splits and cross-validation
- Tracks model performance and feature importance
FeatureStrategy: Abstract base for feature engineeringModelStrategy: Abstract base for model training- Easy to extend with custom implementations
- RollingStatsStrategy: Rolling mean, std, min, max
- LagFeaturesStrategy: Time-based lag features
- PolynomialStrategy: Polynomial features (x², x³)
- InteractionStrategy: Feature interactions (A×B, A÷B)
- RandomForestStrategy: Random Forest models
- LinearStrategy: Linear/Logistic regression
- XGBoostStrategy: XGBoost models
- EnsembleStrategy: Model ensembles
- 🔧 Modular: Core stays simple, strategies are pluggable
- 📈 Scalable: Easy to add new algorithms without touching core
- 🎯 Focused: Each class has single responsibility
- 🔄 Reusable: Strategies work across different datasets
- 🧪 Testable: Easy to unit test individual components
- 📖 Readable: Clear separation makes code self-documenting
# Financial data
df = pd.read_csv('stock_prices.csv')
ml = TabularML(df, target_col='next_day_return')
# Kaggle competition
df = pd.read_csv('house_prices.csv')
ml = TabularML(df, target_col='SalePrice')
# Customer analytics
df = pd.read_csv('customer_data.csv')
ml = TabularML(df, target_col='churn_probability')results = (TabularML(df, target_col='target')
.add_feature_strategy(RollingStatsStrategy())
.add_feature_strategy(PolynomialStrategy())
.set_model_strategy(RandomForestStrategy())
.engineer_features()
.train_model()
.get_feature_importance())# 1. Create strategy file: strategies/feature_strategies/my_features.py
from feature_miner import FeatureStrategy
class MyAwesomeStrategy(FeatureStrategy):
def create_features(self, df, base_features):
# Your logic here
return modified_df, new_feature_names
# 2. Use it
from strategies.feature_strategies.my_features import MyAwesomeStrategy
ml.add_feature_strategy(MyAwesomeStrategy())# 1. Create strategy file: strategies/model_strategies/my_models.py
from model_trainer import ModelStrategy
class MyAwesomeModel(ModelStrategy):
def train(self, X_train, y_train, problem_type, random_state):
# Your training logic
return trained_model
def create_model(self, problem_type, random_state):
# Your model creation logic
return fresh_model
# 2. Use it
from strategies.model_strategies.my_models import MyAwesomeModel
ml.set_model_strategy(MyAwesomeModel())pip install -r requirements.txtpython tabular_ml.py- Strategy Pattern: Easy to plug in new algorithms
- Single Responsibility: Each class does one thing well
- Open/Closed: Open for extension, closed for modification
- Composition over Inheritance: Strategies are composed, not inherited
- Minimal Core: Keep orchestrators lightweight and focused
The framework is designed to grow incrementally:
- Start Simple: Use basic strategies
- Add Complexity: Implement domain-specific strategies
- Scale Up: Add ensemble methods, AutoML strategies
- Optimize: Add performance monitoring, model versioning
The goal: Make it easy to experiment with different approaches while keeping the core framework clean and maintainable!
🧠 core/ (Framework Logic) ├── feature_miner.py # Feature orchestration ├── model_trainer.py # Model orchestration ├── feature_factory.py # Feature engine creation └── model_factory.py # Model engine creation
🔧 features/ (Feature Domain) ├── base.py # FeatureEngine base └── basic_stats.py # Implementation
🔧 models/ (Model Domain) ├── base.py # ModelEngine base └── sklearn_models.py # Implementation