Package weka.classifiers.trees.j48

Examples of weka.classifiers.trees.j48.BinC45ModelSelection


      Instances data = source.getDataSet();
      if (data.classIndex() == -1){
        data.setClassIndex(data.numAttributes() - 1);
      }
      String[] options = weka.core.Utils.splitOptions("-p 0");
      J48 cls = (J48)weka.core.SerializationHelper.read(modelfile);
      cls.setOptions(options);
      for(int i = 0; i < data.numInstances(); i++){
        double pred = cls.classifyInstance(data.instance(i));
        ClusterClass clusClass = ClusterClass.valueOf(
            data.classAttribute().value((int)pred).toUpperCase());
        if(!retval.containsKey(clusClass)){
          retval.put(clusClass, new ArrayList<StoredDomainCluster>());
        }
View Full Code Here


        super.tearDown();
    }
   
    public void testBuildAndClassifyJ48() throws Exception
    {
        Classifier classifier = new J48();
        FastVector attributes = new FastVector();
        FastVector values = new FastVector();
        values.addElement("sunny");
        values.addElement("overcast");
        values.addElement("rain");
        attributes.addElement(new Attribute("outlook", values));
        values = new FastVector();
        values.addElement("false");
        values.addElement("true");
        attributes.addElement(new Attribute("windy", values));
        attributes.addElement(new Attribute("humidity"));
        attributes.addElement(new Attribute("temperature"));
        values = new FastVector();
        values.addElement("yes");
        values.addElement("no");
        attributes.addElement(new Attribute("play", values));
        Instances dataset = new Instances("", attributes, 15);
        dataset.add(createInstance(dataset, "sunny", "false", 85, 85, "no"));
        dataset.add(createInstance(dataset, "sunny", "true", 80, 90, "no"));
        dataset.add(createInstance(dataset, "overcast", "false", 83, 78, "yes"));
        dataset.add(createInstance(dataset, "rain", "false", 70, 96, "yes"));
        dataset.add(createInstance(dataset, "rain", "false", 68, 80, "yes"));
        dataset.add(createInstance(dataset, "rain", "true", 65, 70, "no"));
        dataset.add(createInstance(dataset, "overcast", "true", 64, 65, "yes"));
        dataset.add(createInstance(dataset, "sunny", "false", 72, 95, "no"));
        dataset.add(createInstance(dataset, "sunny", "false", 69, 70, "yes"));
        dataset.add(createInstance(dataset, "rain", "false", 75, 80, "yes"));
        dataset.add(createInstance(dataset, "sunny", "true", 75, 70, "yes"));
        dataset.add(createInstance(dataset, "overcast", "true", 72, 90, "yes"));
        dataset.add(createInstance(dataset, "overcast", "false", 81, 75, "yes"));
        dataset.add(createInstance(dataset, "rain", "true", 71, 91, "no"));
        dataset.setClassIndex(4);
        classifier.buildClassifier(dataset);
        System.out.println(classifier);
       
        double result = classifier.classifyInstance(createInstance(dataset, "sunny", "false", 85, 85, Null.getValue()));
        assertEquals(1.0, result, .1);
        result = classifier.classifyInstance(createInstance(dataset, "sunny", "true", 80, 90, Null.getValue()));
        assertEquals(1.0, result, .1);
        result = classifier.classifyInstance(createInstance(dataset, "overcast", "false", 83, 78, "yes"));
        assertEquals(0.0, result, .1);
        result = classifier.classifyInstance(createInstance(dataset, "rain", "false", 70, 96, "yes"));
        assertEquals(0.0, result, .1);
        result = classifier.classifyInstance(createInstance(dataset, "rain", "false", 68, 80, "yes"));
        assertEquals(0.0, result, .1);
    }
View Full Code Here

public class WekaClusterClassifier extends WekaClassifier{

 
  public WekaClusterClassifier(){
    super.classifier = new J48();
  }
View Full Code Here

  private String[] class_bounds;
  private double min, max;
 
  public WekaBinClassifier(){
    discretize = new Discretize();
    super.classifier = new J48();
  }
View Full Code Here

    setLayout(new GridBagLayout());
   
    m_TreeView = new JScrollPane();
    m_TreeView.setPreferredSize(new Dimension(150, 50));
   
    buildClassifierTree(new J48());
   
    ToolTipManager.sharedInstance().registerComponent(m_Tree);
   
    gbc.weightx = 1;
    gbc.weighty = 1.5;
View Full Code Here

        System.out.println("Number of samples = " + number_samples);
        System.out.println("Summary: " + summary);
        System.out.println();
       
        // a classifier for decision trees:
        J48 j48 = new J48();
       
        // filter for removing samples:
        Remove rm = new Remove();
        rm.setAttributeIndices("1")// remove 1st attribute
View Full Code Here

        String output = this.catalog_proc.getName() + "-labeled.arff";
        FileUtil.writeStringToFile(output, newData.toString());
        LOG.info("Wrote labeled data set to " + output);
       
        // Decision Tree
        J48 j48 = new J48();
        String options[] = {
            "-S", Integer.toString(this.rand.nextInt()),
           
        };
        j48.setOptions(options);

        // Make sure we add the ClusterId attribute to a new MarkovAttributeSet so that
        // we can tell the Classifier to classify that!
        FilteredClassifier fc = new FilteredClassifier();
        MarkovAttributeSet classifier_aset = new MarkovAttributeSet(aset);
View Full Code Here

      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;
View Full Code Here

      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;
View Full Code Here

     */
    @Test
    public void testSave() throws Exception {
        System.out.println("save");

        J48 classifier = new J48();
        classifier.setNumFolds(456);
        WekaModel model = new WekaModel(classifier);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        assertTrue(model.save(out));
        out.close();
        byte[] serializedStr = out.toByteArray();

        //It wrote something
        assertTrue(serializedStr.length > 0);

        //It wrote a J48 classifier
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedStr));
        try {
            J48 serialized = (J48) in.readObject();
            in.close();
            assertEquals(classifier.getNumFolds(), serialized.getNumFolds());
        } catch (ClassNotFoundException e) {
            assertTrue(e.getMessage(), false);
        } catch (IOException e) {
            assertTrue(e.getMessage(), false);
        }
View Full Code Here

TOP

Related Classes of weka.classifiers.trees.j48.BinC45ModelSelection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.