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);
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations