Getting started with streamMOA

knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(streamMOA)
library(stream)
set.seed(1234)

The streamMOA package connects stream to clustering algorithms from MOA (Massive Online Analysis). This vignette shows how to create a data stream, process it with a MOA clusterer, and inspect the resulting micro- and macro-clusters. Java 8 or later is required.

Installation

Install the package from CRAN and load it together with stream:

install.packages(c("stream", "streamMOA"))
library(streamMOA)
library(stream)

Create a data stream

DSD_Gaussians() from stream generates a stream with three clusters and a small amount of noise. Request a finite number of observations with get_points():

stream <- DSD_Gaussians(k = 3, d = 2, noise = 0.05)
get_points(stream, n = 5)

Stream observations are generated as requested, so plotting or retrieving points advances the stream. Set info = FALSE when only feature values are needed and cluster labels are not required.

plot(stream, n = 500)

Cluster the stream

DSC_CluStream() creates a MOA-based online clusterer. The m parameter sets the maximum number of micro-clusters, while horizon controls the time window. The optional k argument enables weighted k-means reclustering to produce macro-clusters. Use update() to train the clusterer on incoming observations:

clustering <- DSC_CluStream(m = 50, horizon = 100, k = 3)
update(clustering, stream, n = 500)
clustering

Inspect the result

The micro-clusters summarize recent observations. Macro-clusters group those summaries into a smaller number of clusters. Retrieve their centers or plot them with the stream:

get_microclusters(clustering)
get_macroclusters(clustering)
plot(clustering, stream, type = "both")

Other clusterers include DSC_DenStream(), DSC_ClusTree(), DSC_DStream_MOA(), DSC_BICO_MOA(), and DSC_StreamKM(). See their help pages and the package vignette Introduction to streamMOA for algorithm details, options, and additional examples.



Try the streamMOA package in your browser

Any scripts or data that you put into this service are public.

streamMOA documentation built on Oct. 14, 2026, 1:06 a.m.