I ran it using the Iris data and it worked, just like it did when you ran the glass dataset. That is why i don't understand why i am getting the strange results even when using the same dataset for the stock data. This is what the confusion matrix looks like when I do the training. Let me know if this indicates a problem. Thanks.

=== Confusion Matrix ===

    a    b    c    d   <-- classified as
 7021   27   15    8 |    a = NoBuy
  691   13   12    8 |    b = StrongBuy
  695   17    7    3 |    c = StrongNoBuy
  758   12    6    3 |    d = Buy


On Thu, Mar 10, 2016 at 2:23 PM, Eibe Frank <eibe@waikato.ac.nz> wrote:
Your code works fine and gives the same results as WEKA’s other UIs. Appended below is a version of your code that I ran in the GroovyConsole for WEKA (using the glass data for both training and testing). It spits out


Total Instances: 214
Found count: 187

And this is the confusion matrix I get when I run the same experiment using WEKA’s UIs:

...
=== Confusion Matrix ===

  a  b  c  d  e  f  g   <-- classified as
 68  1  0  0  0  0  1 |  a = build wind float
  1 74  1  0  0  0  0 |  b = build wind non-float
  0  0 17  0  0  0  0 |  c = vehic wind float
  0  0  0  0  0  0  0 |  d = vehic wind non-float
  0  1  0  0 12  0  0 |  e = containers
  0  0  0  0  0  9  0 |  f = tableware
  0  2  0  0  1  0 26 |  g = headlamps

As you can see, 27 instances are classified as “headlamps”, which gives 214-27=187 other predictions, the same as what your code outputs.

Cheers,
Eibe

import weka.core.converters.ConverterUtils.DataSource
import weka.core.Instance
import weka.core.Instances
import weka.core.Attribute
import weka.classifiers.Classifier
import weka.classifiers.trees.J48

        String filePath = "/Users/eibe/datasets/UCI/glass.arff";
        DataSource source = new DataSource(filePath);
        Instances data = source.getDataSet();
        data.setClassIndex(data.numAttributes() - 1);
        Classifier cModel = (Classifier)new J48();
        cModel.buildClassifier(data);

        String predictFilePath = "/Users/eibe/datasets/UCI/glass.arff";
        source = new DataSource(filePath);
        Instances useData = source.getDataSet();
        useData.setClassIndex(useData.numAttributes() - 1);

        int foundInstanceCount= 0;

        for(int n=0;n<useData.numInstances();n++)
        {
            Instance iUse = useData.instance(n);
            double[] fDistribution = cModel.distributionForInstance(iUse);

            Attribute att = iUse.classAttribute();

            int index = 0;
            double max = 0;

            for(int i=0;i<fDistribution.length;i++)
            {
                double dist = fDistribution[i];

                if(dist > max)
                {
                    index = i;
                    max = dist;
                }
            }

            String action = att.value(index);

            if(action.compareToIgnoreCase("headlamps") != 0)
            {
                foundInstanceCount++;
                System.out.println(action);
            }
        }

        System.out.println("Total Instances: " + useData.numInstances());

        if(foundInstanceCount == 0)
            System.out.println("No matches found");
        else
            System.out.println("Found count: " + foundInstanceCount);

> On 10/03/2016, at 2:57 AM, Jerry Thorpe <jerryjthorpe@gmail.com> wrote:
>
> Hi Eibe,
>
> Here's the code, thanks
>
> private static void StockBotModel() throws Exception
>       {
>               String filePath = "C:\\Users\\Thorpe\\Documents\\StockDataWEKAFiltered.csv";
>               DataSource source = new DataSource(filePath);
>               Instances data = source.getDataSet();
>               data.setClassIndex(data.numAttributes() - 1);
>               Classifier cModel = (Classifier)new J48();
>       //      Classifier cModel = (Classifier)new MultilayerPerceptron();
>               cModel.buildClassifier(data);
>
>       //      String predictFilePath = "C:\\Users\\Thorpe\\Documents\\WekaUseData.csv";
>               source = new DataSource(filePath);
>               Instances useData = source.getDataSet();
>               useData.setClassIndex(useData.numAttributes() - 1);
>
>               int foundInstanceCount= 0;
>
>               for(int n=0;n<useData.numInstances();n++)
>               {
>                       Instance iUse = useData.instance(n);
>                       iUse.setDataset(data);
>                       double[] fDistribution = cModel.distributionForInstance(iUse);
>
>                       Attribute att = iUse.classAttribute();
>
>                       int index = 0;
>                       double max = 0;
>
>                       for(int i=0;i<fDistribution.length;i++)
>                       {
>                               double dist = fDistribution[i];
>
>                               if(dist > max)
>                               {
>                                       index = i;
>                                       max = dist;
>                               }
>                       }
>
>                       String action = att.value(index);
>
>                       if(action.compareToIgnoreCase("NoBuy") != 0)
>                       {
>                               foundInstanceCount++;
>                               System.out.println(action);
>                       }
>               }
>
>               System.out.println("Total Instances: " + useData.numInstances());
>
>               if(foundInstanceCount == 0)
>                       System.out.println("No matches found");
>               else
>                       System.out.println("Found count: " + foundInstanceCount);
>       }
>
> On Tue, Mar 8, 2016 at 11:32 PM, Eibe Frank <eibe@waikato.ac.nz> wrote:
> You need to call distributionForInstance() for every instance in the dataset you use for evaluation, and check whether the class that receives maximum probability is the correct class for that instance.
>
> Maybe you should send the code you use to compute the percentage of correct classifications.
>
> Cheers,
> Eibe
>
> > On 9 Mar 2016, at 10:29, Jerry Thorpe <jerryjthorpe@gmail.com> wrote:
> >
> > Hi Eibe,
> >
> > So should I be checking something besides the distribution? To be sure of my results I ran a training set using the buildClassifier (data) call then distributionForInstance to use the model. From what you are saying I must be doing something wrong. Do you know where their is some sample code that I can check out?
> >
> > Thanks,
> > Jerry
> >
> > On Mar 8, 2016 12:42 PM, "Eibe Frank" <eibe@waikato.ac.nz> wrote:
> > Yes, you should get the same result, regardless of whether you use the API or one of WEKA’s user interfaces, as long as the training and test sets are the same.
> >
> > Cheers,
> > Eibe
> >
> > > On 9/03/2016, at 2:51 AM, Jerry Thorpe <jerryjthorpe@gmail.com> wrote:
> > >
> > > I am using J48 on a data set with 9,000 records. During the training I get a 75% correct rate but when i use the same data in my Java code the distribution rate only finds 120 out of the 9,000 which is about 1.3%.Shouldn't the values match since the data set is the same?
> > >
> > > Thanks
> > > _______________________________________________
> > > Wekalist mailing list
> > > Send posts to: Wekalist@list.waikato.ac.nz
> > > List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> > > List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
> >
> > _______________________________________________
> > Wekalist mailing list
> > Send posts to: Wekalist@list.waikato.ac.nz
> > List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> > List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
> > _______________________________________________
> > Wekalist mailing list
> > Send posts to: Wekalist@list.waikato.ac.nz
> > List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> > List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: Wekalist@list.waikato.ac.nz
> List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: Wekalist@list.waikato.ac.nz
> List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: Wekalist@list.waikato.ac.nz
List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html