Created
March 31, 2018 09:18
-
-
Save thinhdanggroup/bf62bc2de5e7fe184b8b566e5baf2d6a to your computer and use it in GitHub Desktop.
pcut algorithms
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
library(ggplot2) | |
library(utiml) | |
print("Hello, world!") | |
pcut_thresholdk <- function (prediction, ratio, probability = FALSE) { | |
UseMethod("pcut_thresholdk") | |
} | |
pcut_thresholdk.default <- function (prediction, ratio, probability = FALSE) { | |
print("line") | |
n <- nrow(prediction) | |
print(n) | |
print(ratio) | |
num.elem <- ceiling(ratio * n) | |
print(num.elem) | |
print(ncol(prediction)) | |
if (length(num.elem) == 1) { | |
print("len 1") | |
num.elem <- rep(num.elem, ncol(prediction)) | |
print(num.elem) | |
names(num.elem) <- colnames(prediction) | |
print(names(num.elem)) | |
} | |
else if (length(num.elem) != ncol(prediction)) { | |
stop(paste("The number of elements values must be a single value or the", | |
"same number of labels")) | |
} | |
else if (is.null(names(num.elem))) { | |
names(num.elem) <- colnames(prediction) | |
} | |
indexes <- utiml_rename(seq(ncol(prediction)), colnames(prediction)) | |
print(indexes) | |
result <- do.call(cbind, lapply(indexes, function (ncol) { | |
values <- c(rep(1, num.elem[ncol]), rep(0, n - num.elem[ncol])) | |
print("values") | |
print(values) | |
print(prediction[, ncol]) | |
prediction[order(prediction[, ncol], decreasing=TRUE), ncol] <- values | |
print("ncol") | |
print(ncol) | |
print("predict and order") | |
print(prediction[, ncol]) | |
print(order(prediction[, ncol])) | |
print("result") | |
print(prediction[order(prediction[, ncol], decreasing=TRUE), ncol]) | |
print(prediction[, ncol]) | |
prediction[, ncol] | |
})) | |
multilabel_prediction(result, prediction, probability) | |
} | |
pcut_thresholdk.mlresult <- function (prediction, ratio, probability = FALSE) { | |
pcut_thresholdk.default(as.probability(prediction), ratio, probability) | |
} | |
prediction <- matrix(runif(16), ncol = 4) | |
prediction | |
pcut_thresholdk(prediction, .45) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment