How to use a classifier from within Java

View: New views
8 Messages — Rating Filter:   Alert me  

How to use a classifier from within Java

by dbrayford :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I was wonder how I run a Bayes naive classifier on a series of text
files (*.txt). I've separated the files into training set and test set
and have the features stored as strings with an array.
However, I don't know how to set up and run the training set or test
set in Java code. I've looked at the API and am confused on what to
do. I've got all the code to process the output data but am stuck on
how to set up and run the classifier.

Any help would be appreciated as it is very frustrating, because I've
got all the data but don't know how to process the data using weka.

Thanks
David

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

Re: How to use a classifier from within Java

by Peter Reutemann-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I was wonder how I run a Bayes naive classifier on a series of text
> files (*.txt). I've separated the files into training set and test set
> and have the features stored as strings with an array.
> However, I don't know how to set up and run the training set or test
> set in Java code. I've looked at the API and am confused on what to
> do. I've got all the code to process the output data but am stuck on
> how to set up and run the classifier.
>
> Any help would be appreciated as it is very frustrating, because I've
> got all the data but don't know how to process the data using weka.

Read FAQ "How do I use WEKA's classes in my own code?". Link to the
FAQs available from the Weka homepage.

Cheers, Peter
--
Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
http://www.cs.waikato.ac.nz/~fracpete/           Ph. +64 (7) 858-5174

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

Re: How to use a classifier from within Java

by dbrayford :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

                // builds the training set
                for(int i = 0; i < outTrainingFileNames.size(); i++)
                {
                        f = new File(dir + outTrainingFileNames.elementAt(i));
                        try
                        {
// FileInputStream fis = new FileInputStream(f);
// DataInputStream dis = new DataInputStream(fis);
                                BufferedReader reader = new BufferedReader(new FileReader(f));
       
                                        while(reader.readLine() != null)
                                        {
                                                vDataTrain.addElement( reader.readLine() );
                                        }
       
                               
// dis.close();
// fis.close();
                        }
                        catch ( Exception e )
                        {
                                e.printStackTrace();
                        }
                       

                        for(int j = 0; j < vDataTrain.size(); j++)
                        {
                                DataSource source = new DataSource(vDataTrain.elementAt(i));
                                trainingData = source.getDataSet();
                                if(j != 0)
                                        source.nextElement(trainingData);
                        }
                       
                        // choose classifier
                        cModel = (Classifier)new NaiveBayes();
                        // build training set
                        cModel.buildClassifier(trainingData);
                }
                for(int i = 0; i < outTestFileNames.size(); i++)
                {
                        f = new File(dir + outTestFileNames.elementAt(i));
                        try
                        {
// FileInputStream fis = new FileInputStream(f);
// DataInputStream dis = new DataInputStream(fis);
                                BufferedReader reader = new BufferedReader(new FileReader(f));
       
                                        while(reader.readLine() != null)
                                        {
                                                vDataTest.addElement( reader.readLine() );
                                        }
       
                               
// dis.close();
// fis.close();
                        }
                        catch ( Exception e )
                        {
                                e.printStackTrace();
                        }
                       
                       

                }
               
                for(int j = 0; j < vDataTest.size(); j++)
                {
                        DataSource source = new DataSource(vDataTest.elementAt(j));
                        testData = source.getDataSet();
                        if(j != 0)
                                source.nextElement(testData);
                }
                Evaluation eTest = new Evaluation(trainingData);

                for(int j = 0; j < vDataTest.size(); j++)
                {
                        goodBad = outTestGoodBad.elementAt(j);

                        eTest.evaluateModel(cModel, testData);
                       
                        // get the summary for the evaluation model
                        String strSummary = eTest.toSummaryString();
                        System.out.println(strSummary);
}

On Tue, Aug 11, 2009 at 1:52 PM, Peter Reutemann<fracpete@...> wrote:

>> I was wonder how I run a Bayes naive classifier on a series of text
>> files (*.txt). I've separated the files into training set and test set
>> and have the features stored as strings with an array.
>> However, I don't know how to set up and run the training set or test
>> set in Java code. I've looked at the API and am confused on what to
>> do. I've got all the code to process the output data but am stuck on
>> how to set up and run the classifier.
>>
>> Any help would be appreciated as it is very frustrating, because I've
>> got all the data but don't know how to process the data using weka.
>
> Read FAQ "How do I use WEKA's classes in my own code?". Link to the
> FAQs available from the Weka homepage.
>
> Cheers, Peter
> --
> Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
> http://www.cs.waikato.ac.nz/~fracpete/           Ph. +64 (7) 858-5174
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: Wekalist@...
> List info and subscription status: https://list.scms.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 info and subscription status: https://list.scms.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

Re: How to use a classifier from within Java

by dbrayford :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Please ignore the last email. I accidentally sent a incomplete
message, due to badly performing laptop.

David

On Wed, Aug 12, 2009 at 7:10 PM, David Brayford<dbrayford@...> wrote:

>                // builds the training set
>                for(int i = 0; i < outTrainingFileNames.size(); i++)
>                {
>                        f = new File(dir + outTrainingFileNames.elementAt(i));
>                        try
>                        {
> //                              FileInputStream fis = new FileInputStream(f);
> //                              DataInputStream dis = new DataInputStream(fis);
>                                BufferedReader reader = new BufferedReader(new FileReader(f));
>
>                                        while(reader.readLine() != null)
>                                        {
>                                                vDataTrain.addElement( reader.readLine() );
>                                        }
>
>
> //                              dis.close();
> //                              fis.close();
>                        }
>                        catch ( Exception e )
>                        {
>                                e.printStackTrace();
>                        }
>
>
>                        for(int j = 0; j < vDataTrain.size(); j++)
>                        {
>                                DataSource source = new DataSource(vDataTrain.elementAt(i));
>                                trainingData = source.getDataSet();
>                                if(j != 0)
>                                        source.nextElement(trainingData);
>                        }
>
>                        // choose classifier
>                        cModel = (Classifier)new NaiveBayes();
>                        // build training set
>                        cModel.buildClassifier(trainingData);
>                }
>                for(int i = 0; i < outTestFileNames.size(); i++)
>                {
>                        f = new File(dir + outTestFileNames.elementAt(i));
>                        try
>                        {
> //                              FileInputStream fis = new FileInputStream(f);
> //                              DataInputStream dis = new DataInputStream(fis);
>                                BufferedReader reader = new BufferedReader(new FileReader(f));
>
>                                        while(reader.readLine() != null)
>                                        {
>                                                vDataTest.addElement( reader.readLine() );
>                                        }
>
>
> //                              dis.close();
> //                              fis.close();
>                        }
>                        catch ( Exception e )
>                        {
>                                e.printStackTrace();
>                        }
>
>
>
>                }
>
>                for(int j = 0; j < vDataTest.size(); j++)
>                {
>                        DataSource source = new DataSource(vDataTest.elementAt(j));
>                        testData = source.getDataSet();
>                        if(j != 0)
>                                source.nextElement(testData);
>                }
>                Evaluation eTest = new Evaluation(trainingData);
>
>                for(int j = 0; j < vDataTest.size(); j++)
>                {
>                        goodBad = outTestGoodBad.elementAt(j);
>
>                        eTest.evaluateModel(cModel, testData);
>
>                        // get the summary for the evaluation model
>                        String strSummary = eTest.toSummaryString();
>                        System.out.println(strSummary);
> }
>
> On Tue, Aug 11, 2009 at 1:52 PM, Peter Reutemann<fracpete@...> wrote:
>>> I was wonder how I run a Bayes naive classifier on a series of text
>>> files (*.txt). I've separated the files into training set and test set
>>> and have the features stored as strings with an array.
>>> However, I don't know how to set up and run the training set or test
>>> set in Java code. I've looked at the API and am confused on what to
>>> do. I've got all the code to process the output data but am stuck on
>>> how to set up and run the classifier.
>>>
>>> Any help would be appreciated as it is very frustrating, because I've
>>> got all the data but don't know how to process the data using weka.
>>
>> Read FAQ "How do I use WEKA's classes in my own code?". Link to the
>> FAQs available from the Weka homepage.
>>
>> Cheers, Peter
>> --
>> Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
>> http://www.cs.waikato.ac.nz/~fracpete/           Ph. +64 (7) 858-5174
>>
>> _______________________________________________
>> Wekalist mailing list
>> Send posts to: Wekalist@...
>> List info and subscription status: https://list.scms.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 info and subscription status: https://list.scms.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

Re: How to use a classifier from within Java

by Peter Reutemann-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Please ignore the last email. I accidentally sent a incomplete
> message, due to badly performing laptop.

And please don't top-post!

Cheers, Peter
--
Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
http://www.cs.waikato.ac.nz/~fracpete/           Ph. +64 (7) 858-5174

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

structure of Bayesian network

by tgh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
        I use weka and use TAN, I have two sets of data, and I use TAN
algorithm, and get two trained classifiers , C1 for data set1, and C2
for data set2 ,and  C1 and C2 have quite different structures of network
in the trained classifier,
        And I save the two XML BIF files for C1 and C2, test1.xml for C1
and test2.xml for C2, and then  I use data set2 with the before XML BIF
file, test1.xml which is got from C1, to train a new classifier,C3
        I expect that the structure of trained classifier C3 is as the
test1.xml for C1, but it seems that the new classifier C3 is exactly the
same as C2, that is ,the structure of C3 is quite different from C1, but
it is the same as C2,
 
        If I want to make the structure of C3 follow the XML BIF file of
C1, how to do it with weka explorer, or what to do

Could you help me
Thanks



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

question about FromFile search algorithm in weka

by tgh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
        I use weka and use Bayesian network, I have two sets of data,
and I use TAN algorithm, and get two trained classifiers , C1 for data
set1, and C2 for data set2 ,and  C1 and C2 have quite different
structures of network in the trained classifier,
        And I save the two XML BIF files for C1 and C2, test1.xml for C1
and test2.xml for C2, and then I want to use data set2 with the before
XML BIF file, test1.xml which is got from C1, to train a new
classifier,C3

        I set BIFFile and choose FromFile search algorithm and I click
the start run button, and ERROR arise, and does not run,
-----------------------------
Error information
        Problem evaluating classifier:
        Content is not allowed in prolog
-----------------------------

then I try to use dataset2 with XMLBIF file test2.xml, which is got from
C2, that is , got from dataset2, but the same ERROR arise,

what should I do to use XMLBIF file and FromFile search algorithm in
weka
how to use this in weka explore,
Could you help me
Thanks






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

Re: question about FromFile search algorithm in weka

by Peter Reutemann-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>        I use weka and use Bayesian network, I have two sets of data,
> and I use TAN algorithm, and get two trained classifiers , C1 for data
> set1, and C2 for data set2 ,and  C1 and C2 have quite different
> structures of network in the trained classifier,
>        And I save the two XML BIF files for C1 and C2, test1.xml for C1
> and test2.xml for C2, and then I want to use data set2 with the before
> XML BIF file, test1.xml which is got from C1, to train a new
> classifier,C3
>
>        I set BIFFile and choose FromFile search algorithm and I click
> the start run button, and ERROR arise, and does not run,
> -----------------------------
> Error information
>        Problem evaluating classifier:
>        Content is not allowed in prolog
> -----------------------------
>
> then I try to use dataset2 with XMLBIF file test2.xml, which is got from
> C2, that is , got from dataset2, but the same ERROR arise,
>
> what should I do to use XMLBIF file and FromFile search algorithm in
> weka
> how to use this in weka explore,

Searching the archives of the wekalist a bit ("fromfile prolog") and
you would have come across the error and what you're doing wrong:
  https://list.scms.waikato.ac.nz/mailman/htdig/wekalist/2008-December/015511.html

Cheers, Peter
--
Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
http://www.cs.waikato.ac.nz/~fracpete/           Ph. +64 (7) 858-5174

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