Package weka.core

Examples of weka.core.SingleIndex


    int      folds;
    String     tmpStr;
    boolean    compute;
    Instances     result;
    String[]     options;
    SingleIndex    classIndex;
    SingleIndex    valueIndex;
    int      seed;
   
    inst       = null;
    classifier = null;
    runs       = 2;
    folds      = 10;
    compute    = true;
    result     = null;
    classIndex = null;
    valueIndex = null;
    seed       = 1;
   
    try {
      // help?
      if (Utils.getFlag('h', args)) {
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_First") + ThresholdVisualizePanel.class.getName() + Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Second"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Third"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Fourth"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Fifth"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Sixth"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Seventh"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Eighth"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Nineth"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Tenth"));
  System.out.println(Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Eleventh"));
  return;
      }
     
      // regular options
      tmpStr = Utils.getOption('l', args);
      if (tmpStr.length() != 0) {
  result = new Instances(new BufferedReader(new FileReader(tmpStr)));
  compute = false;
      }
     
      if (compute) {
  tmpStr = Utils.getOption('r', args);
  if (tmpStr.length() != 0)
    runs = Integer.parseInt(tmpStr);
  else
    runs = 1;
 
  tmpStr = Utils.getOption('x', args);
  if (tmpStr.length() != 0)
    folds = Integer.parseInt(tmpStr);
  else
    folds = 10;
 
  tmpStr = Utils.getOption('S', args);
  if (tmpStr.length() != 0)
    seed = Integer.parseInt(tmpStr);
  else
    seed = 1;
 
  tmpStr = Utils.getOption('t', args);
  if (tmpStr.length() != 0) {
    inst = new Instances(new BufferedReader(new FileReader(tmpStr)));
    inst.setClassIndex(inst.numAttributes() - 1);
  }
 
  tmpStr = Utils.getOption('W', args);
  if (tmpStr.length() != 0) {
    options = Utils.partitionOptions(args);
  }
  else {
    tmpStr = weka.classifiers.functions.Logistic.class.getName();
    options = new String[0];
  }
  classifier = Classifier.forName(tmpStr, options);
 
  tmpStr = Utils.getOption('c', args);
  if (tmpStr.length() != 0)
    classIndex = new SingleIndex(tmpStr);
  else
    classIndex = new SingleIndex("last");
 
  tmpStr = Utils.getOption('C', args);
  if (tmpStr.length() != 0)
    valueIndex = new SingleIndex(tmpStr);
  else
    valueIndex = new SingleIndex("first");
      }
     
      // compute if necessary
      if (compute) {
  if (classIndex != null) {
    classIndex.setUpper(inst.numAttributes() - 1);
    inst.setClassIndex(classIndex.getIndex());
  }
  else {
    inst.setClassIndex(inst.numAttributes() - 1);
  }
 
  if (valueIndex != null) {
    valueIndex.setUpper(inst.classAttribute().numValues() - 1);
  }
 
  ThresholdCurve tc = new ThresholdCurve();
  EvaluationUtils eu = new EvaluationUtils();
  FastVector predictions = new FastVector();
  for (int i = 0; i < runs; i++) {
    eu.setSeed(seed + i);
    predictions.appendElements(eu.getCVPredictions(classifier, inst, folds));
  }
 
  if (valueIndex != null)
    result = tc.getCurve(predictions, valueIndex.getIndex());
  else
    result = tc.getCurve(predictions);
      }
     
      // setup GUI
      ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
      vmc.setROCString(Messages.getInstance().getString("ThresholdVisualizePanel_OpenVisibleInstances_Text_Third") +
    Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + Messages.getInstance().getString("ThresholdVisualizePanel_OpenVisibleInstances_Text_Fourth"));
      if (compute)    
  vmc.setName(
      result.relationName()
      + Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Twelveth") + inst.classAttribute().value(valueIndex.getIndex()) + Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Thirteenth"));
      else
  vmc.setName(
      result.relationName()
      + Messages.getInstance().getString("ThresholdVisualizePanel_Main_Text_Fourteenth"));
      PlotData2D tempd = new PlotData2D(result);
View Full Code Here


    int      folds;
    String     tmpStr;
    boolean    compute;
    Instances     result;
    String[]     options;
    SingleIndex    classIndex;
    SingleIndex    valueIndex;
    int      seed;
   
    inst       = null;
    classifier = null;
    runs       = 2;
    folds      = 10;
    compute    = true;
    result     = null;
    classIndex = null;
    valueIndex = null;
    seed       = 1;
   
    try {
      // help?
      if (Utils.getFlag('h', args)) {
  System.out.println("\nOptions for " + ThresholdVisualizePanel.class.getName() + ":\n");
  System.out.println("-h\n\tThis help.");
  System.out.println("-t <file>\n\tDataset to process with given classifier.");
  System.out.println("-c <num>\n\tThe class index. first and last are valid, too (default: last).");
  System.out.println("-C <num>\n\tThe index of the class value to get the the curve for (default: first).");
  System.out.println("-W <classname>\n\tFull classname of classifier to run.\n\tOptions after '--' are passed to the classifier.\n\t(default: weka.classifiers.functions.Logistic)");
  System.out.println("-r <number>\n\tThe number of runs to perform (default: 1).");
  System.out.println("-x <number>\n\tThe number of Cross-validation folds (default: 10).");
  System.out.println("-S <number>\n\tThe seed value for randomizing the data (default: 1).");
  System.out.println("-l <file>\n\tPreviously saved threshold curve ARFF file.");
  return;
      }
     
      // regular options
      tmpStr = Utils.getOption('l', args);
      if (tmpStr.length() != 0) {
  result = new Instances(new BufferedReader(new FileReader(tmpStr)));
  compute = false;
      }
     
      if (compute) {
  tmpStr = Utils.getOption('r', args);
  if (tmpStr.length() != 0)
    runs = Integer.parseInt(tmpStr);
  else
    runs = 1;
 
  tmpStr = Utils.getOption('x', args);
  if (tmpStr.length() != 0)
    folds = Integer.parseInt(tmpStr);
  else
    folds = 10;
 
  tmpStr = Utils.getOption('S', args);
  if (tmpStr.length() != 0)
    seed = Integer.parseInt(tmpStr);
  else
    seed = 1;
 
  tmpStr = Utils.getOption('t', args);
  if (tmpStr.length() != 0) {
    inst = new Instances(new BufferedReader(new FileReader(tmpStr)));
    inst.setClassIndex(inst.numAttributes() - 1);
  }
 
  tmpStr = Utils.getOption('W', args);
  if (tmpStr.length() != 0) {
    options = Utils.partitionOptions(args);
  }
  else {
    tmpStr = weka.classifiers.functions.Logistic.class.getName();
    options = new String[0];
  }
  classifier = Classifier.forName(tmpStr, options);
 
  tmpStr = Utils.getOption('c', args);
  if (tmpStr.length() != 0)
    classIndex = new SingleIndex(tmpStr);
  else
    classIndex = new SingleIndex("last");
 
  tmpStr = Utils.getOption('C', args);
  if (tmpStr.length() != 0)
    valueIndex = new SingleIndex(tmpStr);
  else
    valueIndex = new SingleIndex("first");
      }
     
      // compute if necessary
      if (compute) {
  if (classIndex != null) {
    classIndex.setUpper(inst.numAttributes() - 1);
    inst.setClassIndex(classIndex.getIndex());
  }
  else {
    inst.setClassIndex(inst.numAttributes() - 1);
  }
 
  if (valueIndex != null) {
    valueIndex.setUpper(inst.classAttribute().numValues() - 1);
  }
 
  ThresholdCurve tc = new ThresholdCurve();
  EvaluationUtils eu = new EvaluationUtils();
  FastVector predictions = new FastVector();
  for (int i = 0; i < runs; i++) {
    eu.setSeed(seed + i);
    predictions.appendElements(eu.getCVPredictions(classifier, inst, folds));
  }
 
  if (valueIndex != null)
    result = tc.getCurve(predictions, valueIndex.getIndex());
  else
    result = tc.getCurve(predictions);
      }
     
      // setup GUI
      ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
      vmc.setROCString("(Area under ROC = " +
    Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
      if (compute)    
  vmc.setName(
      result.relationName()
      + ". (Class value " + inst.classAttribute().value(valueIndex.getIndex()) + ")");
      else
  vmc.setName(
      result.relationName()
      + " (display only)");
      PlotData2D tempd = new PlotData2D(result);
View Full Code Here

    int      folds;
    String     tmpStr;
    boolean    compute;
    Instances     result;
    String[]     options;
    SingleIndex    classIndex;
    SingleIndex    valueIndex;
    int      seed;
   
    inst       = null;
    classifier = null;
    runs       = 2;
    folds      = 10;
    compute    = true;
    result     = null;
    classIndex = null;
    valueIndex = null;
    seed       = 1;
   
    try {
      // help?
      if (Utils.getFlag('h', args)) {
  System.out.println("\nOptions for " + ThresholdVisualizePanel.class.getName() + ":\n");
  System.out.println("-h\n\tThis help.");
  System.out.println("-t <file>\n\tDataset to process with given classifier.");
  System.out.println("-c <num>\n\tThe class index. first and last are valid, too (default: last).");
  System.out.println("-C <num>\n\tThe index of the class value to get the the curve for (default: first).");
  System.out.println("-W <classname>\n\tFull classname of classifier to run.\n\tOptions after '--' are passed to the classifier.\n\t(default: weka.classifiers.functions.Logistic)");
  System.out.println("-r <number>\n\tThe number of runs to perform (default: 1).");
  System.out.println("-x <number>\n\tThe number of Cross-validation folds (default: 10).");
  System.out.println("-S <number>\n\tThe seed value for randomizing the data (default: 1).");
  System.out.println("-l <file>\n\tPreviously saved threshold curve ARFF file.");
  return;
      }
     
      // regular options
      tmpStr = Utils.getOption('l', args);
      if (tmpStr.length() != 0) {
  result = new Instances(new BufferedReader(new FileReader(tmpStr)));
  compute = false;
      }
     
      if (compute) {
  tmpStr = Utils.getOption('r', args);
  if (tmpStr.length() != 0)
    runs = Integer.parseInt(tmpStr);
  else
    runs = 1;
 
  tmpStr = Utils.getOption('x', args);
  if (tmpStr.length() != 0)
    folds = Integer.parseInt(tmpStr);
  else
    folds = 10;
 
  tmpStr = Utils.getOption('S', args);
  if (tmpStr.length() != 0)
    seed = Integer.parseInt(tmpStr);
  else
    seed = 1;
 
  tmpStr = Utils.getOption('t', args);
  if (tmpStr.length() != 0) {
    inst = new Instances(new BufferedReader(new FileReader(tmpStr)));
    inst.setClassIndex(inst.numAttributes() - 1);
  }
 
  tmpStr = Utils.getOption('W', args);
  if (tmpStr.length() != 0) {
    options = Utils.partitionOptions(args);
  }
  else {
    tmpStr = weka.classifiers.functions.Logistic.class.getName();
    options = new String[0];
  }
  classifier = AbstractClassifier.forName(tmpStr, options);
 
  tmpStr = Utils.getOption('c', args);
  if (tmpStr.length() != 0)
    classIndex = new SingleIndex(tmpStr);
  else
    classIndex = new SingleIndex("last");
 
  tmpStr = Utils.getOption('C', args);
  if (tmpStr.length() != 0)
    valueIndex = new SingleIndex(tmpStr);
  else
    valueIndex = new SingleIndex("first");
      }
     
      // compute if necessary
      if (compute) {
  if (classIndex != null) {
    classIndex.setUpper(inst.numAttributes() - 1);
    inst.setClassIndex(classIndex.getIndex());
  }
  else {
    inst.setClassIndex(inst.numAttributes() - 1);
  }
 
  if (valueIndex != null) {
    valueIndex.setUpper(inst.classAttribute().numValues() - 1);
  }
 
  ThresholdCurve tc = new ThresholdCurve();
  EvaluationUtils eu = new EvaluationUtils();
  FastVector predictions = new FastVector();
  for (int i = 0; i < runs; i++) {
    eu.setSeed(seed + i);
    predictions.appendElements(eu.getCVPredictions(classifier, inst, folds));
  }
 
  if (valueIndex != null)
    result = tc.getCurve(predictions, valueIndex.getIndex());
  else
    result = tc.getCurve(predictions);
      }
     
      // setup GUI
      ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
      vmc.setROCString("(Area under ROC = " +
    Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
      if (compute)    
  vmc.setName(
      result.relationName()
      + ". (Class value " + inst.classAttribute().value(valueIndex.getIndex()) + ")");
      else
  vmc.setName(
      result.relationName()
      + " (display only)");
      PlotData2D tempd = new PlotData2D(result);
View Full Code Here

TOP

Related Classes of weka.core.SingleIndex

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.