Skip to main content
Tweeted twitter.com/#!/StackStats/status/492061296767283200
added 70 characters in body
Source Link

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What I want to do is to "predict" the value of a node given the value of other nodes as evidence (obviously, with the exception of the node whose values we are predicting).

I have continuous variables.

library(bnlearn)                       # Load the package in R
data(gaussian.test)
training.set = gaussian.test[1:4000, ] # This is training set to learn the parameters
test.set = gaussian.test[4001:4010, ]  # This is test set to give as evidence
res = hc(training.set)                 # learn BN structure on training set data 
fitted = bn.fit(res, training.set)     # learning of parameters
pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I do not understand the reason for that, could someone please explain it?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

test.set$C = 0                     # To not give the original value of node C as evidence
pred = predict(fitted$C, test.set) # predicts the value of node C given test set
table(pred, test.set[, "C"])       # compares the predicted value as original
   

Is this approach wrong? (Using "NA" is not allowed.)

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What I want to do is to "predict" the value of a node given the value of other nodes as evidence (obviously, with the exception of the node whose values we are predicting).

I have continuous variables.

data(gaussian.test)
training.set = gaussian.test[1:4000, ] # This is training set to learn the parameters
test.set = gaussian.test[4001:4010, ]  # This is test set to give as evidence
res = hc(training.set)                 # learn BN structure on training set data 
fitted = bn.fit(res, training.set)     # learning of parameters
pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I do not understand the reason for that, could someone please explain it?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

test.set$C = 0                     # To not give the original value of node C as evidence
pred = predict(fitted$C, test.set) # predicts the value of node C given test set
table(pred, test.set[, "C"])       # compares the predicted value as original
   

Is this approach wrong? (Using "NA" is not allowed.)

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What I want to do is to "predict" the value of a node given the value of other nodes as evidence (obviously, with the exception of the node whose values we are predicting).

I have continuous variables.

library(bnlearn)                       # Load the package in R
data(gaussian.test)
training.set = gaussian.test[1:4000, ] # This is training set to learn the parameters
test.set = gaussian.test[4001:4010, ]  # This is test set to give as evidence
res = hc(training.set)                 # learn BN structure on training set data 
fitted = bn.fit(res, training.set)     # learning of parameters
pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I do not understand the reason for that, could someone please explain it?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

test.set$C = 0                     # To not give the original value of node C as evidence
pred = predict(fitted$C, test.set) # predicts the value of node C given test set
table(pred, test.set[, "C"])       # compares the predicted value as original
   

Is this approach wrong? (Using "NA" is not allowed.)

light editing & formatting
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What What I want to do is to "predict" the value of a node given the value of other nodes as evidence ( obviouslyobviously, with the exception of the node whose values we are predicting).

I have continuous variables.

  data(gaussian.test)
  training.set = gaussian.test[1:4000, ] #This# This is training set to learn the parameters
  test.set = gaussian.test[4001:4010, ]  #This# This is test set to give as evidence
  res = hc(training.set)                 # learn BN structure on training set data 
  fitted = bn.fit(res, training.set)     # learning of parameters
  pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
  table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I coulddo not getunderstand the reason for that ? Could, could someone please explain it?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

  test.set$C = 0                 # To not give the original value of node C as evidence
  pred = predict(fitted$$C = 0                     # To not give the original value of node C as evidence
pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
  table(pred, test.set[, "C"])           # compares the predicted value as original
   

Is this a wrong approach wrong? Using(Using "NA" is not allowed. Thanks a lot!)

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What I want to do is to "predict" the value of a node given the value of other nodes as evidence ( obviously, with the exception of the node whose values we are predicting).

I have continuous variables.

  data(gaussian.test)
  training.set = gaussian.test[1:4000, ] #This is training set to learn the parameters
  test.set = gaussian.test[4001:4010, ]  #This is test set to give as evidence
  res = hc(training.set)                 # learn BN structure on training set data 
  fitted = bn.fit(res, training.set)     # learning of parameters
  pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
  table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I could not get the reason for that ? Could someone please explain ?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

  test.set$C = 0                 # To not give the original value of node C as evidence
  pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
  table(pred, test.set[, "C"])           # compares the predicted value as original
   

Is this a wrong approach ? Using "NA" is not allowed. Thanks a lot!

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What I want to do is to "predict" the value of a node given the value of other nodes as evidence (obviously, with the exception of the node whose values we are predicting).

I have continuous variables.

data(gaussian.test)
training.set = gaussian.test[1:4000, ] # This is training set to learn the parameters
test.set = gaussian.test[4001:4010, ]  # This is test set to give as evidence
res = hc(training.set)                 # learn BN structure on training set data 
fitted = bn.fit(res, training.set)     # learning of parameters
pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I do not understand the reason for that, could someone please explain it?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

test.set$C = 0                     # To not give the original value of node C as evidence
pred = predict(fitted$C, test.set) # predicts the value of node C given test set
table(pred, test.set[, "C"])       # compares the predicted value as original
   

Is this approach wrong? (Using "NA" is not allowed.)

Source Link

Prediction of continuous variable using "bnlearn" package in R

I use bnlearn package in R to learn the structure of my Bayesian Network and its parameters. What I want to do is to "predict" the value of a node given the value of other nodes as evidence ( obviously, with the exception of the node whose values we are predicting).

I have continuous variables.

  data(gaussian.test)
  training.set = gaussian.test[1:4000, ] #This is training set to learn the parameters
  test.set = gaussian.test[4001:4010, ]  #This is test set to give as evidence
  res = hc(training.set)                 # learn BN structure on training set data 
  fitted = bn.fit(res, training.set)     # learning of parameters
  pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
  table(pred, test.set[, "C"])           # compares the predicted value as original

Now, this code works well and gives a table in which you can see that predicted values for node C are exactly same as the original value of node C in test set.

I could not get the reason for that ? Could someone please explain ?

I know, I am providing entire df of test set that already has the value of node C in it. But if I give the data of other columns, it gives an error. So, I tried an alternative of putting other values to 0.

  test.set$C = 0                 # To not give the original value of node C as evidence
  pred = predict(fitted$C, test.set)     # predicts the value of node C given test set
  table(pred, test.set[, "C"])           # compares the predicted value as original
   

Is this a wrong approach ? Using "NA" is not allowed. Thanks a lot!