question abt the WEKA LVQ.......

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

question abt the WEKA LVQ.......

SUFIYAN WARRAICH
 have to make a java Application in which i m trying to use OLVQ1 Classes....
i can easily use the Cross Validation Model for the class.... but
when i try to use 2 datasets one for training and other for testing...
the code doesnt work but just entering the names of the data sets....
Sir i m trying to work with the following code....



import java.util.Collection;
import weka.classifiers.evaluation.*;
import weka.classifiers.Evaluation;
import weka.classifiers.neural.lvq.algorithm.Lvq1Algorithm;
import weka.classifiers.neural.common.learning.LearningKernelFactory;
import weka.classifiers.neural.common.learning.LearningRateKernel;
import weka.classifiers.neural.lvq.initialise.InitialisationFactory;
import weka.core.SelectedTag;
import weka.classifiers.neural.lvq.Olvq1;
import weka.core.Instances;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedWriter;
import weka.experiment.CrossValidationResultProducer;
import weka.gui.beans.DataVisualizer;

public class LVQTest{

public LVQTest(){

      try{




      // load the dataset for the training and then carry out the testing...

      Instances dataset = new Instances(new FileReader("weather.arff"));

//      Instances dataset1 = new Instances(new FileReader("weatherer.arff"));

      dataset.setClassIndex(dataset.numAttributes()-1);
//      dataset1.setClassIndex(dataset.numAttributes()-1);

      // prepare the algorithm for the optamized Learning Vector
Quantization...

      Olvq1 algorithm = new Olvq1();

      SelectedTag init = new
SelectedTag(InitialisationFactory.INITALISE_TRAINING_EVEN,

      InitialisationFactory.TAGS_MODEL_INITALISATION);

      algorithm.setInitialisationMode(init);

      SelectedTag lfunc = new
SelectedTag(LearningKernelFactory.LEARNING_FUNCTION_LINEAR,

      LearningKernelFactory.TAGS_LEARNING_FUNCTION);

      algorithm.setLearningFunction(lfunc);

      algorithm.setSeed(123);

      algorithm.setTotalCodebookVectors(50);

      algorithm.setTotalTrainingIterations(5000);

      algorithm.setUseVoting(false);
      // train and test the model (10 fold cross validation)  so that we
can have the idea...


      Evaluation evaluation = new Evaluation(dataset);

      //////////////////////********



      CrossValidationResultProducer cvrp= new CrossValidationResultProducer();

      DataVisualizer dv=new DataVisualizer();




      System.out.println("Traing the Data.....");

      evaluation.crossValidateModel(algorithm, dataset, 5, new
java.util.Random(algorithm.getSeed()));

//      System.out.println("Testing the Data.....");

//      evaluation.crossValidateModel(algorithm, dataset1, 5, new
java.util.Random(algorithm.getSeed()));


      EvaluationUtils  ut =  new EvaluationUtils();
//      Prediction p = ut.getPrediction(algorithm,dataset);
      // write out stats

      ///***** POLICE LINE DO NOT CROSS*****//////***** POLICE LINE DO NOT
CROSS*****///
      ///***** POLICE LINE DO NOT CROSS*****//////***** POLICE LINE DO NOT
CROSS*****///

      System.out.println("Golbal Information of The LVQ");
      System.out.println(algorithm.globalInfo());
      System.out.println("Summary for Evaluation");
      System.out.println(evaluation.toSummaryString());
      System.out.println("Number of Instances");
      System.out.println(evaluation.numInstances());
      System.out.println("Precision For Evaluation");
      System.out.println(evaluation.precision(0));
      System.out.println("Correct Evaluation");
      System.out.println(evaluation.correct());
      System.out.println("InCorrect Evaluation");
      System.out.println(evaluation.incorrect());
      System.out.println("Detailed Class String");
      System.out.println(evaluation.toClassDetailsString());
      System.out.println("Error Rate");
      System.out.println(evaluation.errorRate());
//      System.out.println(evaluation.evaluateModelOnce(algorithm,dataset));
      System.out.println("Cumulative Margin Distribution String");
      System.out.println(evaluation.toCumulativeMarginDistributionString());
      System.out.println("Matrix String");
      System.out.println(evaluation.toMatrixString());
      System.out.println(dataset.sumOfWeights());
      System.out.println("Learning Rate");
      System.out.println(algorithm.getLearningRate());
      System.out.println("Get total Code Book Vector");
      System.out.println(algorithm.getTotalCodebookVectors());


//      System.out.println(cvrp.getResultNames());
//      System.out.println(dv);
//      System.out.println(algorithm.getTrainingBmuUsage());
      System.out.println("Training Iterations
"+algorithm.getTotalTrainingIterations());




      ///***** POLICE LINE DO NOT CROSS*****//////***** POLICE LINE DO NOT
CROSS*****///
      ///***** POLICE LINE DO NOT CROSS*****//////***** POLICE LINE DO NOT
CROSS*****///


      BufferedWriter out = new BufferedWriter(new
FileWriter("C:\\labor.txt",true));
                      out.write(algorithm.globalInfo());
                      out.write("\n");
                      out.write(evaluation.toSummaryString());
              out.write(evaluation.toMatrixString());
              out.close();
 // Exception Handling for the Errors that Occur....
}catch (Exception e){
      e.printStackTrace();
}

}

//The Main Program for the Execution of the LVQ....

public static void main(String args[]){
      LVQTest tst = new LVQTest();
}

}


 when i try to train on one set and test on other it does work
out.... i will be grateful if someone tell me some way to get it done or
send some reference code document to carry this out....
in which i can train the model on one dataset and train it on
other...... as it gives me the error..... "model was not
prepared"..... and exit.....


Thankyou Very Much


--
Regards,
Sufiyan Warraich
NUST Institute of Information Technology
Rawalpindi
Pakistan
0321-5186069

_______________________________________________
Wekalist mailing list
[hidden email]
https://list.scms.waikato.ac.nz/mailman/listinfo/wekalist
Reply | Threaded
Open this post in threaded view
|

Re: question abt the WEKA LVQ.......

Peter Reutemann
>  have to make a java Application in which i m trying to use OLVQ1 Classes....
> i can easily use the Cross Validation Model for the class.... but
> when i try to use 2 datasets one for training and other for testing...

I'm not sure whether I understood you correctly... Crossvalidation is
used if there's only one dataset available. You use 5-fold
crossvalidation in your code, which divides the dataset into 5 parts and
uses 4 of them to train and 1 to test (and this process is done 5
times). If you now want to run it with a training and a test file, you
cannot use crossvalidation. Take a look at the following method of the
weka.classifiers.Evaluation class:
   public static String evaluateModel(
        Classifier classifier, String [] options)

And there check out what happens to the -T option (which defines a test
file on the command line), especially the variables "testFileName" and
"testReader". Instead of calling the "crossValidateModel(...)", the
following method is used:
   public double evaluateModelOnce(
        Classifier classifier, Instance instance)

HTH

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

_______________________________________________
Wekalist mailing list
[hidden email]
https://list.scms.waikato.ac.nz/mailman/listinfo/wekalist