Search in sources :

Example 16 with ModelRecord

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

the class SplineTest method testSplineModelRecordConstructor.

@Test
public void testSplineModelRecordConstructor() {
    ModelRecord record = new ModelRecord();
    record.setFeatureFamily("TEST");
    record.setFeatureName("a");
    record.setMinVal(1.0);
    record.setMaxVal(3.0);
    List<Double> weightVec = new ArrayList<Double>();
    weightVec.add(5.0);
    weightVec.add(10.0);
    weightVec.add(-20.0);
    record.setWeightVector(weightVec);
    Spline spline = new Spline(record);
    testSpline(spline, 0.1f);
}
Also used : ArrayList(java.util.ArrayList) ModelRecord(com.airbnb.aerosolve.core.ModelRecord) Test(org.junit.Test)

Example 17 with ModelRecord

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

the class SplineTest method testSplineToModelRecord.

@Test
public void testSplineToModelRecord() {
    float[] weights = { 5.0f, 10.0f, -20.0f };
    Spline spline = new Spline(1.0f, 3.0f, weights);
    ModelRecord record = spline.toModelRecord("family", "name");
    assertEquals(record.getFeatureFamily(), "family");
    assertEquals(record.getFeatureName(), "name");
    List<Double> weightVector = record.getWeightVector();
    assertEquals(5.0f, weightVector.get(0).floatValue(), 0.01f);
    assertEquals(10.0f, weightVector.get(1).floatValue(), 0.01f);
    assertEquals(-20.0f, weightVector.get(2).floatValue(), 0.01f);
    assertEquals(1.0f, record.getMinVal(), 0.01f);
    assertEquals(3.0f, record.getMaxVal(), 0.01f);
}
Also used : ModelRecord(com.airbnb.aerosolve.core.ModelRecord) Test(org.junit.Test)

Example 18 with ModelRecord

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

the class DecisionTreeTransformTest method makeTree.

/*
   * XOR like decision regions
   * 
   *         x = 2
   *          |
   *    -0.5  |   1.0
   *          |-------- y = 1
   *   -------- y = 0
   *          |
   *     0.25 |   -0.75
   *          |
   */
public DecisionTreeModel makeTree() {
    ArrayList<ModelRecord> records = new ArrayList<>();
    DecisionTreeModel tree = new DecisionTreeModel();
    tree.setStumps(records);
    // 0 - an x split at 2
    ModelRecord record = new ModelRecord();
    record.setFeatureFamily("loc");
    record.setFeatureName("x");
    record.setThreshold(2.0);
    record.setLeftChild(1);
    record.setRightChild(2);
    records.add(record);
    // 1 - a y split at 0
    record = new ModelRecord();
    record.setFeatureFamily("loc");
    record.setFeatureName("y");
    record.setThreshold(0.0);
    record.setLeftChild(3);
    record.setRightChild(4);
    records.add(record);
    // 2 - a y split at 1
    record = new ModelRecord();
    record.setFeatureFamily("loc");
    record.setFeatureName("y");
    record.setThreshold(1.0);
    record.setLeftChild(5);
    record.setRightChild(6);
    records.add(record);
    // 3  a leaf
    record = new ModelRecord();
    record.setFeatureWeight(0.25);
    records.add(record);
    // 4  a leaf
    record = new ModelRecord();
    record.setFeatureWeight(-0.5);
    records.add(record);
    // 5  a leaf
    record = new ModelRecord();
    record.setFeatureWeight(-0.75);
    records.add(record);
    // 6  a leaf
    record = new ModelRecord();
    record.setFeatureWeight(1.0);
    records.add(record);
    return tree;
}
Also used : DecisionTreeModel(com.airbnb.aerosolve.core.models.DecisionTreeModel) ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Example 19 with ModelRecord

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

the class SupportVector method toModelRecord.

public ModelRecord toModelRecord() {
    ModelRecord rec = new ModelRecord();
    rec.setScale(scale);
    rec.setFunctionForm(form);
    ArrayList<Double> weightVector = new ArrayList<>();
    for (int i = 0; i < floatVector.getValues().length; i++) {
        weightVector.add((double) floatVector.getValues()[i]);
    }
    rec.setWeightVector(weightVector);
    rec.setFeatureWeight(weight);
    return rec;
}
Also used : ArrayList(java.util.ArrayList) ModelRecord(com.airbnb.aerosolve.core.ModelRecord)

Example 20 with ModelRecord

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

the class LinearTest method testLinearModelRecordConstructor.

@Test
public void testLinearModelRecordConstructor() {
    ModelRecord record = new ModelRecord();
    record.setFeatureFamily("TEST");
    record.setFeatureName("a");
    List<Double> weightVec = new ArrayList<>();
    weightVec.add(0.2);
    weightVec.add(1.5);
    record.setWeightVector(weightVec);
    record.setMinVal(-6.0f);
    record.setMaxVal(5.0f);
    Linear linearFunc = new Linear(record);
    testLinear(linearFunc);
}
Also used : ArrayList(java.util.ArrayList) ModelRecord(com.airbnb.aerosolve.core.ModelRecord) Test(org.junit.Test)

Aggregations

ModelRecord (com.airbnb.aerosolve.core.ModelRecord)40 ModelHeader (com.airbnb.aerosolve.core.ModelHeader)14 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 FloatVector (com.airbnb.aerosolve.core.util.FloatVector)8 Map (java.util.Map)5 FeatureVector (com.airbnb.aerosolve.core.FeatureVector)4 BufferedReader (java.io.BufferedReader)3 BufferedWriter (java.io.BufferedWriter)3 CharArrayWriter (java.io.CharArrayWriter)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 LabelDictionaryEntry (com.airbnb.aerosolve.core.LabelDictionaryEntry)2 AbstractFunction (com.airbnb.aerosolve.core.function.AbstractFunction)2 Function (com.airbnb.aerosolve.core.function.Function)2 NDTreeModelTest (com.airbnb.aerosolve.core.models.NDTreeModelTest)2 SupportVector (com.airbnb.aerosolve.core.util.SupportVector)2 HashMap (java.util.HashMap)2 DebugScoreRecord (com.airbnb.aerosolve.core.DebugScoreRecord)1 MulticlassScoringResult (com.airbnb.aerosolve.core.MulticlassScoringResult)1