Description
K2 is a score-based greedy search algorithm for learning Bayesian networks from data. It was published in Cooper, G. and Herskovits, E. (1992). It is a Bayesian method for the induction of probabilistic networks from data. K2 uses a Bayesian score, P(Bs, D), to rank different structures and it uses a greedy search algorithm to maxmize P(Bs, D). The main classes in the k2 package are K2Manager.java, which loads the input training data, and K2.java, which implements the learning procedure. (Please see our references.) K2 can either be run graphically or from the command line, as appears below.
Inputs to K2 include:
Output of K2: For each node, K2 returns its most probable parents given the training data D.
In our implementation, the set of nodes and the database D are stored in the input training data file in xml format. The upper bound u is set to a fixed value of 5 in K2.java. The required ordering can be input from the command line. If no ordering is given at the command line, 0 - n is assumed according to the node ordering in the input data file. The output of K2 is the learned network in XMLBIF format. You can use the network editor to open and see its structure.
Example
Use K2 to learn a Bayesian network from training data. To run K2, first we need to prepare the input training data. In this example, we first use DataGenerator to generate the training data, then we run K2 on this training dataset to recover (learn) the network from the data. You can view the resulting network -- learned.xml -- here.============================= Example of K2 ======================================== D:\bnj>java bbn/DataGenerator2 asia.xml asia1500.xml 1500 * * * DataGenerator2 * * * Usage: java DataGenerator2 input.xml output.xml number_of_samples (0 will genera te an evdience file) Success! D:\bnj>java k2/K2 asia1500.xml learned.xml Usage: java k2.K2 input.xml output.xml [order] (if no order is given, 0 - n is assumed). [loaded network and training samples] [Network learned.] [Finished.] D:\bnj> ========================== End of K2 Example======================================