tester_bn* NewNetTester_bn ( nodelist_bn*  test_nodes,   nodelist_bn*  unobsv_nodes,   int  tests )

Creates a tester_bn which is a tool for grading a Bayes net, using a set of real cases to see how well the predictions or diagnosis of the net match the actual cases. It is not for decision networks.

test_nodes are the nodes that the Bayes net will predict and get rated on. Their values in the case file are all hidden from the Bayes net (i.e., unobserved) whenever a case is read. For each such case, the Bayes net does a prediction and compares that prediction with the true value from the case file, accumulating statistics as it goes.

If unobsv_nodes is non-NULL, then the nodes it contains will also be unobserved. It is okay if it repeats nodes already in test_nodes.

Pass -1 for tests.

After creating the tester_bn object, you run the tests using TestWithCaseset_bn, and then read out the results of the tests with the GetTest... functions. When done, you discard the tester_bn with DeleteNetTester_bn.

IMPORTANT: Before calling TestWithCaseset_bn, you may want to call RetractNetFindings_bn to remove any findings entered, because otherwise those findings will be considered while testing each case in the file.

The same net-testing capability is available as "Cases -> Test With Cases" in Netica Application.

Version:

Versions 2.08 and later have this function.

See also:

TestWithCaseset_bn    Accumulate case data into the test
GetTestConfusion_bn    Get elements of the confusion matrix
GetTestErrorRate_bn    Get fraction of test cases where prediction failed
GetTestLogLoss_bn    Get the "logarithmic loss" score of the test
GetTestQuadraticLoss_bn    Get the "quadratic loss" score of the test
DeleteNetTester_bn    Free up tester and all its resources
NewNodeList2_bn    Create the node lists

Example:

net_bn* net = ReadNet_bn (NewFileStream_ns ("ChestClinic.dne", env, NULL), NO_VISUAL_INFO);
nodelist_bn* unobsv_nodes = NewNodeList2_bn (0, net);
nodelist_bn*   test_nodes = NewNodeList2_bn (0, net);
node_bn* test_node = GetNodeNamed_bn ("Cancer", net);
AddNodeToList_bn (test_node, test_nodes, LAST_ENTRY);
// Now make the unobserved nodes list out of other factors not known during diagnosis:
AddNodeToList_bn (GetNodeNamed_bn ("Tuberculosis", net), unobsv_nodes, LAST_ENTRY);
AddNodeToList_bn (GetNodeNamed_bn ("Bronchitis", net), unobsv_nodes, LAST_ENTRY);
AddNodeToList_bn (GetNodeNamed_bn ("TbOrCa", net), unobsv_nodes, LAST_ENTRY);
RetractNetFindings_bn (net);   // IMPORTANT: Otherwise any findings will be part of tests !!
CompileNet_bn (net);

tester_bn* tester = NewNetTester_bn (test_nodes, unobsv_nodes, -1);

stream_ns* casefile = NewFileStream_ns ("ChestClinic.cas", env, NULL);
caseset_cs* caseset = NewCaseset_cs ("ChestClinicCases", env);
AddFileToCaseset_cs (caseset, casefile, 1.0, NULL);
TestWithCaseset_bn (tester, caseset); 

PrintConfusionMatrix (tester, test_node); // defined in example for GetTestConfusion_bn
printf ("Error rate = %f %\n", 100 * GetTestErrorRate_bn (tester, test_node));
printf ("Logarithmic loss = %f %\n", GetTestLogLoss_bn (tester, test_node));

DeleteNetTester_bn (tester);
DeleteCaseset_cs (caseset);
//====================================================
Confusion matrix for Cancer:
        Present  Absent  Actual
        6        1       Present
        1        192     Absent

Error rate = 1 %

Logarithmic loss = 0.02794