@@ -145,7 +145,18 @@ is.jaspMachineLearning <- function(x) {
145
145
as.character(levels(as.factor(model $ model [, 1 ]))[round(predict(model , newdata = dataset , type = " response" ), 0 ) + 1 ])
146
146
}
147
147
.mlPredictionGetPredictions.vglm <- function (model , dataset ) {
148
- # TODO
148
+ model [[" original" ]]@ terms $ terms <- model [[" terms" ]]
149
+ logodds <- predict(model [[" original" ]], newdata = dataset )
150
+ ncategories <- ncol(logodds ) + 1
151
+ probabilities <- matrix (0 , nrow = nrow(logodds ), ncol = ncategories )
152
+ for (i in seq_len(ncategories - 1 )) {
153
+ probabilities [, i ] <- exp(logodds [, i ])
154
+ }
155
+ probabilities [, ncategories ] <- 1
156
+ row_sums <- rowSums(probabilities )
157
+ probabilities <- probabilities / row_sums
158
+ predicted_columns <- apply(probabilities , 1 , which.max )
159
+ as.character(levels(as.factor(model $ target ))[predicted_columns ])
149
160
}
150
161
151
162
# S3 method to make find out number of observations in training data
@@ -186,7 +197,7 @@ is.jaspMachineLearning <- function(x) {
186
197
nrow(model [[" data" ]])
187
198
}
188
199
.mlPredictionGetTrainingN.vglm <- function (model ) {
189
- nrow(model $ x )
200
+ nrow(model [[ " x " ]] )
190
201
}
191
202
192
203
# S3 method to decode the model variables in the result object
@@ -253,7 +264,8 @@ is.jaspMachineLearning <- function(x) {
253
264
return (model )
254
265
}
255
266
.decodeJaspMLobject.vglm <- function (model ) {
256
- # TODO
267
+ formula <- formula(paste(decodeColNames(strsplit(as.character(model $ terms ), " " )[[1 ]][1 ]), " ~" , paste0(decodeColNames(strsplit(strsplit(as.character(model $ terms ), split = " ~ " )[[1 ]][2 ], split = " + " , fixed = TRUE )[[1 ]]), collapse = " + " )))
268
+ model $ terms <- stats :: terms(formula )
257
269
return (model )
258
270
}
259
271
0 commit comments