@Test public void testFeature() { System.out.println("feature"); int[][] result = { {0, 3, 6, 9}, {0, 3, 6, 8}, {1, 3, 6, 9}, {2, 4, 6, 9}, {2, 5, 7, 9}, {2, 5, 7, 8}, {1, 5, 7, 8}, {0, 4, 6, 9}, {0, 5, 7, 9}, {2, 4, 7, 9}, {0, 4, 7, 8}, {1, 4, 6, 8}, {1, 3, 7, 9}, {2, 4, 6, 8} }; DataFrame data = WeatherNominal.formula.x(WeatherNominal.data); SparseOneHotEncoder n2sb = new SparseOneHotEncoder(data.schema()); int[][] onehot = n2sb.apply(data); for (int i = 0; i < data.size(); i++) { for (int j = 0; j < result[i].length; j++) { assertEquals(result[i][j], onehot[i][j]); } } }
public int[] apply(Tuple x) { int[] features = new int[schema.length()]; for (int i = 0; i < features.length; i++) { features[i] = x.getInt(i) + base[i]; } return features; }
SparseOneHotEncoder { public int[] apply(Tuple x) { int[] features = new int[schema.length()]; for (int i = 0; i < features.length; i++) { features[i] = x.getInt(i) + base[i]; } return features; } }
SparseOneHotEncoder { public int[] apply(Tuple x) { int[] features = new int[schema.length()]; for (int i = 0; i < features.length; i++) { features[i] = x.getInt(i) + base[i]; } return features; } SparseOneHotEncoder(StructType schema); }
SparseOneHotEncoder { public int[] apply(Tuple x) { int[] features = new int[schema.length()]; for (int i = 0; i < features.length; i++) { features[i] = x.getInt(i) + base[i]; } return features; } SparseOneHotEncoder(StructType schema); int[] apply(Tuple x); int[][] apply(DataFrame data); }
SparseOneHotEncoder { public int[] apply(Tuple x) { int[] features = new int[schema.length()]; for (int i = 0; i < features.length; i++) { features[i] = x.getInt(i) + base[i]; } return features; } SparseOneHotEncoder(StructType schema); int[] apply(Tuple x); int[][] apply(DataFrame data);  }