bnlearn

Importing any function from an R package into python

社会主义新天地 提交于 2020-02-05 06:02:04
问题 While using the rpy2 library of Python to work with R. I get the following error message while trying to import a function of the bnlearn package : # Using R inside python import rpy2 import rpy2.robjects as robjects import rpy2.robjects.packages as rpackages from rpy2.robjects.vectors import StrVector from rpy2.robjects.packages import importr utils = rpackages.importr('utils') utils.chooseCRANmirror(ind=1) # Install packages packnames = ('visNetwork', 'bnlearn') utils.install_packages

Importing any function from an R package into python

坚强是说给别人听的谎言 提交于 2020-02-05 06:01:17
问题 While using the rpy2 library of Python to work with R. I get the following error message while trying to import a function of the bnlearn package : # Using R inside python import rpy2 import rpy2.robjects as robjects import rpy2.robjects.packages as rpackages from rpy2.robjects.vectors import StrVector from rpy2.robjects.packages import importr utils = rpackages.importr('utils') utils.chooseCRANmirror(ind=1) # Install packages packnames = ('visNetwork', 'bnlearn') utils.install_packages

BNlearn R error “variable Variable1 must have at least two levels.”

风格不统一 提交于 2019-12-31 04:10:49
问题 Trying to create a BN using BNlearn, but I keep getting an error; Error in check.data(data, allowed.types = discrete.data.types) : variable Variable1 must have at least two levels. It gives me that error for every of my variable, even though they're all factors and has more than 1 levels, As you can see - in this case my variable "model" has 4 levels As I can't share the variables and dataset, I've created a small set and belonging code to the data set. I get the same problem. I know I've

BNlearn R error “variable Variable1 must have at least two levels.”

巧了我就是萌 提交于 2019-12-31 04:10:08
问题 Trying to create a BN using BNlearn, but I keep getting an error; Error in check.data(data, allowed.types = discrete.data.types) : variable Variable1 must have at least two levels. It gives me that error for every of my variable, even though they're all factors and has more than 1 levels, As you can see - in this case my variable "model" has 4 levels As I can't share the variables and dataset, I've created a small set and belonging code to the data set. I get the same problem. I know I've

R bnlearn eval inside function

落花浮王杯 提交于 2019-12-20 02:39:17
问题 I am using the bnlearn package in R to train a Bayesian network. I have troubles with the following code (slightly modified bnlearn example code): library(bnlearn) data(learning.test) fitted = bn.fit(hc(learning.test), learning.test) myfuncBN=function(){ var = names(learning.test) obs = 2 str = paste("(", names(learning.test)[-3], "=='", sapply(learning.test[obs,-3], as.character), "')", sep = "", collapse = " & ") str2 = paste("(", names(learning.test)[3], "=='", as.character(learning.test

Prediction with cpdist using “probabilities” as evidence

僤鯓⒐⒋嵵緔 提交于 2019-12-11 02:39:29
问题 I have a very quick question with an easy reproducible example that is related to my work on prediction with bnlearn library(bnlearn) Learning.set4=cbind(c("Yes","Yes","Yes","No","No","No"),c(9,10,8,3,2,1)) Learning.set4=as.data.frame(Learning.set4) Learning.set4[,c(2)]=as.numeric(as.character(Learning.set4[,c(2)])) colnames(Learning.set4)=c("Cause","Cons") b.network=empty.graph(colnames(Learning.set4)) struct.mat=matrix(0,2,2) colnames(struct.mat)=colnames(Learning.set4) rownames(struct.mat)

bnlearn + Rgraphviz: double arrows instead of undirected edges when customizing plots

爷,独闯天下 提交于 2019-12-04 16:48:44
I am trying to customize a plot of a graph learned with bnlearn using RGraphviz . When I have undirected edges, RGraphviz turns them into directed edges to both directions when I try to customize the appearance of the graph. A reproducible example could be: set.seed(1) x1 = rnorm(50, 0, 1) x2 = rnorm(50, 0, 1) x3 = x2 + rnorm(50, 0, 1) x4 = -2*x1 + x3 + rnorm(50, 0, 1) graph = data.frame(x1, x2, x3, x4) library(bnlearn) library(Rgraphviz) res = gs(graph) options(repr.plot.width=3, repr.plot.height=3) g1 <- graphviz.plot(res) Graph not customized: So far so good. But if I try to customize it: