-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
162 lines (162 loc) · 4.25 KB
/
.Rhistory
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
devtools::install_github("Hobbeist/kappaRule")
library(mlbench)
library(rsample)
library(tidyverse)
library(ruleFit)
data("PimaIndiansDiabetes")
data <- PimaIndiansDiabetes
y <- "diabetes"
data$diabetes <- as.factor(ifelse(data$diabetes %in% "neg", 0, 1))
# Train and Test set
set.seed(456)
split <- initial_split(data)
train <- training(split)
test <- testing(split)
# Model
rf_results <-
kappaRule(data = train,
y = "diabetes",
ntree = 20,
max.depth = 3,
rule.filter = 10,
rule.extract.cores = 64,
kappa.cores = 64
)
rf_results
kappaRule_metrics
#' @importFrom broom tidy
#' @importFrom caret confusionMatrix
#'
#' @export
kappaRule_metrics <- function(test_data,
model,
measure = NULL){
results_test <- broom::tidy(caret::confusionMatrix(table(test_data[,model$y],
predict.ruleFit(test_data, model))))%>%
dplyr::select(term, estimate) %>%
dplyr::rename(Test_Metrics = estimate) %>%
dplyr::rename(Measure = term) %>%
dplyr::filter(!Measure %in% "mcnemar")
results_train <- broom::tidy(caret::confusionMatrix(table(model$RuleData[,model$y],
predict(model$RuleFit,
Matrix::as.matrix(model$RuleData %>%
dplyr::select(!!-model$y)),
type = "class"))))%>%
dplyr::select(term, estimate) %>%
dplyr::rename(Train_Metrics = estimate) %>%
dplyr::rename(Measure = term) %>%
dplyr::filter(!Measure %in% "mcnemar")
return(as_tibble(cbind(results_train, results_test[,"Test_Metrics"])))
}
kappaRule_metrics(test, rf_results)
roxygen2::roxygenise()
predict(test, rf_results)
predict(rf_results, train)
predict(rf_results, test)
predict(rf_results, test_data=test)
predict.ruleFit(rf_results, test_data=test)
predict.ruleFit(test_data=test, rf_results)
roxygen2::roxygenise()
library(ruleFit)
devtools::install_github("Hobbeist/kappaRule")
roxygen2::roxygenise()
devtools::install_github("Hobbeist/kappaRule")
library(mlbench)
library(rsample)
library(tidyverse)
library(ruleFit)
data("PimaIndiansDiabetes")
data <- PimaIndiansDiabetes
y <- "diabetes"
data$diabetes <- as.factor(ifelse(data$diabetes %in% "neg", 0, 1))
# Train and Test set
set.seed(456)
split <- initial_split(data)
train <- training(split)
test <- testing(split)
# Model
rf_results <-
kappaRule(data = train,
y = "diabetes",
ntree = 20,
max.depth = 3,
rule.filter = 10,
rule.extract.cores = 64,
kappa.cores = 64
)
kappaRule::kappaRule_metrics(test, rf_results)
kappaRule::kappaRule_metrics(test, rf_results)
rf_results
roxygen2::roxygenise()
devtools::install_github("Hobbeist/kappaRule")
rm(list=ls())
library(mlbench)
library(rsample)
library(tidyverse)
library(ruleFit)
data("PimaIndiansDiabetes")
data <- PimaIndiansDiabetes
y <- "diabetes"
data$diabetes <- as.factor(ifelse(data$diabetes %in% "neg", 0, 1))
# Train and Test set
set.seed(456)
split <- initial_split(data)
train <- training(split)
test <- testing(split)
# Model
rf_results <-
kappaRule(data = train,
y = "diabetes",
ntree = 20,
max.depth = 3,
rule.filter = 10,
rule.extract.cores = 64,
kappa.cores = 64
)
kappaRule::kappaRule_metrics(test, rf_results)
kappaRule::kappaRule_metrics(test_data = test, model = rf_results)
test
rf_results
test_data <- test
model <- rf_results
results_test <- broom::tidy(caret::confusionMatrix(table(test_data[,model$y],
predict.kappaRule(model = model, test_data = test_data))))%>%
dplyr::select(term, estimate) %>%
dplyr::rename(Test_Metrics = estimate) %>%
dplyr::rename(Measure = term) %>%
dplyr::filter(!Measure %in% "mcnemar")
predict(rf_results, test)
library(kappaRule)
remove.packages("kappaRule", lib="~/R/x86_64-pc-linux-gnu-library/4.1")
roxygen2::roxygenise()
roxygen2::roxygenise()
devtools::install_github("Hobbeist/kappaRule")
remove.packages("ruleFit", lib="~/R/x86_64-pc-linux-gnu-library/4.1")
library(mlbench)
library(rsample)
library(tidyverse)
library(kappaRule)
data("PimaIndiansDiabetes")
data <- PimaIndiansDiabetes
y <- "diabetes"
data$diabetes <- as.factor(ifelse(data$diabetes %in% "neg", 0, 1))
# Train and Test set
set.seed(456)
split <- initial_split(data)
train <- training(split)
test <- testing(split)
# Model
rf_results <-
kappaRule(data = train,
y = "diabetes",
ntree = 20,
max.depth = 3,
rule.filter = 10,
rule.extract.cores = 64,
kappa.cores = 64
)
kappaRule::kappaRule_metrics(test_data = test, model = rf_results)
roxygen2::roxygenise()
library(kappaRule)
remove.packages("kappaRule", lib="~/R/x86_64-pc-linux-gnu-library/4.1")
roxygen2::roxygenise()