/** * Use this method to make a batch of classification decisions about several objects. This * function is implemented in the most naive way (simply calling * {@link #classify(FeatureVector)} repeatedly) and should be overridden if there is a more * efficient implementation. * * @param vectors The vectors to make decisions about. * @return An array of feature vectors, one per input vector. **/ public FeatureVector[] classify(FeatureVector[] vectors) { FeatureVector[] result = new FeatureVector[vectors.length]; for (int i = 0; i < vectors.length; ++i) result[i] = classify(vectors[i]); return result; }
/** * Use this method to make a batch of classification decisions about several examples. This * function is implemented in the most naive way (simply calling * {@link #classify(int[],double[])} repeatedly) and should be overridden if there is a more * efficient implementation. * * @param e The examples to make decisions about, represented as arrays of indices and * strengths. * @return An array of feature vectors, one per input object. **/ public FeatureVector[] classify(Object[][] e) { FeatureVector[] result = new FeatureVector[e.length]; for (int i = 0; i < e.length; ++i) result[i] = classify((int[]) e[i][0], (double[]) e[i][1]); return result; }
/** * This method makes one or more decisions about a single object, returning those decisions as * {@link Feature}s in a vector. * * @param example The object to make decisions about. * @return A vector of {@link Feature}s about the input object. **/ public FeatureVector classify(Object example) { Object[] exampleArray = getExampleArray(example, false); return classify((int[]) exampleArray[0], (double[]) exampleArray[1]); }
public TestReal(Learner classifier, Classifier oracle, Parser parser) { int examples = 0; double totalDifference = 0; double[] actuals = {}; double[] predictions = {}; classifier.write(System.out); for (Object example = parser.next(); example != null; example = parser.next()) { double prediction = classifier.realValue(example); predictions = Arrays.copyOf(predictions, predictions.length + 1); predictions[predictions.length - 1] = prediction; double value = oracle.realValue(example); actuals = Arrays.copyOf(actuals, actuals.length + 1); actuals[actuals.length - 1] = value; double difference = Math.abs(prediction - value); totalDifference += difference; classifier.classify(example); ++examples; System.out.println("Example " + examples + " difference: " + difference + " (prediction: " + prediction + ")"); } System.out.println("test examples number: " + examples); double avg = totalDifference / examples; System.out.println("Average difference: " + avg); double p = getPearsonCorrelation(predictions, actuals); System.out.println("Pearson correlation:" + p); SpearmansCorrelation e = new SpearmansCorrelation(); double sp = e.correlation(predictions, actuals); System.out.println("Spearman correlation:" + sp); }
/** * This method makes one or more decisions about a single feature vector, returning those * decisions as {@link Feature}s in a vector. * * @param vector The vector to make decisions about. * @return A vector of {@link Feature}s about the input vector. **/ public FeatureVector classify(FeatureVector vector) { Classifier saveExtractor = getExtractor(); Classifier saveLabeler = getLabeler(); setExtractor(new FeatureVectorReturner()); setLabeler(new LabelVectorReturner()); FeatureVector result = classify((Object) vector); setExtractor(saveExtractor); setLabeler(saveLabeler); return result; }