@Override
    public SparseArray apply(Tuple x) {
        SparseArray features = new SparseArray();
        for (int i = 0; i < columns.length; i++) {
            StructField field = schema.field(columns[i]);
            if (field.isNumeric()) {
                features.append(base[i], x.getDouble(columns[i]));
            } else if (field.measure instanceof CategoricalMeasure) {
                features.append(x.getInt(columns[i]) + base[i], 1);
            } else {
                throw new IllegalArgumentException(String.format("Column '%s' is neither numeric or categorical", field.name));
            }
        }

        return features;
    }
@Test
    public void test() {
        System.out.println("Sparse Encoder");

        DataFrame data = Weather.data;
        SparseEncoder encoder = new SparseEncoder(data.schema(), "outlook", "temperature", "humidity", "windy");
        SparseArray[] features = encoder.apply(data);

        assertEquals(data.size(), features.length);
        for (int i = 0; i < data.size(); i++) {
            assertEquals(4, features[i].size());
        }

        assertEquals( 1, features[0].get(0), 1E-7);
        assertEquals(85, features[0].get(3), 1E-7);
        assertEquals(85, features[0].get(4), 1E-7);
        assertEquals( 1, features[0].get(6), 1E-7);

        assertEquals( 1, features[13].get(2), 1E-7);
        assertEquals(71, features[13].get(3), 1E-7);
        assertEquals(91, features[13].get(4), 1E-7);
        assertEquals( 1, features[13].get(5), 1E-7);
    }