stream <- DSD_Gaussians(k = 3, d = 3)
get_points(stream, n = 5)
## Example 1: rename the columns
rename <- function(x, names) {
colnames(x) <- names
x
}
# By default, the info columns starting with . are not affected.
stream2 <- stream %>% DSF_Func(rename, names = c("A", "B", "C"))
stream2
get_points(stream2, n = 5)
## Example 2: add a sum columns
stream3 <- stream2 %>% DSF_Func(function(x) {
x$sum = rowSums(x)
x
})
stream3
get_points(stream3, n = 5)
## Example 3: Project the stream on its first 2 PCs (using a sample)
pr <- princomp(get_points(stream, n = 100, info = FALSE))
pca_trans <- function(x) predict(pr, x[, c("X1", "X2", "X3")])[, 1:2 , drop = FALSE]
pca_trans(get_points(stream, n = 3, info = FALSE))
stream4 <- stream %>% DSF_Func(pca_trans)
stream4
get_points(stream4, n = 3)
plot(stream4)
## Example 4: Change a class labels using info = TRUE. We redefine class 3 as noise (NA)
stream5 <- stream %>% DSF_Func(
function(x) { x[['.class']][x[['.class']] == 3] <- NA; x },
info = TRUE)
stream5
get_points(stream5, n = 5)
plot(stream5)
Run the code above in your browser using DataLab