有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java通过wekaapi构建bayes网

我想用一个现有的数据集构建一个贝叶斯网络(或贝叶斯网络),有没有人用WEKAAPI学习贝叶斯网络的演示代码


共 (1) 个答案

  1. # 1 楼答案

    //==============================学习贝叶斯网络(结构和CPT)===================== //K2学习者=新K2();//集合搜索算法1

        //MultiNomialBMAEstimator estimator = new MultiNomialBMAEstimator(); //set estimator 1
        //estimator.setUseK2Prior(true);
    
        //BMAEstimator estimator = new BMAEstimator(); //set estimator 2
    
        SimpleEstimator estimator = new SimpleEstimator(); //set estimator 3
        SimulatedAnnealing learner = new SimulatedAnnealing(); // set search algorithm 2    
    
        Evaluation evaluation = new Evaluation(ins);
    
        EditableBayesNet bnBayesNet = new EditableBayesNet(ins);
        bnBayesNet.initStructure();
    
        learner.buildStructure(bnBayesNet, ins);
        estimator.estimateCPTs(bnBayesNet);
    
        //=================== visualize the bayes net ====================
        GraphVisualizer graphVisualizer = new GraphVisualizer();
        graphVisualizer.readBIF(bnBayesNet.graph());
    
        final JFrame jFrame = new JFrame("Weka Classifier Graph Visualizer: Bayes net");
        jFrame.setSize(500, 400);
        jFrame.getContentPane().setLayout(new BorderLayout());
        jFrame.getContentPane().add(graphVisualizer, BorderLayout.CENTER);
        jFrame.addWindowFocusListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                jFrame.dispose();               
            }
        });
        jFrame.setVisible(true);
        graphVisualizer.layoutGraph();