5 min read

Quick Start Guide

This guide will help you get started with OpenMOA in just a few minutes. You'll learn how to install the library, create your first data stream, and train an online classifier.

Installation

Install OpenMOA using pip:

pip install openmoa

For the latest development version, install directly from GitHub:

pip install git+https://github.com/ZW-SIYUAN/OpenMOA.git

Your First Stream

Let's create a simple data stream using the SEA generator, a classic benchmark for concept drift:

from openmoa.streams import SEAGenerator

# Create a stream with 10% noise
stream = SEAGenerator(noise_percentage=0.1)

# Generate samples one at a time
for i in range(5):
    X, y = stream.next_sample()
    print(f"Sample {i}: features={X}, label={y}")

Training a Classifier

Now let's train a Hoeffding Tree classifier on the stream:

from openmoa.streams import SEAGenerator
from openmoa.classifiers import HoeffdingTree

# Initialize stream and classifier
stream = SEAGenerator(noise_percentage=0.1)
classifier = HoeffdingTree()

# Train on 1000 samples
correct = 0
for i in range(1000):
    X, y = stream.next_sample()
    
    # Predict before training (prequential evaluation)
    prediction = classifier.predict(X)
    if prediction == y:
        correct += 1
    
    # Train on the sample
    classifier.partial_fit(X, y)

print(f"Accuracy: {correct / 1000 * 100:.2f}%")

Using the Evaluation Framework

OpenMOA provides a built-in evaluation framework for cleaner code:

from openmoa.streams import SEAGenerator
from openmoa.classifiers import HoeffdingTree
from openmoa.evaluation import prequential_evaluation

# Run prequential evaluation
results = prequential_evaluation(
    stream=SEAGenerator(noise_percentage=0.1),
    learner=HoeffdingTree(),
    max_instances=10000,
    sample_frequency=1000
)

# Print results
print(f"Final Accuracy: {results.accuracy():.4f}")
print(f"Total Time: {results.total_time:.2f}s")

Next Steps

Now that you have the basics, explore these topics:

Next: Installation