public static void main(String argv[]) throws IOException {
    int i, predict_probability = 0;
    svm_print_string = svm_print_stdout;

    // parse options
    for (i = 0; i < argv.length; i++) {
      if (argv[i].charAt(0) != '-') break;
      ++i;
      switch (argv[i - 1].charAt(1)) {
        case 'b':
          predict_probability = atoi(argv[i]);
          break;
        case 'q':
          svm_print_string = svm_print_null;
          i--;
          break;
        default:
          System.err.print("Unknown option: " + argv[i - 1] + "\n");
          exit_with_help();
      }
    }
    if (i >= argv.length - 2) exit_with_help();
    try {
      BufferedReader input = new BufferedReader(new FileReader(argv[i]));
      DataOutputStream output =
          new DataOutputStream(new BufferedOutputStream(new FileOutputStream(argv[i + 2])));
      svm_model model = svm.svm_load_model(argv[i + 1]);
      if (model == null) {
        System.err.print("can't open model file " + argv[i + 1] + "\n");
        System.exit(1);
      }
      if (predict_probability == 1) {
        if (svm.svm_check_probability_model(model) == 0) {
          System.err.print("Model does not support probabiliy estimates\n");
          System.exit(1);
        }
      } else {
        if (svm.svm_check_probability_model(model) != 0) {
          svm_predict.info("Model supports probability estimates, but disabled in prediction.\n");
        }
      }
      predict(input, output, model, predict_probability);
      input.close();
      output.close();
    } catch (FileNotFoundException e) {
      exit_with_help();
    } catch (ArrayIndexOutOfBoundsException e) {
      exit_with_help();
    }
  }
Example #2
0
 private static void exit_with_help() {
   System.err.print(
       "usage: svm_predict [options] test_file model_file output_file\n"
           + "options:\n"
           + "-b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); one-class SVM not supported yet\n");
   System.exit(1);
 }
  public static void main(String argv[]) throws IOException {
    int i, predict_probability = 0;

    // parse options
    for (i = 0; i < argv.length; i++) {
      if (argv[i].charAt(0) != '-') break;
      ++i;
      switch (argv[i - 1].charAt(1)) {
        case 'b':
          predict_probability = atoi(argv[i]);
          break;
        default:
          System.err.print("unknown option\n");
          exit_with_help();
      }
    }
    if (i >= argv.length) exit_with_help();
    try {
      BufferedReader input = new BufferedReader(new FileReader(argv[i]));
      DataOutputStream output = new DataOutputStream(new FileOutputStream(argv[i + 2]));
      svm_model model = svm.svm_load_model(argv[i + 1]);
      if (predict_probability == 1)
        if (svm.svm_check_probability_model(model) == 0) {
          System.err.print("Model does not support probabiliy estimates\n");
          System.exit(1);
        }
      predict(input, output, model, predict_probability);
      input.close();
      output.close();
    } catch (FileNotFoundException e) {
      exit_with_help();
    } catch (ArrayIndexOutOfBoundsException e) {
      exit_with_help();
    }
  }
 private static void exit_with_help() {
   System.err.print(help());
   System.exit(1);
 }