Search in sources :

Example 1 with SingleExtractFn

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)));
}
Also used : SingleExtractFn(com.spotify.zoltar.FeatureExtractFns.SingleExtractFn) PredictFn(com.spotify.zoltar.PredictFns.PredictFn) Assert.assertTrue(org.junit.Assert.assertTrue) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test) AsyncPredictFn(com.spotify.zoltar.PredictFns.AsyncPredictFn) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Duration(java.time.Duration) Is.is(org.hamcrest.core.Is.is) ExtractFn(com.spotify.zoltar.FeatureExtractFns.ExtractFn) Assert.fail(org.junit.Assert.fail) Collections(java.util.Collections) Duration(java.time.Duration) Test(org.junit.Test)

Aggregations

ExtractFn (com.spotify.zoltar.FeatureExtractFns.ExtractFn)1 SingleExtractFn (com.spotify.zoltar.FeatureExtractFns.SingleExtractFn)1 AsyncPredictFn (com.spotify.zoltar.PredictFns.AsyncPredictFn)1 PredictFn (com.spotify.zoltar.PredictFns.PredictFn)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 Is.is (org.hamcrest.core.Is.is)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1