predict.stdbscan: Predict newdata

View source: R/predict.R

predict.stdbscanR Documentation

Predict newdata

Description

Assigns each new observation to an existing cluster from a fitted stdbscan object, or marks it as noise if it falls outside any cluster.

Usage

## S3 method for class 'stdbscan'
predict(object, data, newdata, ...)

Arguments

object

An object of class stdbscan.

data

matrix. The data set used to create the clustering object.

newdata

matrix. New data points for which the cluster membership should be predicted. The data must be in the same format as the input data.

...

Additional arguments are passed on to dbscan::frNN().

Value

An integer vector of cluster labels, matching the labels of the input stdbscan object.

Examples

data(geolife_traj)

geolife_traj$date_time <- as.POSIXct(
  paste(geolife_traj$date, geolife_traj$time),
  format = "%Y-%m-%d %H:%M:%S",
  tz = "GMT"
)
geolife_traj$t <- as.numeric(
  geolife_traj$date_time - min(geolife_traj$date_time)
)
data <- cbind(geolife_traj$x, geolife_traj$y, geolife_traj$t)

res <- st_dbscan(
  data = data,
  eps_spatial = 3,
  eps_temporal = 30,
  min_pts = 5
)

newdata <- cbind(
  c(440160,  440165,  440144,  440130,  440160),
  c(4428129, 4428135, 4428120, 4428123, 4428122),
  c(4617,    4620,    4629,    4635,    4640)
)
predict(res, data, newdata)


stdbscan documentation built on March 14, 2026, 5:06 p.m.