Based on a given network structure, I created a data frame of 100 instances for six binary variables(x1 to x6). So it's a 100 x 6 data frame of 0/1 values stored in a variable 'input_params'. Created an empty graph using statements:
library(bnlearn)
bn_graph = empty.graph(names(input_params))
But when I try fitting above parameters('input_params') in the network using
bn_nw <- bn.fit(bn_graph, input_params)
I get an error saying
Error in data.type(x) :
variable x1 is not supported in bnlearn (type: integer).
What data type conversion should I do to avoid this error? Right now its 0 or 1 in the values.
The function
bn.fit()
in the packagebnlearn
calculates a local conditional probability distribution for each variable.In the discrete case we expect
categorical
(factor function) parameters (in the columns"fac1","fac2","fac3"
) :fac_cols <- c("fac1","fac2","fac3")
Is is the data continous (e.g. measurements from a sensor) the data needs to be of type
numeric
(numeric function):num_cols <- c("num1","num2","num3")
Assuming
input_params
is a data.frame, we need to transform both sets of columns (fac_cols
,num_cols
) by either:or with
dplyr