Map<Value, Double> labelMap = new HashMap<Value, Double>();
List<Double> target = EvaluationUtils.createTarget(labels, labelMap);
// Initialize parameters object for LibLINEAR
double[] cs = {0.0001, 0.001, 0.01, 0.1, 1,10,100,1000, 10000}; // C values to optimize over.
LibLINEARParameters linParms = new LibLINEARParameters(LibLINEARParameters.SVC_DUAL, cs);
linParms.setDoCrossValidation(true);
// Set the weights of the different classes, for the first 100 instances
Map<Double, Double> counts = EvaluationUtils.computeClassCounts(target.subList(0,100));
int[] wLabels = new int[counts.size()];
double[] weights = new double[counts.size()];
for (double label : counts.keySet()) {
wLabels[(int) label - 1] = (int) label;
weights[(int) label - 1] = 1 / counts.get(label);
}
linParms.setWeightLabels(wLabels);
linParms.setWeights(weights);
// Train model on the first 100 instances.
LibLINEARModel model = LibLINEAR.trainLinearModel(Arrays.copyOfRange(featureVectors, 0, 100), EvaluationUtils.target2Doubles(target.subList(0, 100)), linParms);
// Test on the rest of the data