-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.R
65 lines (55 loc) · 1.37 KB
/
Utilities.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
library(lubridate)
library(stringr)
library(xgboost)
library(randomForest)
library(ggplot2)
library(scales)
library(plyr)
library(dplyr)
library(MLmetrics)
library(Ckmeans.1d.dp)
library(caret)
CategoryToInteger <- function(feature)
{
feature.categories <- unique(feature)
feature.categories.id <- 1:length(feature.categories)
names(feature.categories.id) <- as.vector(feature.categories)
feature <- feature.categories.id[feature]
return(feature)
}
GetBooleanFeatureFromGroup <- function(feature, group)
{
indices <- grep(group, feature)
feature.is.bool <- rep(0, length(feature))
feature.is.bool[indices] <- 1
return(feature.is.bool)
}
GetIntegerFeatureFromGroups <- function(feature, groups)
{
feature.group <- rep(0, length(feature))
i <- 1
for(group in groups)
{
indices <- grep(group, feature)
feature.group[indices] <- i
i <- i + 1
}
return(feature.group)
}
#
# CreateDataframeFromThreshold <- function(prediction, threshold)
# {
# prediction.ncol <- ncol(prediction)
# x <- apply(prediction, 1, function(x) which(x >= threshold))
# for(i in 1:length(x))
# {
# if(length(x[[i]]) > 0)
# {
# row <- rep(0, prediction.ncol)
# row[x[[i]][[1]]] <- 1
# prediction[i, ] <- row
# }
# }
#
# return(prediction)
# }