本文整理汇总了Java中ca.pfv.spmf.algorithms.classifiers.decisiontree.id3.DecisionTree类的典型用法代码示例。如果您正苦于以下问题:Java DecisionTree类的具体用法?Java DecisionTree怎么用?Java DecisionTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DecisionTree类属于ca.pfv.spmf.algorithms.classifiers.decisiontree.id3包,在下文中一共展示了DecisionTree类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import ca.pfv.spmf.algorithms.classifiers.decisiontree.id3.DecisionTree; //导入依赖的package包/类
@Test
public void main() {
NoExceptionAssertion.assertDoesNotThrow(() -> {
// Read input file and run algorithm to create a decision tree
AlgoID3 algo = new AlgoID3();
// There is three parameters:
// - a file path
// - the "target attribute that should be used to create the decision tree
// - the separator that was used in the file to separate values (by default it is a space)
DecisionTree tree = algo.runAlgorithm("tennis.txt", "play", " ");
algo.printStatistics();
// print the decision tree:
tree.print();
// Use the decision tree to make predictions
// For example, we want to predict the class of an instance:
String[] instance = {null, "sunny", "hot", "normal", "weak"};
String prediction = tree.predictTargetAttributeValue(instance);
System.out.println("The class that is predicted is: " + prediction);
});
}
示例2: main
import ca.pfv.spmf.algorithms.classifiers.decisiontree.id3.DecisionTree; //导入依赖的package包/类
public static void main(String [] arg) throws IOException{
// Read input file and run algorithm to create a decision tree
AlgoID3 algo = new AlgoID3();
// There is three parameters:
// - a file path
// - the "target attribute that should be used to create the decision tree
// - the separator that was used in the file to separate values (by default it is a space)
DecisionTree tree = algo.runAlgorithm(fileToPath("tennis.txt"), "play", " ");
algo.printStatistics();
// print the decision tree:
tree.print();
// Use the decision tree to make predictions
// For example, we want to predict the class of an instance:
String [] instance = {null, "sunny", "hot", "normal", "weak"};
String prediction = tree.predictTargetAttributeValue(instance);
System.out.println("The class that is predicted is: " + prediction);
}