List of usage examples for weka.classifiers.trees J48 setConfidenceFactor
public void setConfidenceFactor(float v)
From source file:kfst.classifier.WekaClassifier.java
License:Open Source License
/** * This method builds and evaluates the decision tree(DT) classifier. * The j48 are used as the DT classifier implemented in the Weka software. * * @param pathTrainData the path of the train set * @param pathTestData the path of the test set * @param confidenceValue The confidence factor used for pruning * @param minNumSampleInLeaf The minimum number of instances per leaf * /*from ww w .j av a 2 s . co m*/ * @return the classification accuracy */ public static double dTree(String pathTrainData, String pathTestData, double confidenceValue, int minNumSampleInLeaf) { double resultValue = 0; try { BufferedReader readerTrain = new BufferedReader(new FileReader(pathTrainData)); Instances dataTrain = new Instances(readerTrain); readerTrain.close(); dataTrain.setClassIndex(dataTrain.numAttributes() - 1); BufferedReader readerTest = new BufferedReader(new FileReader(pathTestData)); Instances dataTest = new Instances(readerTest); readerTest.close(); dataTest.setClassIndex(dataTest.numAttributes() - 1); J48 decisionTree = new J48(); decisionTree.setConfidenceFactor((float) confidenceValue); decisionTree.setMinNumObj(minNumSampleInLeaf); decisionTree.buildClassifier(dataTrain); Evaluation eval = new Evaluation(dataTest); eval.evaluateModel(decisionTree, dataTest); resultValue = 100 - (eval.errorRate() * 100); } catch (Exception ex) { Logger.getLogger(WekaClassifier.class.getName()).log(Level.SEVERE, null, ex); } return resultValue; }
From source file:KFST.featureSelection.embedded.TreeBasedMethods.DecisionTreeBasedMethod.java
License:Open Source License
/** * {@inheritDoc }//w w w. ja v a 2 s . c o m */ @Override protected String buildClassifier(Instances dataTrain) { try { if (TREE_TYPE == TreeType.C45) { J48 decisionTreeC45 = new J48(); decisionTreeC45.setConfidenceFactor((float) confidenceValue); decisionTreeC45.setMinNumObj(minNumSampleInLeaf); decisionTreeC45.buildClassifier(dataTrain); return decisionTreeC45.toString(); } else if (TREE_TYPE == TreeType.RANDOM_TREE) { RandomTree decisionTreeRandomTree = new RandomTree(); decisionTreeRandomTree.setKValue(randomTreeKValue); decisionTreeRandomTree.setMaxDepth(randomTreeMaxDepth); decisionTreeRandomTree.setMinNum(randomTreeMinNum); decisionTreeRandomTree.setMinVarianceProp(randomTreeMinVarianceProp); decisionTreeRandomTree.buildClassifier(dataTrain); return decisionTreeRandomTree.toString(); } } catch (Exception ex) { Logger.getLogger(DecisionTreeBasedMethod.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:org.openml.webapplication.fantail.dc.landmarking.J48BasedLandmarker.java
License:Open Source License
public Map<String, Double> characterize(Instances data) { int numFolds = m_NumFolds; double score1 = 0.5; double score2 = 0.5; // double score3 = 0.5; double score3 = 0.5; double score4 = 0.5; // double score3 = 0.5; double score5 = 0.5; double score6 = 0.5; double score7 = 0.5; double score8 = 0.5; double score9 = 0.5; weka.classifiers.trees.J48 cls = new weka.classifiers.trees.J48(); cls.setConfidenceFactor(0.00001f); try {/*from w w w. j a va 2 s .c om*/ weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(data); eval.crossValidateModel(cls, data, numFolds, new java.util.Random(1)); score1 = eval.pctIncorrect(); score2 = eval.weightedAreaUnderROC(); score7 = eval.kappa(); } catch (Exception e) { e.printStackTrace(); } // cls = new weka.classifiers.trees.J48(); cls.setConfidenceFactor(0.0001f); try { weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(data); eval.crossValidateModel(cls, data, numFolds, new java.util.Random(1)); score3 = eval.pctIncorrect(); score4 = eval.weightedAreaUnderROC(); score8 = eval.kappa(); } catch (Exception e) { e.printStackTrace(); } // cls = new weka.classifiers.trees.J48(); cls.setConfidenceFactor(0.001f); try { weka.classifiers.Evaluation eval = new weka.classifiers.Evaluation(data); eval.crossValidateModel(cls, data, numFolds, new java.util.Random(1)); score5 = eval.pctIncorrect(); score6 = eval.weightedAreaUnderROC(); score9 = eval.kappa(); } catch (Exception e) { e.printStackTrace(); } Map<String, Double> qualities = new HashMap<String, Double>(); qualities.put(ids[0], score1); qualities.put(ids[1], score2); qualities.put(ids[2], score3); qualities.put(ids[3], score4); qualities.put(ids[4], score5); qualities.put(ids[5], score6); qualities.put(ids[6], score7); qualities.put(ids[7], score8); qualities.put(ids[8], score9); return qualities; }
From source file:uv.datamining.tp2.WekaModeler.java
public static void generarArbol(File file, float cm) throws Exception { ArffLoader loader = new ArffLoader(); loader.setFile(file);//w w w . java2 s . co m Instances data = loader.getDataSet(); data.setClassIndex(data.numAttributes() - 1); //columna con el atributo clase J48 tree = new J48(); tree.setConfidenceFactor(cm); tree.buildClassifier(data); Evaluation eval = new Evaluation(data); eval.evaluateModel(tree, data); System.out.println(eval.toSummaryString()); weka.core.SerializationHelper.write( file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(".")) + ".model", tree); }