weka.classifiers.functions.LibSVM Java Examples
The following examples show how to use
weka.classifiers.functions.LibSVM.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PolarityClassifier.java From sentiment-analysis with Apache License 2.0 | 6 votes |
/**Initializes the MNB and SVM classifiers, by loading the previously generated models.*/ private void initializeClassifiers(){ mnb_classifiers = new Classifier[3]; try { mnb_classifiers[0] = (Classifier) weka.core.SerializationHelper.read(folder+"/models/text.model"); mnb_classifiers[1] = (Classifier) weka.core.SerializationHelper.read(folder+"/models/feature.model"); mnb_classifiers[2] = (Classifier) weka.core.SerializationHelper.read(folder+"/models/complex.model"); lexicon_classifier = (LibSVM) weka.core.SerializationHelper.read(folder+"/models/lexicon.model"); BufferedReader trdr = new BufferedReader(new FileReader(new File(folder+"/train/T.arff"))); BufferedReader frdr = new BufferedReader(new FileReader(new File(folder+"/train/F.arff"))); BufferedReader crdr = new BufferedReader(new FileReader(new File(folder+"/train/C.arff"))); training_text = new Instances(trdr); training_feature = new Instances(frdr); training_complex = new Instances(crdr); trdr.close(); frdr.close(); crdr.close(); } catch (Exception e) { e.printStackTrace(); } }
Example #2
Source File: WekaEmailIntentClassifier.java From EmailIntentDataSet with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("Usage: WekaSpeechActClassifier <train_set_input_file> <test_set_input_file>"); System.exit(0); } String arffFileTrain = args[0]; String arffFileTest = args[1]; LibSVM wekaClassifier = new LibSVM(); wekaClassifier.setOptions(new String[] {"-B", "-H"}); Instances preparedData = (Instances) SerializationHelper.read(arffFileTrain); Instances preparedTest = (Instances) SerializationHelper.read(arffFileTest); System.out.println("Reading train set and test set done!"); System.out.print("\nTraining..."); wekaClassifier.buildClassifier(preparedData); System.out.println("\nTraining...done!"); Evaluation evalTrain = new Evaluation(preparedData); evalTrain.evaluateModel(wekaClassifier, preparedData); DecimalFormat formatter = new DecimalFormat("#0.0"); System.out.println("\nEvaluating on trainSet..."); System.out.println(evalTrain.toSummaryString()); System.out.println("\nResult on trainSet..."); System.out.println("Precision:" + formatter.format(100*evalTrain.precision(0)) + "%" + " - Recal: " + formatter.format(100*evalTrain.recall(0)) + "%" + " - F1: " + formatter.format(evalTrain.fMeasure(0)) + "%"); Evaluation eval = new Evaluation(preparedTest); eval.evaluateModel(wekaClassifier, preparedTest); System.out.println("\nEvaluating on testSet..."); System.out.println(eval.toSummaryString()); System.out.println("\nResult on testSet..."); System.out.println("Precision:" + formatter.format(100*eval.precision(0)) + "%" + " - Recal: " + formatter.format(100*eval.recall(0)) + "%" + " - F1: " + formatter.format(100*eval.fMeasure(0)) + "%"); System.out.println("True positive rate: " + formatter.format(100*eval.truePositiveRate(0)) + "%" + " - True negative rate: " + formatter.format(100*eval.trueNegativeRate(0)) + "%"); System.out.println("Accuracy: " + formatter.format(100*((eval.truePositiveRate(0) + eval.trueNegativeRate(0)) / 2)) + "%"); System.out.println("\nDone!"); }