glmtree
: logistic regression trees for efficient segmentationlibrary(FactoMineR)
mixed = PCA(data[,c("x1","x2")])
data$pca1 = predict(mixed, data)$coord[,1]
data$pca2 = predict(mixed, data)$coord[,2]
test$pca1 = predict(mixed, test)$coord[,1]
test$pca2 = predict(mixed, test)$coord[,2]
data$cluster = ifelse(data$pca1 > 1, 1, ifelse(data$pca1 > 0, 2, 3))
test$cluster = ifelse(test$pca1 > 1, 1, ifelse(test$pca1 > 0, 2, 3))
pred = matrix(0, nrow = 0.2*1000, ncol = 1)
for (j in 1:3) {
modele = glm(y ~ x1 + x2, data = data[data$cluster==j,], family=binomial(link = "logit"))
pred[test$cluster==j] = predict(modele, test[test$cluster==j,], type="response")
}
normalizedGini(test$y,pred)
## [1] 0.6836398
if (require(partykit, quietly = TRUE)) {
mob_data = partykit::glmtree(formula = y ~ x1 + x2 | x1 + x2, data = data, family = binomial)
plot(mob_data)
normalizedGini(test$y, predict(mob_data,test))
}
## Warning: package 'partykit' was built under R version 3.5.2
## Warning: package 'libcoin' was built under R version 3.5.2
##
## Attaching package: 'partykit'
## The following object is masked from 'package:glmtree':
##
## glmtree
## [1] 0.7129581
glmtree
approach## The bic criterion for iteration 1 is -295.885590615788
## The bic criterion for iteration 2 is -194.772983195209
## The bic criterion for iteration 3 is -194.772983195209
## The bic criterion for iteration 4 is -194.772983195209
## The bic criterion for iteration 5 is -194.772983195209
## The bic criterion for iteration 6 is -194.772983195209
## The bic criterion for iteration 7 is -194.772983195209
## The bic criterion for iteration 8 is -194.772983195209
## The bic criterion for iteration 9 is -194.772983195209
## The bic criterion for iteration 10 is -203.928829516155
## The bic criterion for iteration 11 is -202.730397275718
## The bic criterion for iteration 12 is -202.730397275718
## The bic criterion for iteration 13 is -202.730397275718
## The bic criterion for iteration 14 is -202.730397275718
## The bic criterion for iteration 15 is -202.730397275718
## The bic criterion for iteration 16 is -202.730397275718
## The bic criterion for iteration 17 is -202.730397275718
## The bic criterion for iteration 18 is -202.730397275718
## The bic criterion for iteration 19 is -202.730397275718
## The bic criterion for iteration 20 is -202.730397275718
## The bic criterion for iteration 21 is -202.730397275718
## The bic criterion for iteration 22 is -202.730397275718
## The bic criterion for iteration 23 is -202.730397275718
## The bic criterion for iteration 24 is -202.730397275718
## The bic criterion for iteration 25 is -202.730397275718
## The bic criterion for iteration 26 is -202.730397275718
## The bic criterion for iteration 27 is -202.730397275718
## The bic criterion for iteration 28 is -202.730397275718
## The bic criterion for iteration 29 is -202.730397275718
## The bic criterion for iteration 30 is -202.730397275718
## The bic criterion for iteration 31 is -202.730397275718
## The bic criterion for iteration 32 is -202.730397275718
## The bic criterion for iteration 33 is -202.730397275718
## The bic criterion for iteration 34 is -202.730397275718
## The bic criterion for iteration 35 is -202.730397275718
## The bic criterion for iteration 36 is -202.730397275718
## The bic criterion for iteration 37 is -202.730397275718
## The bic criterion for iteration 38 is -202.730397275718
## The bic criterion for iteration 39 is -202.730397275718
## The bic criterion for iteration 40 is -202.730397275718
## The bic criterion for iteration 41 is -202.730397275718
## The bic criterion for iteration 42 is -202.730397275718
## The bic criterion for iteration 43 is -202.730397275718
## The bic criterion for iteration 44 is -202.730397275718
## The bic criterion for iteration 45 is -202.730397275718
## The bic criterion for iteration 46 is -202.730397275718
## The bic criterion for iteration 47 is -202.730397275718
## The bic criterion for iteration 48 is -202.730397275718
## The bic criterion for iteration 49 is -202.730397275718
## The bic criterion for iteration 50 is -202.730397275718
## The bic criterion for iteration 51 is -202.730397275718
## The bic criterion for iteration 52 is -202.730397275718
## The bic criterion for iteration 53 is -202.730397275718
## The bic criterion for iteration 54 is -202.730397275718
## The bic criterion for iteration 55 is -202.730397275718
## The bic criterion for iteration 56 is -202.730397275718
## The bic criterion for iteration 57 is -202.730397275718
## The bic criterion for iteration 58 is -202.730397275718
## The bic criterion for iteration 59 is -202.730397275718
## The bic criterion for iteration 60 is -202.730397275718
## The bic criterion for iteration 61 is -202.730397275718
## The bic criterion for iteration 62 is -202.730397275718
## The bic criterion for iteration 63 is -202.730397275718
## The bic criterion for iteration 64 is -202.730397275718
## The bic criterion for iteration 65 is -202.730397275718
## The bic criterion for iteration 66 is -202.730397275718
## The bic criterion for iteration 67 is -202.730397275718
## The bic criterion for iteration 68 is -202.730397275718
## The bic criterion for iteration 69 is -202.730397275718
## The bic criterion for iteration 70 is -202.730397275718
## The bic criterion for iteration 71 is -202.730397275718
## The bic criterion for iteration 72 is -202.730397275718
## The bic criterion for iteration 73 is -202.730397275718
## The bic criterion for iteration 74 is -202.730397275718
## The bic criterion for iteration 75 is -202.730397275718
## The bic criterion for iteration 76 is -202.730397275718
## The bic criterion for iteration 77 is -202.730397275718
## The bic criterion for iteration 78 is -202.730397275718
## The bic criterion for iteration 79 is -202.730397275718
## The bic criterion for iteration 80 is -202.730397275718
## The bic criterion for iteration 81 is -202.730397275718
## The bic criterion for iteration 82 is -202.730397275718
## The bic criterion for iteration 83 is -202.730397275718
## The bic criterion for iteration 84 is -202.730397275718
## The bic criterion for iteration 85 is -202.730397275718
## The bic criterion for iteration 86 is -202.730397275718
## The bic criterion for iteration 87 is -202.730397275718
## The bic criterion for iteration 88 is -202.730397275718
## The bic criterion for iteration 89 is -202.730397275718
## The bic criterion for iteration 90 is -202.730397275718
## The bic criterion for iteration 91 is -202.730397275718
## The bic criterion for iteration 92 is -202.730397275718
## The bic criterion for iteration 93 is -202.730397275718
## The bic criterion for iteration 94 is -202.730397275718
## The bic criterion for iteration 95 is -202.730397275718
## The bic criterion for iteration 96 is -202.730397275718
## The bic criterion for iteration 97 is -202.730397275718
## The bic criterion for iteration 98 is -202.730397275718
## The bic criterion for iteration 99 is -202.730397275718
## The bic criterion for iteration 100 is -202.730397275718
## The bic criterion for iteration 101 is -202.730397275718
## The bic criterion for iteration 102 is -202.730397275718
## The bic criterion for iteration 103 is -202.730397275718
## The bic criterion for iteration 104 is -202.730397275718
## The bic criterion for iteration 105 is -202.730397275718
## The bic criterion for iteration 106 is -202.730397275718
## The bic criterion for iteration 107 is -202.730397275718
## The bic criterion for iteration 108 is -202.730397275718
## The bic criterion for iteration 109 is -202.730397275718
## The bic criterion for iteration 110 is -202.730397275718
## The bic criterion for iteration 111 is -202.730397275718
## The bic criterion for iteration 112 is -202.730397275718
## The bic criterion for iteration 113 is -202.730397275718
## The bic criterion for iteration 114 is -202.730397275718
## The bic criterion for iteration 115 is -202.730397275718
## The bic criterion for iteration 116 is -202.730397275718
## The bic criterion for iteration 117 is -202.730397275718
## The bic criterion for iteration 118 is -202.730397275718
## The bic criterion for iteration 119 is -202.730397275718
## The bic criterion for iteration 120 is -202.730397275718
## The bic criterion for iteration 121 is -202.730397275718
## The bic criterion for iteration 122 is -202.730397275718
## The bic criterion for iteration 123 is -202.730397275718
## The bic criterion for iteration 124 is -202.730397275718
## The bic criterion for iteration 125 is -202.730397275718
## The bic criterion for iteration 126 is -202.730397275718
## The bic criterion for iteration 127 is -202.730397275718
## The bic criterion for iteration 128 is -202.730397275718
## The bic criterion for iteration 129 is -202.730397275718
## The bic criterion for iteration 130 is -202.730397275718
## The bic criterion for iteration 131 is -202.730397275718
## The bic criterion for iteration 132 is -202.730397275718
## The bic criterion for iteration 133 is -202.730397275718
## The bic criterion for iteration 134 is -202.730397275718
## The bic criterion for iteration 135 is -202.730397275718
## The bic criterion for iteration 136 is -202.730397275718
## The bic criterion for iteration 137 is -202.730397275718
## The bic criterion for iteration 138 is -202.730397275718
## The bic criterion for iteration 139 is -202.730397275718
## The bic criterion for iteration 140 is -202.730397275718
## The bic criterion for iteration 141 is -202.730397275718
## The bic criterion for iteration 142 is -202.730397275718
## The bic criterion for iteration 143 is -202.730397275718
## The bic criterion for iteration 144 is -202.730397275718
## The bic criterion for iteration 145 is -202.730397275718
## The bic criterion for iteration 146 is -202.730397275718
## The bic criterion for iteration 147 is -202.730397275718
## The bic criterion for iteration 148 is -202.730397275718
## The bic criterion for iteration 149 is -202.730397275718
## The bic criterion for iteration 150 is -202.730397275718
## The bic criterion for iteration 151 is -202.730397275718
## The bic criterion for iteration 152 is -202.730397275718
## The bic criterion for iteration 153 is -202.730397275718
## The bic criterion for iteration 154 is -202.730397275718
## The bic criterion for iteration 155 is -202.730397275718
## The bic criterion for iteration 156 is -202.730397275718
## The bic criterion for iteration 157 is -202.730397275718
## The bic criterion for iteration 158 is -202.730397275718
## The bic criterion for iteration 159 is -202.730397275718
## The bic criterion for iteration 160 is -202.730397275718
## The bic criterion for iteration 161 is -202.730397275718
## The bic criterion for iteration 162 is -202.730397275718
## The bic criterion for iteration 163 is -202.730397275718
## The bic criterion for iteration 164 is -202.730397275718
## The bic criterion for iteration 165 is -202.730397275718
## The bic criterion for iteration 166 is -202.730397275718
## The bic criterion for iteration 167 is -202.730397275718
## The bic criterion for iteration 168 is -202.730397275718
## The bic criterion for iteration 169 is -202.730397275718
## The bic criterion for iteration 170 is -202.730397275718
## The bic criterion for iteration 171 is -202.730397275718
## The bic criterion for iteration 172 is -202.730397275718
## The bic criterion for iteration 173 is -202.730397275718
## The bic criterion for iteration 174 is -202.730397275718
## The bic criterion for iteration 175 is -202.730397275718
## The bic criterion for iteration 176 is -202.730397275718
## The bic criterion for iteration 177 is -202.730397275718
## The bic criterion for iteration 178 is -202.730397275718
## The bic criterion for iteration 179 is -202.730397275718
## The bic criterion for iteration 180 is -202.730397275718
## The bic criterion for iteration 181 is -202.730397275718
## The bic criterion for iteration 182 is -202.730397275718
## The bic criterion for iteration 183 is -202.730397275718
## The bic criterion for iteration 184 is -202.730397275718
## The bic criterion for iteration 185 is -202.730397275718
## The bic criterion for iteration 186 is -202.730397275718
## The bic criterion for iteration 187 is -202.730397275718
## The bic criterion for iteration 188 is -202.730397275718
## The bic criterion for iteration 189 is -202.730397275718
## The bic criterion for iteration 190 is -202.730397275718
## The bic criterion for iteration 191 is -202.730397275718
## The bic criterion for iteration 192 is -202.730397275718
## The bic criterion for iteration 193 is -202.730397275718
## The bic criterion for iteration 194 is -202.730397275718
## The bic criterion for iteration 195 is -202.730397275718
## The bic criterion for iteration 196 is -202.730397275718
## The bic criterion for iteration 197 is -202.730397275718
## The bic criterion for iteration 198 is -202.730397275718
## The bic criterion for iteration 199 is -202.730397275718
## The bic criterion for iteration 200 is -202.730397275718
data$c_map <- factor(apply(predict(tree@best.tree$tree,data,type="prob"),1,function(p) names(which.max(p))))
test$c_map <- factor(apply(predict(tree@best.tree$tree,data,type="prob"),1,function(p) names(which.max(p))))
table(data$c_map)
##
## 5 9
## 100 100
pred = matrix(0, nrow = 0.2*1000, ncol = 1)
for (j in levels(data$c_map)) {
modele = glm(y ~ x1 + x2, data = data[data$c_map==j,], family=binomial(link = "logit"))
pred[test$c_map==j] = predict(modele, test[test$c_map==j,], type="response")
}
normalizedGini(test$y,pred)
## [1] 0.6623515
mixed = FAMD(data[,c("x1","x2","x3")])
dim_famd = predict(mixed,test)$coord[,"Dim 1"] < 0
pred = matrix(0, nrow = 0.2*1000, ncol = 1)
for (j in c(TRUE,FALSE)) {
modele = glm(y ~ x1 + x2 + x3, data = data[dim_famd==j,], family=binomial(link = "logit"))
pred[dim_famd==j] = predict(modele, test[dim_famd==j,], type="response")
}
normalizedGini(test$y,pred)
## [1] 0.09950249
if (require(partykit, quietly = TRUE)) {
mob_data = partykit::glmtree(formula = y ~ x1 + x2 +x3 | x1 + x2 + x3, data = data, family = binomial)
plot(mob_data)
normalizedGini(test$y, predict(mob_data,test))
}
## [1] 0.3375334
glmtree
approach## The bic criterion for iteration 1 is -599.975732000295
## The bic criterion for iteration 2 is -300.14743855334
## The bic criterion for iteration 3 is -300.14743855334
## The bic criterion for iteration 4 is -300.14743855334
## The bic criterion for iteration 5 is -300.14743855334
## The bic criterion for iteration 6 is -300.14743855334
## The bic criterion for iteration 7 is -300.14743855334
## The bic criterion for iteration 8 is -300.14743855334
## The bic criterion for iteration 9 is -305.116920633568
## The bic criterion for iteration 10 is -300.14743855334
## The bic criterion for iteration 11 is -305.116920633568
## The bic criterion for iteration 12 is -300.14743855334
## The bic criterion for iteration 13 is -305.116920633568
## The bic criterion for iteration 14 is -305.116920633568
## The bic criterion for iteration 15 is -305.116920633568
## The bic criterion for iteration 16 is -305.116920633568
## The bic criterion for iteration 17 is -305.116920633568
## The bic criterion for iteration 18 is -305.116920633568
## The bic criterion for iteration 19 is -305.116920633568
## The bic criterion for iteration 20 is -305.116920633568
## The bic criterion for iteration 21 is -305.116920633568
## The bic criterion for iteration 22 is -305.116920633568
## The bic criterion for iteration 23 is -305.116920633568
## The bic criterion for iteration 24 is -305.116920633568
## The bic criterion for iteration 25 is -305.116920633568
## The bic criterion for iteration 26 is -305.116920633568
## The bic criterion for iteration 27 is -305.116920633568
## The bic criterion for iteration 28 is -305.116920633568
## The bic criterion for iteration 29 is -305.116920633568
## The bic criterion for iteration 30 is -300.14743855334
## The bic criterion for iteration 31 is -300.14743855334
## The bic criterion for iteration 32 is -300.14743855334
## The bic criterion for iteration 33 is -300.14743855334
## The bic criterion for iteration 34 is -300.14743855334
## The bic criterion for iteration 35 is -300.14743855334
## The bic criterion for iteration 36 is -305.116920633568
## The bic criterion for iteration 37 is -305.116920633568
## The bic criterion for iteration 38 is -305.116920633568
## The bic criterion for iteration 39 is -305.116920633568
## The bic criterion for iteration 40 is -305.116920633568
## The bic criterion for iteration 41 is -305.116920633568
## The bic criterion for iteration 42 is -305.116920633568
## The bic criterion for iteration 43 is -305.116920633568
## The bic criterion for iteration 44 is -305.116920633568
## The bic criterion for iteration 45 is -305.116920633568
## The bic criterion for iteration 46 is -305.116920633568
## The bic criterion for iteration 47 is -305.116920633568
## The bic criterion for iteration 48 is -305.116920633568
## The bic criterion for iteration 49 is -305.116920633568
## The bic criterion for iteration 50 is -305.116920633568
## The bic criterion for iteration 51 is -305.116920633568
## The bic criterion for iteration 52 is -305.116920633568
## The bic criterion for iteration 53 is -305.116920633568
## The bic criterion for iteration 54 is -305.116920633568
## The bic criterion for iteration 55 is -305.116920633568
## The bic criterion for iteration 56 is -305.116920633568
## The bic criterion for iteration 57 is -305.116920633568
## The bic criterion for iteration 58 is -305.116920633568
## The bic criterion for iteration 59 is -305.116920633568
## The bic criterion for iteration 60 is -305.116920633568
## The bic criterion for iteration 61 is -305.116920633568
## The bic criterion for iteration 62 is -305.116920633568
## The bic criterion for iteration 63 is -305.116920633568
## The bic criterion for iteration 64 is -305.116920633568
## The bic criterion for iteration 65 is -305.116920633568
## The bic criterion for iteration 66 is -305.116920633568
## The bic criterion for iteration 67 is -305.116920633568
## The bic criterion for iteration 68 is -305.116920633568
## The bic criterion for iteration 69 is -305.116920633568
## The bic criterion for iteration 70 is -305.116920633568
## The bic criterion for iteration 71 is -305.116920633568
## The bic criterion for iteration 72 is -305.116920633568
## The bic criterion for iteration 73 is -305.116920633568
## The bic criterion for iteration 74 is -305.116920633568
## The bic criterion for iteration 75 is -305.116920633568
## The bic criterion for iteration 76 is -305.116920633568
## The bic criterion for iteration 77 is -305.116920633568
## The bic criterion for iteration 78 is -305.116920633568
## The bic criterion for iteration 79 is -305.116920633568
## The bic criterion for iteration 80 is -305.116920633568
## The bic criterion for iteration 81 is -305.116920633568
## The bic criterion for iteration 82 is -305.116920633568
## The bic criterion for iteration 83 is -305.116920633568
## The bic criterion for iteration 84 is -305.116920633568
## The bic criterion for iteration 85 is -305.116920633568
## The bic criterion for iteration 86 is -305.116920633568
## The bic criterion for iteration 87 is -305.116920633568
## The bic criterion for iteration 88 is -305.116920633568
## The bic criterion for iteration 89 is -305.116920633568
## The bic criterion for iteration 90 is -305.116920633568
## The bic criterion for iteration 91 is -305.116920633568
## The bic criterion for iteration 92 is -305.116920633568
## The bic criterion for iteration 93 is -305.116920633568
## The bic criterion for iteration 94 is -305.116920633568
## The bic criterion for iteration 95 is -305.116920633568
## The bic criterion for iteration 96 is -305.116920633568
## The bic criterion for iteration 97 is -305.116920633568
## The bic criterion for iteration 98 is -305.116920633568
## The bic criterion for iteration 99 is -305.116920633568
## The bic criterion for iteration 100 is -305.116920633568
## The bic criterion for iteration 101 is -305.116920633568
## The bic criterion for iteration 102 is -305.116920633568
## The bic criterion for iteration 103 is -305.116920633568
## The bic criterion for iteration 104 is -305.116920633568
## The bic criterion for iteration 105 is -305.116920633568
## The bic criterion for iteration 106 is -305.116920633568
## The bic criterion for iteration 107 is -305.116920633568
## The bic criterion for iteration 108 is -305.116920633568
## The bic criterion for iteration 109 is -305.116920633568
## The bic criterion for iteration 110 is -305.116920633568
## The bic criterion for iteration 111 is -305.116920633568
## The bic criterion for iteration 112 is -305.116920633568
## The bic criterion for iteration 113 is -305.116920633568
## The bic criterion for iteration 114 is -305.116920633568
## The bic criterion for iteration 115 is -305.116920633568
## The bic criterion for iteration 116 is -305.116920633568
## The bic criterion for iteration 117 is -305.116920633568
## The bic criterion for iteration 118 is -305.116920633568
## The bic criterion for iteration 119 is -305.116920633568
## The bic criterion for iteration 120 is -305.116920633568
## The bic criterion for iteration 121 is -305.116920633568
## The bic criterion for iteration 122 is -305.116920633568
## The bic criterion for iteration 123 is -305.116920633568
## The bic criterion for iteration 124 is -305.116920633568
## The bic criterion for iteration 125 is -305.116920633568
## The bic criterion for iteration 126 is -305.116920633568
## The bic criterion for iteration 127 is -305.116920633568
## The bic criterion for iteration 128 is -305.116920633568
## The bic criterion for iteration 129 is -305.116920633568
## The bic criterion for iteration 130 is -305.116920633568
## The bic criterion for iteration 131 is -305.116920633568
## The bic criterion for iteration 132 is -305.116920633568
## The bic criterion for iteration 133 is -305.116920633568
## The bic criterion for iteration 134 is -305.116920633568
## The bic criterion for iteration 135 is -305.116920633568
## The bic criterion for iteration 136 is -305.116920633568
## The bic criterion for iteration 137 is -305.116920633568
## The bic criterion for iteration 138 is -305.116920633568
## The bic criterion for iteration 139 is -305.116920633568
## The bic criterion for iteration 140 is -305.116920633568
## The bic criterion for iteration 141 is -305.116920633568
## The bic criterion for iteration 142 is -305.116920633568
## The bic criterion for iteration 143 is -305.116920633568
## The bic criterion for iteration 144 is -305.116920633568
## The bic criterion for iteration 145 is -305.116920633568
## The bic criterion for iteration 146 is -305.116920633568
## The bic criterion for iteration 147 is -305.116920633568
## The bic criterion for iteration 148 is -305.116920633568
## The bic criterion for iteration 149 is -305.116920633568
## The bic criterion for iteration 150 is -305.116920633568
## The bic criterion for iteration 151 is -305.116920633568
## The bic criterion for iteration 152 is -305.116920633568
## The bic criterion for iteration 153 is -305.116920633568
## The bic criterion for iteration 154 is -305.116920633568
## The bic criterion for iteration 155 is -305.116920633568
## The bic criterion for iteration 156 is -305.116920633568
## The bic criterion for iteration 157 is -305.116920633568
## The bic criterion for iteration 158 is -305.116920633568
## The bic criterion for iteration 159 is -305.116920633568
## The bic criterion for iteration 160 is -305.116920633568
## The bic criterion for iteration 161 is -305.116920633568
## The bic criterion for iteration 162 is -305.116920633568
## The bic criterion for iteration 163 is -305.116920633568
## The bic criterion for iteration 164 is -305.116920633568
## The bic criterion for iteration 165 is -305.116920633568
## The bic criterion for iteration 166 is -305.116920633568
## The bic criterion for iteration 167 is -305.116920633568
## The bic criterion for iteration 168 is -305.116920633568
## The bic criterion for iteration 169 is -305.116920633568
## The bic criterion for iteration 170 is -305.116920633568
## The bic criterion for iteration 171 is -305.116920633568
## The bic criterion for iteration 172 is -305.116920633568
## The bic criterion for iteration 173 is -305.116920633568
## The bic criterion for iteration 174 is -305.116920633568
## The bic criterion for iteration 175 is -305.116920633568
## The bic criterion for iteration 176 is -305.116920633568
## The bic criterion for iteration 177 is -305.116920633568
## The bic criterion for iteration 178 is -305.116920633568
## The bic criterion for iteration 179 is -305.116920633568
## The bic criterion for iteration 180 is -305.116920633568
## The bic criterion for iteration 181 is -305.116920633568
## The bic criterion for iteration 182 is -305.116920633568
## The bic criterion for iteration 183 is -305.116920633568
## The bic criterion for iteration 184 is -305.116920633568
## The bic criterion for iteration 185 is -305.116920633568
## The bic criterion for iteration 186 is -305.116920633568
## The bic criterion for iteration 187 is -305.116920633568
## The bic criterion for iteration 188 is -305.116920633568
## The bic criterion for iteration 189 is -305.116920633568
## The bic criterion for iteration 190 is -305.116920633568
## The bic criterion for iteration 191 is -305.116920633568
## The bic criterion for iteration 192 is -305.116920633568
## The bic criterion for iteration 193 is -305.116920633568
## The bic criterion for iteration 194 is -305.116920633568
## The bic criterion for iteration 195 is -305.116920633568
## The bic criterion for iteration 196 is -305.116920633568
## The bic criterion for iteration 197 is -305.116920633568
## The bic criterion for iteration 198 is -305.116920633568
## The bic criterion for iteration 199 is -305.116920633568
## The bic criterion for iteration 200 is -305.116920633568
data$c_map <- factor(apply(predict(tree@best.tree$tree,data,type="prob"),1,function(p) names(which.max(p))))
test$c_map <- factor(apply(predict(tree@best.tree$tree,test,type="prob"),1,function(p) names(which.max(p))))
table(data$c,data$c_map)
##
## 7 8
## 1 40 37
## 2 29 37
## 3 31 26
pred = matrix(0, nrow = 0.2*1000, ncol = 1)
for (j in 1:nlevels(data$c_map)) {
pred[test$c_map==levels(data$c_map)[j]] = predict(tree@best.tree$glms[[j]], test[test$c_map==levels(data$c_map)[j],], type="response")
}
normalizedGini(test$y,pred)
## [1] 0.3566589