weka.classifiers.trees.J48类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中weka.classifiers.trees.J48类的一些代码示例,展示了J48类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。J48类的具体详情如下:
包路径:weka.classifiers.trees.J48
类名称:J48

J48介绍

[英]Class for generating a pruned or unpruned C4.5 decision tree. For more information, see

Ross Quinlan (1993). C4.5: Programs for Machine Learning. Morgan Kaufmann Publishers, San Mateo, CA.

BibTeX:

@book{Quinlan1993, 
address = {San Mateo, CA}, 
author = {Ross Quinlan}, 
publisher = {Morgan Kaufmann Publishers}, 
title = {C4.5: Programs for Machine Learning}, 
year = {1993} 
}

Valid options are:

-U 
Use unpruned tree.
-O 
Do not collapse tree.
-C <pruning confidence> 
Set confidence threshold for pruning. 
(default 0.25)
-M <minimum number of instances> 
Set minimum number of instances per leaf. 
(default 2)
-R 
Use reduced error pruning.
-N <number of folds> 
Set number of folds for reduced error 
pruning. One fold is used as pruning set. 
(default 3)
-B 
Use binary splits only.
-S 
Don't perform subtree raising.
-L 
Do not clean up after the tree has been built.
-A 
Laplace smoothing for predicted probabilities.
-J 
Do not use MDL correction for info gain on numeric attributes.
-Q <seed> 
Seed for random data shuffling (default 1).
-doNotMakeSplitPointActualValue 
Do not make split point actual value.

[中]类,用于生成修剪或未修剪的C4。5决策树。有关详细信息,请参阅
罗斯·昆兰(1993年)。补体第四成份。5:机器学习程序。摩根·考夫曼出版社,加利福尼亚州圣马特奥。
BibTeX:

@book{Quinlan1993, 
address = {San Mateo, CA}, 
author = {Ross Quinlan}, 
publisher = {Morgan Kaufmann Publishers}, 
title = {C4.5: Programs for Machine Learning}, 
year = {1993} 
}

有效选项包括:

-U 
Use unpruned tree.
-O 
Do not collapse tree.
-C <pruning confidence> 
Set confidence threshold for pruning. 
(default 0.25)
-M <minimum number of instances> 
Set minimum number of instances per leaf. 
(default 2)
-R 
Use reduced error pruning.
-N <number of folds> 
Set number of folds for reduced error 
pruning. One fold is used as pruning set. 
(default 3)
-B 
Use binary splits only.
-S 
Don't perform subtree raising.
-L 
Do not clean up after the tree has been built.
-A 
Laplace smoothing for predicted probabilities.
-J 
Do not use MDL correction for info gain on numeric attributes.
-Q <seed> 
Seed for random data shuffling (default 1).
-doNotMakeSplitPointActualValue 
Do not make split point actual value.

代码示例

代码示例来源:origin: stackoverflow.com

J48 model=new J48(); 
model.buildClassifier(test);

代码示例来源:origin: stackoverflow.com

J48 j48 = new J48();
j48.buildClassifier(train);
weka.core.SerializationHelper.write("/some/where/j48.model", j48);

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns the value of the named measure
 * 
 * @param additionalMeasureName the name of the measure to query for its value
 * @return the value of the named measure
 * @throws IllegalArgumentException if the named measure is not supported
 */
@Override
public double getMeasure(String additionalMeasureName) {
 if (additionalMeasureName.compareToIgnoreCase("measureNumRules") == 0) {
  return measureNumRules();
 } else if (additionalMeasureName.compareToIgnoreCase("measureTreeSize") == 0) {
  return measureTreeSize();
 } else if (additionalMeasureName.compareToIgnoreCase("measureNumLeaves") == 0) {
  return measureNumLeaves();
 } else {
  throw new IllegalArgumentException(additionalMeasureName
   + " not supported (j48)");
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
  * Main method for testing this class
  * 
  * @param argv the commandline options
  */
 public static void main(String[] argv) {
  runClassifier(new J48(), argv);
 }
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.ml-asl

public static Classifier getClassifier(WekaClassifier classifier)
  throws IllegalArgumentException
{
  try {
    switch (classifier)
    {
      case NAIVE_BAYES:
        return new NaiveBayes();
      case J48:
        J48 j48 = new J48();			
        j48.setOptions(new String[] { "-C", "0.25", "-M", "2" });
        return j48;
      case SMO:
        SMO smo = new SMO();
        smo.setOptions(Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
        return smo;
      case LOGISTIC:
        Logistic logistic = new Logistic();
        logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1"));
        return logistic;
      default:
        throw new IllegalArgumentException("Classifier " + classifier + " not found!");
    }
  }
  catch (Exception e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: stackoverflow.com

J48 tree = new J48();
tree.buildClassifier(dataset);
tree.toSource(testt);
System.out.println(tree.toString());

代码示例来源:origin: stackoverflow.com

J48 j48 = new J48();
j48.setUnpruned(true);        // using an unpruned J48
j48.buildClassifier(train);
System.out.print(j48.graph());

代码示例来源:origin: com.github.fracpete/multisearch-weka-package

public void testListParameterFlag() throws Exception {
  ListParameter listparameter = new ListParameter();
  String options = "-list \"true false\" -property \"unpruned\"";
  listparameter.setOptions(Utils.splitOptions(options));
  Vector<Performance> results = searchValuesAll(listparameter, new J48());
  
  Map<Boolean, Boolean> expectedValues = new HashMap<Boolean, Boolean>();
  for (Performance result : results) {
   J48 current = (J48) result.m_Classifier;
   expectedValues.put(current.getUnpruned(), true);
  }
  verifyExpectedValues(expectedValues, 2);
  assertEquals(expectedValues.size(), 2);
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Builds the classifier to generate a partition.
 */
@Override
public void generatePartition(Instances data) throws Exception {
 buildClassifier(data);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns a string describing classifier
 * 
 * @return a description suitable for displaying in the explorer/experimenter
 *         gui
 */
public String globalInfo() {
 return "Class for generating a pruned or unpruned C4.5 decision tree. For more "
  + "information, see\n\n" + getTechnicalInformation().toString();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

public void buildClassifier(Instances instances) throws Exception {
 getCapabilities().testWithFail(instances);

代码示例来源:origin: org.dkpro.similarity/dkpro-similarity-algorithms-ml-gpl

public static Classifier getClassifier(WekaClassifier classifier)
  throws IllegalArgumentException
{
  try {
    switch (classifier)
    {
      case NAIVE_BAYES:
        return new NaiveBayes();
      case J48:
        J48 j48 = new J48();			
        j48.setOptions(new String[] { "-C", "0.25", "-M", "2" });
        return j48;
      case SMO:
        SMO smo = new SMO();
        smo.setOptions(Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
        return smo;
      case LOGISTIC:
        Logistic logistic = new Logistic();
        logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1"));
        return logistic;
      default:
        throw new IllegalArgumentException("Classifier " + classifier + " not found!");
    }
  }
  catch (Exception e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: Waikato/weka-trunk

/**
  * Main method for testing this class
  * 
  * @param argv the commandline options
  */
 public static void main(String[] argv) {
  runClassifier(new J48(), argv);
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Builds the classifier to generate a partition.
 */
@Override
public void generatePartition(Instances data) throws Exception {
 buildClassifier(data);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Returns a string describing classifier
 * 
 * @return a description suitable for displaying in the explorer/experimenter
 *         gui
 */
public String globalInfo() {
 return "Class for generating a pruned or unpruned C4.5 decision tree. For more "
  + "information, see\n\n" + getTechnicalInformation().toString();
}

代码示例来源:origin: Waikato/weka-trunk

public void buildClassifier(Instances instances) throws Exception {
 getCapabilities().testWithFail(instances);

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Default constructor.
 */
public RegressionByDiscretization() {
 m_Classifier = new weka.classifiers.trees.J48();
}

代码示例来源:origin: dkpro/dkpro-similarity

public static Classifier getClassifier(WekaClassifier classifier)
  throws IllegalArgumentException
{
  try {
    switch (classifier)
    {
      case NAIVE_BAYES:
        return new NaiveBayes();
      case J48:
        J48 j48 = new J48();			
        j48.setOptions(new String[] { "-C", "0.25", "-M", "2" });
        return j48;
      case SMO:
        SMO smo = new SMO();
        smo.setOptions(Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\""));
        return smo;
      case LOGISTIC:
        Logistic logistic = new Logistic();
        logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1"));
        return logistic;
      default:
        throw new IllegalArgumentException("Classifier " + classifier + " not found!");
    }
  }
  catch (Exception e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Returns the value of the named measure
 * 
 * @param additionalMeasureName the name of the measure to query for its value
 * @return the value of the named measure
 * @throws IllegalArgumentException if the named measure is not supported
 */
@Override
public double getMeasure(String additionalMeasureName) {
 if (additionalMeasureName.compareToIgnoreCase("measureNumRules") == 0) {
  return measureNumRules();
 } else if (additionalMeasureName.compareToIgnoreCase("measureTreeSize") == 0) {
  return measureTreeSize();
 } else if (additionalMeasureName.compareToIgnoreCase("measureNumLeaves") == 0) {
  return measureNumLeaves();
 } else {
  throw new IllegalArgumentException(additionalMeasureName
   + " not supported (j48)");
 }
}

代码示例来源:origin: stackoverflow.com

//Learning
DataSource source = new DataSource(Path);
Instances data = source.getDataSet();
J48 tree = tree.buildClassifier(data);

//Evaluation
Evaluation eval = new Evaluation(data);
eval.evaluateModel(tree, data);
System.out.println((eval.correct()/data.numInstances())*100);

相关文章