Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added getEps * added getEps to clusterTask * integrated getEps fun
- Loading branch information
Showing
5 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' @title Computes a suitable eps value for DBScan | ||
#' | ||
#' @description | ||
#' The criterion used is an elbow criterion for knn distancies. | ||
#' Since this is a subjective criterion the calculation is just heuristic | ||
#' | ||
#' @param data [\code{data.frame}]\cr | ||
#' A Dataframe with different numeric variables. | ||
#' @return [\code{numeric(1)}] | ||
#' An eps value for dbscan | ||
#' @import checkmate | ||
#' @importFrom pracma gradient | ||
#' @importFrom dbscan kNNdist | ||
getEps = function(data) { | ||
dists = kNNdist(data, k = 5) | ||
y = sort(dists) | ||
x = seq(1, length(y)) | ||
f = gradient(y, x) | ||
# make "later" values bigger by weighting with the decreasing knnDists | ||
# add mean againt dividing by 0 | ||
wf = f / (sort(dists, decreasing = TRUE) + mean(dists)) | ||
# remove small values | ||
big.wf = wf[wf > mean(wf)] | ||
big.x3 = x[wf > mean(wf)] | ||
trim.wf = big.wf[big.wf <= quantile(big.wf, 0.85)] | ||
trim.x = big.x3[big.wf <= quantile(big.wf, 0.85)] | ||
eps.ind = trim.x[trim.wf == max(trim.wf)] | ||
# in case multiple max are found | ||
mean(y[eps.ind]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters