NaiveBayesClassifier nb = new NaiveBayesClassifier(data.getAttributes()); nb.setClassName(classVarName); nb.updateModel(data); for (DataOnMemory<DataInstance> batch : data.iterableOverBatches(100)) { nb.updateModel(batch); System.out.println(nb.getModel()); System.out.println(nb.getDAG()); double realValue = d.getValue(nb.getClassVar()); double predValue; d.setValue(nb.getClassVar(), Utils.missingValue()); Multinomial posteriorProb = nb.predict(d);
/** * Constructor of the classifier which is initialized with the default arguments: * the last variable in attributes is the class variable and importance sampling * is the inference algorithm for making the predictions. * @param attributes list of attributes of the classifier (i.e. its variables) * @throws WrongConfigurationException is thrown when the attributes passed are not suitable * for such classifier */ public NaiveBayesClassifier(Attributes attributes) throws WrongConfigurationException { super(attributes); this.setLearningAlgorithm(new ParallelMLMissingData()); }
NaiveBayesClassifier model = new NaiveBayesClassifier(data.getAttributes()); model.setClassName(data.getAttributes().getFullListOfAttributes().get(data.getAttributes().getFullListOfAttributes().size() - 1).getName()); model.updateModel(data); BayesianNetwork nbClassifier = model.getModel(); System.out.println(nbClassifier.toString());
/** * tests if the attributes passed as an argument in the constructor are suitable for this classifier * @return boolean value with the result of the test. */ @Override public boolean isValidConfiguration(){ boolean isValid = true; long numFinite = vars.getListOfVariables().stream() .filter( v -> v.getStateSpaceTypeEnum().equals(StateSpaceTypeEnum.FINITE_SET)) .count(); if(numFinite == 0) { isValid = false; String errorMsg = "It should contain at least 1 discrete variable and the rest shoud be real"; this.setErrorMessage(errorMsg); } return isValid; }