Search in sources :

Example 61 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class CustomMultiscaleQuantizeTransformTest method testSelectAndExcludeFeatures.

@Test
public void testSelectAndExcludeFeatures() {
    Config config = ConfigFactory.parseString(makeConfig("select_features: [\"lat\", \"long\"] \n" + "exclude_features: [\"lat\"] \n"));
    Transform transform = TransformFactory.createTransform(config, "test_quantize");
    FeatureVector featureVector = makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 2);
    Set<String> out = stringFeatures.get("loc_quantized");
    log.info("quantize output");
    for (String string : out) {
        log.info(string);
    }
    assertTrue(out.size() == 2);
    assertTrue(out.contains("long[1.0]=40.0"));
    assertTrue(out.contains("long[10.0]=40.0"));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) HashSet(java.util.HashSet) Set(java.util.Set) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 62 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class CustomMultiscaleQuantizeTransformTest method testSelectFeatures.

@Test
public void testSelectFeatures() {
    Config config = ConfigFactory.parseString(makeConfig("select_features: [\"lat\"] \n"));
    Transform transform = TransformFactory.createTransform(config, "test_quantize");
    FeatureVector featureVector = makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 2);
    Set<String> out = stringFeatures.get("loc_quantized");
    log.info("quantize output");
    for (String string : out) {
        log.info(string);
    }
    assertTrue(out.size() == 2);
    assertTrue(out.contains("lat[10.0]=30.0"));
    assertTrue(out.contains("lat[1.0]=37.0"));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) HashSet(java.util.HashSet) Set(java.util.Set) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 63 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class CutFloatTransformTest method testTransform.

@Test
public void testTransform() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(config, "test_cut");
    FeatureVector featureVector = TransformTestingHelper.makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 1);
    Map<String, Double> feat1 = featureVector.getFloatFeatures().get("loc");
    assertEquals(2, feat1.size());
    assertEquals(37.7, feat1.get("lat"), 0.1);
    assertNull(feat1.get("long"));
    assertEquals(-20.0, feat1.get("z"), 0.1);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Set(java.util.Set) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 64 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class CutFloatTransformTest method testTransformWithNewOutput.

@Test
public void testTransformWithNewOutput() {
    Config config = ConfigFactory.parseString(makeConfigWithOutput());
    Transform transform = TransformFactory.createTransform(config, "test_cut");
    FeatureVector featureVector = TransformTestingHelper.makeFeatureVector();
    transform.doTransform(featureVector);
    Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
    assertTrue(stringFeatures.size() == 1);
    // original feature should not change
    Map<String, Double> feat1 = featureVector.getFloatFeatures().get("loc");
    assertEquals(3, feat1.size());
    assertEquals(37.7, feat1.get("lat"), 0.1);
    assertEquals(40.0, feat1.get("long"), 0.1);
    assertEquals(-20, feat1.get("z"), 0.1);
    // capped features are in a new feature family
    assertTrue(featureVector.getFloatFeatures().containsKey("new_output"));
    Map<String, Double> feat2 = featureVector.getFloatFeatures().get("new_output");
    assertEquals(1, feat2.size());
    assertEquals(37.7, feat2.get("lat"), 0.1);
    assertNull(feat2.get("long"));
    assertNull(feat2.get("z"));
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Set(java.util.Set) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 65 with FeatureVector

use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.

the class FloatToDenseTransformTest method testPartial.

@Test
public void testPartial() {
    FeatureVector featureVector = testTransform(makeFeatureVectorPartial());
    Map<String, List<Double>> denseFeatures = featureVector.getDenseFeatures();
    assertNull(denseFeatures);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) List(java.util.List) Test(org.junit.Test)

Aggregations

FeatureVector (com.airbnb.aerosolve.core.FeatureVector)225 Test (org.junit.Test)154 Config (com.typesafe.config.Config)117 Set (java.util.Set)59 HashMap (java.util.HashMap)58 HashSet (java.util.HashSet)50 Map (java.util.Map)46 ArrayList (java.util.ArrayList)11 Example (com.airbnb.aerosolve.core.Example)9 List (java.util.List)9 ModelRecord (com.airbnb.aerosolve.core.ModelRecord)5 ModelHeader (com.airbnb.aerosolve.core.ModelHeader)4 BufferedReader (java.io.BufferedReader)4 IOException (java.io.IOException)4 MulticlassScoringResult (com.airbnb.aerosolve.core.MulticlassScoringResult)3 BufferedWriter (java.io.BufferedWriter)3 CharArrayWriter (java.io.CharArrayWriter)3 StringReader (java.io.StringReader)3 DebugScoreRecord (com.airbnb.aerosolve.core.DebugScoreRecord)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2