use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class LowRankLinearModelTest method testScoreNonEmptyFeature.
@Test
public void testScoreNonEmptyFeature() {
FeatureVector animalFv = makeFeatureVector("animal");
FeatureVector colorFv = makeFeatureVector("color");
FeatureVector fruitFv = makeFeatureVector("fruit");
LowRankLinearModel model = makeLowRankLinearModel();
ArrayList<MulticlassScoringResult> s1 = model.scoreItemMulticlass(animalFv);
assertEquals(s1.size(), 3);
assertEquals(0.0f, s1.get(0).score, 3.0f);
assertEquals(0.0f, s1.get(1).score, 1e-10f);
assertEquals(0.0f, s1.get(2).score, 1e-10f);
ArrayList<MulticlassScoringResult> s2 = model.scoreItemMulticlass(colorFv);
assertEquals(s2.size(), 3);
assertEquals(0.0f, s2.get(0).score, 1e-10f);
assertEquals(0.0f, s2.get(1).score, 6.0f);
assertEquals(0.0f, s2.get(2).score, 1e-10f);
ArrayList<MulticlassScoringResult> s3 = model.scoreItemMulticlass(fruitFv);
assertEquals(s3.size(), 3);
assertEquals(0.0f, s3.get(0).score, 1e-10f);
assertEquals(0.0f, s3.get(1).score, 1e-10f);
assertEquals(0.0f, s3.get(2).score, 4.0f);
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class LowRankLinearModelTest method testScoreEmptyFeature.
@Test
public void testScoreEmptyFeature() {
FeatureVector featureVector = new FeatureVector();
LowRankLinearModel model = makeLowRankLinearModel();
ArrayList<MulticlassScoringResult> score = model.scoreItemMulticlass(featureVector);
assertEquals(score.size(), 3);
assertEquals(0.0f, score.get(0).score, 1e-10f);
assertEquals(0.0f, score.get(1).score, 1e-10f);
assertEquals(0.0f, score.get(2).score, 1e-10f);
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class LowRankLinearModelTest method makeFeatureVector.
public FeatureVector makeFeatureVector(String label) {
FeatureVector featureVector = new FeatureVector();
HashMap stringFeatures = new HashMap<String, HashSet<String>>();
featureVector.setStringFeatures(stringFeatures);
HashMap floatFeatures = new HashMap<String, HashMap<String, Double>>();
featureVector.setFloatFeatures(floatFeatures);
HashMap feature = new HashMap<String, Float>();
switch(label) {
case "animal":
{
feature.put("cat", 1.0);
feature.put("dog", 2.0);
floatFeatures.put("a", feature);
break;
}
case "color":
{
feature.put("red", 2.0);
feature.put("black", 4.0);
floatFeatures.put("c", feature);
break;
}
case "fruit":
{
feature.put("apple", 1.0);
feature.put("kiwi", 3.0);
floatFeatures.put("f", feature);
break;
}
default:
break;
}
return featureVector;
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class ModelScorerTest method rawProbability.
@Test
public void rawProbability() throws Exception {
ModelConfig incomeModel = ModelConfig.builder().modelName("income.model").configName("income_prediction.conf").key("spline_model").build();
ModelScorer modelScorer = new ModelScorer(incomeModel);
FeatureMapping featureMapping = new FeatureMapping();
featureMapping.add(dataName1);
featureMapping.add(dataName2);
featureMapping.add(dataName3);
featureMapping.finish();
FeatureGen f = new FeatureGen(featureMapping);
f.add(data1, dataName1);
f.add(data2, dataName2);
f.add(data3, dataName3);
Features features = f.gen();
List<StringFamily> stringFamilies = new ArrayList<>();
stringFamilies.add(new StringFamily("S"));
List<FloatFamily> floatFamilies = new ArrayList<>();
floatFamilies.add(new FloatFamily("F"));
Example example = FeatureVectorGen.toSingleFeatureVectorExample(features, stringFamilies, floatFamilies);
FeatureVector featureVector = example.getExample().get(0);
final Map<String, Map<String, Double>> floatFeatures = featureVector.getFloatFeatures();
Map<String, Double> floatFeatureFamily = floatFeatures.get("F");
assertEquals(floatFeatureFamily.get("age"), 30, 0.1);
assertEquals(floatFeatureFamily.get("hours"), 40, 0.1);
final Map<String, Set<String>> stringFeatures = featureVector.getStringFeatures();
Set<String> stringFeatureFamily = stringFeatures.get("S");
assertFalse(stringFeatureFamily.contains("marital-status"));
assertTrue(stringFeatureFamily.contains("married"));
double score = modelScorer.score(example);
log.info("score {}", score);
}
use of com.airbnb.aerosolve.core.FeatureVector in project aerosolve by airbnb.
the class AdditiveModelTest method testScoreEmptyFeature.
@Test
public void testScoreEmptyFeature() {
FeatureVector featureVector = new FeatureVector();
AdditiveModel model = new AdditiveModel();
float score = model.scoreItem(featureVector);
assertEquals(0.0f, score, 1e-10f);
}
Aggregations