Search in sources :

Example 6 with FeatureVector

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);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) MulticlassScoringResult(com.airbnb.aerosolve.core.MulticlassScoringResult) Test(org.junit.Test)

Example 7 with FeatureVector

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);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) MulticlassScoringResult(com.airbnb.aerosolve.core.MulticlassScoringResult) Test(org.junit.Test)

Example 8 with FeatureVector

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;
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) HashMap(java.util.HashMap)

Example 9 with 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);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) Set(java.util.Set) ArrayList(java.util.ArrayList) Example(com.airbnb.aerosolve.core.Example) Map(java.util.Map) Test(org.junit.Test)

Example 10 with FeatureVector

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);
}
Also used : FeatureVector(com.airbnb.aerosolve.core.FeatureVector) 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