use of com.spotify.zoltar.FeatureExtractFns.SingleExtractFn in project zoltar by spotify.
the class PredictorTest method nonEmpty.
@Test
public void nonEmpty() throws InterruptedException, ExecutionException, TimeoutException {
final Duration wait = Duration.ofSeconds(1);
final SingleExtractFn<Integer, Float> extractFn = input -> (float) input / 10;
final PredictFn<DummyModel, Integer, Float, Float> predictFn = (model, vectors) -> {
return vectors.stream().map(vector -> Prediction.create(vector.input(), vector.value() * 2)).collect(Collectors.toList());
};
final ModelLoader<DummyModel> loader = ModelLoader.lift(DummyModel::new);
final List<Prediction<Integer, Float>> predictions = DefaultPredictorBuilder.create(loader, extractFn, predictFn).predictor().predict(1).toCompletableFuture().get(wait.toMillis(), TimeUnit.MILLISECONDS);
assertThat(predictions.size(), is(1));
assertThat(predictions.get(0), is(Prediction.create(1, 0.2f)));
}
Aggregations