Search in sources :

Example 31 with FeatureVector

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

the class FloatToDenseTransformTest method testNoString.

@Test
public void testNoString() {
    FeatureVector featureVector = testTransform(makeFeatureVectorString(), notStringConfig());
    Map<String, Set<String>> features = featureVector.getStringFeatures();
    assertNull(features);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Set(java.util.Set) Test(org.junit.Test)

Example 32 with FeatureVector

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

the class ApproximatePercentileTransformTest method makeFeatureVector.

public FeatureVector makeFeatureVector(double low, double high, double val) {
    Map<String, Set<String>> stringFeatures = new HashMap<>();
    Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
    Set list = new HashSet<String>();
    list.add("aaa");
    list.add("bbb");
    stringFeatures.put("strFeature1", list);
    Map<String, Double> map = new HashMap<>();
    map.put("10th", low);
    map.put("90th", high);
    floatFeatures.put("DECILES", map);
    Map<String, Double> map2 = new HashMap<>();
    map2.put("foo", val);
    floatFeatures.put("F", map2);
    FeatureVector featureVector = new FeatureVector();
    featureVector.setStringFeatures(stringFeatures);
    featureVector.setFloatFeatures(floatFeatures);
    return featureVector;
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector)

Example 33 with FeatureVector

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

the class ApproximatePercentileTransformTest method testTransform.

@Test
public void testTransform() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(config, "test_approximate_percentile");
    double[] values = { -1.0, 10.0, 15.0, 20.0, 50.0, 60.0, 100.0, 200.0 };
    double[] expected = { 0.0, 0.0, 0.05, 0.11, 0.44, 0.55, 1.0, 1.0 };
    for (int i = 0; i < values.length; i++) {
        double val = values[i];
        FeatureVector featureVector = makeFeatureVector(10.0, 100.0, val);
        transform.doTransform(featureVector);
        Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
        assertTrue(stringFeatures.size() == 1);
        Map<String, Double> out = featureVector.floatFeatures.get("PERCENTILE");
        assertTrue(out.size() == 1);
        assertEquals(expected[i], out.get("percentile"), 0.01);
    }
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 34 with FeatureVector

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

the class ApproximatePercentileTransformTest method testEmptyFeatureVector.

@Test
public void testEmptyFeatureVector() {
    Config config = ConfigFactory.parseString(makeConfig());
    Transform transform = TransformFactory.createTransform(config, "test_approximate_percentile");
    FeatureVector featureVector = new FeatureVector();
    transform.doTransform(featureVector);
    assertTrue(featureVector.getStringFeatures() == null);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) Test(org.junit.Test)

Example 35 with FeatureVector

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

the class CapFloatTransformTest method testTransformWithNewOutput.

@Test
public void testTransformWithNewOutput() {
    Config config = ConfigFactory.parseString(makeConfigWithOutput());
    Transform transform = TransformFactory.createTransform(config, "test_cap");
    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(3, feat2.size());
    assertEquals(37.7, feat2.get("lat"), 0.1);
    assertEquals(39.0, feat2.get("long"), 0.1);
    assertEquals(1.0, feat2.get("z"), 0.1);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Config(com.typesafe.config.Config) 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