public weka.classifiers.Classifier getClassifier() throws Exception {

    StringToWordVector stwv = new StringToWordVector();
    stwv.setTFTransform(hasParam(Constant.RUNTIME_PARAMS.USE_TFIDF));
    stwv.setIDFTransform(hasParam(Constant.RUNTIME_PARAMS.USE_TFIDF));
    stwv.setLowerCaseTokens(hasParam(Constant.RUNTIME_PARAMS.CONV_LOWERCASE));
    stwv.setUseStoplist(hasParam(Constant.RUNTIME_PARAMS.REM_STOP_WORDS));
    stwv.setOutputWordCounts(hasParam(Constant.RUNTIME_PARAMS.USE_WORD_FREQ));
    if (hasParam(Constant.RUNTIME_PARAMS.TRAIN_AND_TEST)) stwv.setInputFormat(getTrainData());
    if (hasParam(Constant.RUNTIME_PARAMS.USE_BIGRAM)) {
      NGramTokenizer tokenizer = new NGramTokenizer();
      tokenizer.setNGramMinSize(2);
      stwv.setTokenizer(tokenizer);
    } else if (hasParam(Constant.RUNTIME_PARAMS.USE_TRIGRAM)) {
      NGramTokenizer tokenizer = new NGramTokenizer();
      tokenizer.setNGramMinSize(3);
      stwv.setTokenizer(tokenizer);
    }
    if (hasParam(Constant.RUNTIME_PARAMS.USE_STEMMER)) {
      SnowballStemmer stemmer = new SnowballStemmer("porter");
      stwv.setStemmer(stemmer);
    }

    Logistic l = new Logistic();

    FilteredClassifier cls = new FilteredClassifier();
    cls.setClassifier(l);
    cls.setFilter(stwv);
    if (hasParam(Constant.RUNTIME_PARAMS.TRAIN_AND_TEST)) cls.buildClassifier(getTrainData());

    return cls;
  }
  public static void classify(Instances train, File file) throws Exception {
    FastVector atts = new FastVector();
    String[] classes = {"classical", "hiphop", "pop", "rock"};
    double[] val;
    FastVector attValsRel = new FastVector();

    // Setting attributes for the test data
    Attribute attributeZero = new Attribute("Zero_Crossings");
    atts.addElement(attributeZero);
    Attribute attributeLPC = new Attribute("LPC");
    atts.addElement(attributeLPC);
    Attribute attributeCentroid = new Attribute("Spectral_Centroid");
    atts.addElement(attributeCentroid);
    Attribute attributeRollOff = new Attribute("Spectral_Rolloff_Point");
    atts.addElement(attributeRollOff);
    Attribute attributePeakDetection = new Attribute("Peak_Detection");
    atts.addElement(attributePeakDetection);
    Attribute attributeStrongestBeat = new Attribute("Strongest_Beat");
    atts.addElement(attributeStrongestBeat);
    Attribute attributeBeatSum = new Attribute("Beat_Sum");
    atts.addElement(attributeBeatSum);
    Attribute attributeRMS = new Attribute("RMS");
    atts.addElement(attributeRMS);
    Attribute attributeConstantQ = new Attribute("ConstantQ");
    atts.addElement(attributeConstantQ);
    Attribute attributeMFT = new Attribute("MagnitudeFFT");
    atts.addElement(attributeMFT);
    Attribute attributeMFCC = new Attribute("MFCC");
    atts.addElement(attributeMFCC);

    for (int i = 0; i < classes.length; i++) attValsRel.addElement(classes[i]);
    atts.addElement(new Attribute("class", attValsRel));
    // Adding instances to the test dataset

    Instances test = new Instances("AudioSamples", atts, 0);
    val = makeData(file, null, attValsRel, test.numAttributes());
    Instance instance = new Instance(test.numAttributes());
    instance.setValue(attributeZero, val[0]);
    instance.setValue(attributeLPC, val[1]);
    instance.setValue(attributeCentroid, val[2]);
    instance.setValue(attributeRollOff, val[3]);
    instance.setValue(attributePeakDetection, val[4]);
    instance.setValue(attributeStrongestBeat, val[5]);
    instance.setValue(attributeBeatSum, val[6]);
    instance.setValue(attributeRMS, val[7]);
    instance.setValue(attributeConstantQ, val[8]);
    instance.setValue(attributeMFT, val[9]);
    instance.setValue(attributeMFCC, val[10]);
    test.add(instance);
    // Setting the class attribute
    test.setClassIndex(test.numAttributes() - 1);
    System.out.println(test);
    // Trainging the classifier with train dataset
    classifier = new FilteredClassifier();
    classifier.buildClassifier(train);

    // Classifying the test data with the train data
    for (int i = 0; i < test.numInstances(); i++) {
      double pred = classifier.classifyInstance(test.instance(i));
      System.out.println("===== Classified instance =====");
      System.out.println("Class predicted: " + test.classAttribute().value((int) pred));
    }
  }