All Implemented Interfaces:
Serializable, OptionHandler, RevisionHandler, TechnicalInformationHandler

public class K2 extends LocalScoreSearchAlgorithm implements TechnicalInformationHandler
This Bayes Network learning algorithm uses a hill climbing algorithm restricted by an order on the variables.

For more information see:

G.F. Cooper, E. Herskovits (1990). A Bayesian method for constructing Bayesian belief networks from databases.

G. Cooper, E. Herskovits (1992). A Bayesian method for the induction of probabilistic networks from data. Machine Learning. 9(4):309-347.

Works with nominal variables and no missing values only.

BibTeX:

 @proceedings{Cooper1990,
    author = {G.F. Cooper and E. Herskovits},
    booktitle = {Proceedings of the Conference on Uncertainty in AI},
    pages = {86-94},
    title = {A Bayesian method for constructing Bayesian belief networks from databases},
    year = {1990}
 }
 
 @article{Cooper1992,
    author = {G. Cooper and E. Herskovits},
    journal = {Machine Learning},
    number = {4},
    pages = {309-347},
    title = {A Bayesian method for the induction of probabilistic networks from data},
    volume = {9},
    year = {1992}
 }
 

Valid options are:

 -N
  Initial structure is empty (instead of Naive Bayes)
 
 -P <nr of parents>
  Maximum number of parents
 
 -R
  Random order.
  (default false)
 
 -mbc
  Applies a Markov Blanket correction to the network structure, 
  after a network structure is learned. This ensures that all 
  nodes in the network are part of the Markov blanket of the 
  classifier node.
 
 -S [BAYES|MDL|ENTROPY|AIC|CROSS_CLASSIC|CROSS_BAYES]
  Score type (BAYES, BDeu, MDL, ENTROPY and AIC)
 
Version:
$Revision: 11247 $
Author:
Remco Bouckaert (rrb@xm.co.nz)
See Also:
  • Constructor Details

    • K2

      public K2()
  • Method Details

    • getTechnicalInformation

      public TechnicalInformation getTechnicalInformation()
      Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
      Specified by:
      getTechnicalInformation in interface TechnicalInformationHandler
      Returns:
      the technical information about this class
    • search

      public void search(BayesNet bayesNet, Instances instances) throws Exception
      search determines the network structure/graph of the network with the K2 algorithm, restricted by its initial structure (which can be an empty graph, or a Naive Bayes graph.
      Parameters:
      bayesNet - the network
      instances - the data to work with
      Throws:
      Exception - if something goes wrong
    • setMaxNrOfParents

      public void setMaxNrOfParents(int nMaxNrOfParents)
      Sets the max number of parents
      Parameters:
      nMaxNrOfParents - the max number of parents
    • getMaxNrOfParents

      public int getMaxNrOfParents()
      Gets the max number of parents.
      Returns:
      the max number of parents
    • setInitAsNaiveBayes

      public void setInitAsNaiveBayes(boolean bInitAsNaiveBayes)
      Sets whether to init as naive bayes
      Parameters:
      bInitAsNaiveBayes - whether to init as naive bayes
    • getInitAsNaiveBayes

      public boolean getInitAsNaiveBayes()
      Gets whether to init as naive bayes
      Returns:
      whether to init as naive bayes
    • setRandomOrder

      public void setRandomOrder(boolean bRandomOrder)
      Set random order flag
      Parameters:
      bRandomOrder - the random order flag
    • getRandomOrder

      public boolean getRandomOrder()
      Get random order flag
      Returns:
      the random order flag
    • listOptions

      public Enumeration<Option> listOptions()
      Returns an enumeration describing the available options.
      Specified by:
      listOptions in interface OptionHandler
      Overrides:
      listOptions in class LocalScoreSearchAlgorithm
      Returns:
      an enumeration of all the available options.
    • setOptions

      public void setOptions(String[] options) throws Exception
      Parses a given list of options.

      Valid options are:

       -N
        Initial structure is empty (instead of Naive Bayes)
       
       -P <nr of parents>
        Maximum number of parents
       
       -R
        Random order.
        (default false)
       
       -mbc
        Applies a Markov Blanket correction to the network structure, 
        after a network structure is learned. This ensures that all 
        nodes in the network are part of the Markov blanket of the 
        classifier node.
       
       -S [BAYES|MDL|ENTROPY|AIC|CROSS_CLASSIC|CROSS_BAYES]
        Score type (BAYES, BDeu, MDL, ENTROPY and AIC)
       
      Specified by:
      setOptions in interface OptionHandler
      Overrides:
      setOptions in class LocalScoreSearchAlgorithm
      Parameters:
      options - the list of options as an array of strings
      Throws:
      Exception - if an option is not supported
    • getOptions

      public String[] getOptions()
      Gets the current settings of the search algorithm.
      Specified by:
      getOptions in interface OptionHandler
      Overrides:
      getOptions in class LocalScoreSearchAlgorithm
      Returns:
      an array of strings suitable for passing to setOptions
    • globalInfo

      public String globalInfo()
      This will return a string describing the search algorithm.
      Overrides:
      globalInfo in class LocalScoreSearchAlgorithm
      Returns:
      The string.
    • randomOrderTipText

      public String randomOrderTipText()
      Returns:
      a string to describe the RandomOrder option.
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Overrides:
      getRevision in class LocalScoreSearchAlgorithm
      Returns:
      the revision