Learn R Programming

dbnR (version 0.7.1)

predict_dt: Performs inference over a test data set with a GBN

Description

Performs inference over a test data set, plots the results and gives metrics of the accuracy of the results.

Usage

predict_dt(fit, dt, obj_nodes, verbose = T)

Arguments

fit

the fitted bn

dt

the test data set

obj_nodes

the nodes that are going to be predicted. They are all predicted at the same time

verbose

if TRUE, displays the metrics and plots the real values against the predictions

Value

the prediction results

Examples

Run this code
# NOT RUN {
size = 3
data(motor)
dt_train <- motor[200:2500]
dt_val <- motor[2501:3000]

# With a DBN 
obj <- c("pm_t_0")
net <- learn_dbn_struc(dt_train, size)
f_dt_train <- fold_dt(dt_train, size)
f_dt_val <- fold_dt(dt_val, size)
fit <- fit_dbn_params(net, f_dt_train, method = "mle")
res <- suppressWarnings(predict_dt(fit, f_dt_val, obj_nodes = obj, verbose = FALSE))

# With a Gaussian BN directly from bnlearn
obj <- c("pm")
net <- bnlearn::mmhc(dt_train)
fit <- bnlearn::bn.fit(net, dt_train, method = "mle")
res <- suppressWarnings(predict_dt(fit, dt_val, obj_nodes = obj, verbose = FALSE))
# }

Run the code above in your browser using DataLab