Skip to main content

CrunchDAO Crunch Example

This package provides example utilities and base classes for CrunchDAO machine learning competitions.

Installation

pip install crunchdao-crunch-example

Usage

Iris Classification

The package provides iris classification utilities with a dual structure:

# Import base class from namespace package
from crunchdao.crunch_example.iris import IrisModelBase
import pandas as pd

class MyIrisModel(IrisModelBase):
    def train(self, train_data: pd.DataFrame) -> None:
        # Implement your training logic here
        # train_data contains features and target labels
        pass
    
    def infer(self, dataframe: pd.DataFrame) -> pd.DataFrame:
        # Implement your inference logic here
        # dataframe contains features to predict on
        predictions = [0, 1, 2]  # Your model predictions
        
        return pd.DataFrame({
            'prediction': predictions
        })

# Use your model
model = MyIrisModel()

# Training data with features and target
train_data = pd.DataFrame({
    'sepal_length': [5.1, 4.9, 4.7],
    'sepal_width': [3.5, 3.0, 3.2],
    'petal_length': [1.4, 1.4, 1.3],
    'petal_width': [0.2, 0.2, 0.2],
    'species': [0, 0, 0]  # 0=setosa, 1=versicolor, 2=virginica
})

model.train(train_data)

# Test data with just features
test_data = pd.DataFrame({
    'sepal_length': [6.1, 5.9],
    'sepal_width': [2.9, 3.0],
    'petal_length': [4.7, 4.2],
    'petal_width': [1.4, 1.5]
})

predictions = model.infer(test_data)
print(predictions)

Package Structure

The package provides a dual structure:

Namespace Package (for base classes)

  • crunchdao.crunch_example.iris - Namespace package containing IrisModelBase
    • Accessible via: from crunchdao.crunch_example.iris import IrisModelBase

Direct Package (for examples and utilities)

  • crunchdao_crunch_example/ - Main package with examples and utilities
    • models/ - Example model implementations (not importable packages)
      • neural_network/ - Multi-layer perceptron with sklearn
      • random_forest/ - Ensemble tree-based classifier
      • svm/ - Support vector machine classifier
    • scripts/ - Utility scripts for training and model management (not importable packages)

Model Examples

The package includes complete model implementations:

  • Neural Network (models/neural_network/) - Multi-layer perceptron with sklearn
  • Random Forest (models/random_forest/) - Ensemble tree-based classifier
  • SVM (models/svm/) - Support vector machine classifier

Each model includes:

  • Pre-trained model files in resources/
  • Implementation code in submissions/main.py
  • Dependencies in submissions/requirements.txt

Utility Scripts

The scripts/ directory contains:

  • pretrain_models.py - Train all models on iris dataset
  • pretrain_neural_network.py - Specific neural network training
  • sync_models.py - Sync models with storage systems
  • cleanup_docker.py - Docker environment cleanup

Development

Requirements

  • Python 3.11+
  • uv (for dependency management)

Setup

# Clone the repository
git clone https://github.com/crunchdao/coordinator-setup
cd coordinator-setup/examples/crunch_examples

# Install dependencies
uv sync

# Install in development mode
uv pip install -e .

Testing

uv run pytest

Building

# Build the package
uv build

# Upload to PyPI (requires authentication)
uv publish

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for crunchdao-crunch-example 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crunchdao-crunch-example 0.3.2
File Size Uploaded
crunchdao_crunch_example-0.3.2.tar.gz 167.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crunchdao-crunch-example 0.3.2
File Interpreter ABI Platform
crunchdao_crunch_example-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 345.0 kB

Release files / crunchdao_crunch_example-0.3.2.tar.gz

Download URL crunchdao_crunch_example-0.3.2.tar.gz
Size 167.7 kB
Tags Source
SHA-256 checksum
How to use checksums
71ffe086427d482614a9ccfa27b93c5e79b524441b0c5dbbada907acb8f4c673
BLAKE2b-256 checksum
How to use checksums
b508666f87531b64ac0a4ae6bce574493f65b460447fe22ce6abc9e81316c640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / crunchdao_crunch_example-0.3.2-py3-none-any.whl

Download URL crunchdao_crunch_example-0.3.2-py3-none-any.whl
Size 177.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ef45f0841cfdf8cb34e879d3880b9736e9b97f9486baca90f53877b53d5e9de
BLAKE2b-256 checksum
How to use checksums
63745f43b4aef418ab40e1bdcaf19c793923f1889b7bfe534f345fbbf0f5ed3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page