@Override public OneHotEncoderModelInfo getModelInfo(final OneHotEncoder from, DataFrame df) { OneHotEncoderModelInfo modelInfo = new OneHotEncoderModelInfo(); String inputColumn = from.getInputCol(); //Ugly but the only way to deal with spark here int numTypes = -1; Attribute attribute = Attribute.fromStructField(df.schema().apply(inputColumn)); if (attribute.attrType() == AttributeType.Nominal()) { numTypes = ((NominalAttribute) Attribute.fromStructField(df.schema().apply(inputColumn))).values().get().length; } else if (attribute.attrType() == AttributeType.Binary()) { numTypes = ((BinaryAttribute) Attribute.fromStructField(df.schema().apply(inputColumn))).values().get().length; } //TODO: Since dropLast is not accesible here, We are deliberately setting numTypes. This is the reason, we should use CustomOneHotEncoder modelInfo.setNumTypes(numTypes - 1); Set<String> inputKeys = new LinkedHashSet<String>(); inputKeys.add(from.getInputCol()); modelInfo.setInputKeys(inputKeys); Set<String> outputKeys = new LinkedHashSet<String>(); outputKeys.add(from.getOutputCol()); modelInfo.setOutputKeys(outputKeys); return modelInfo; }
@Test public void testBinaryAttribute() { BinaryAttribute attr = BinaryAttribute.defaultAttr() .withName("clicked").withIndex(2).withValues("no", "yes"); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); } }
@Test public void testBinaryAttribute() { BinaryAttribute attr = BinaryAttribute.defaultAttr() .withName("clicked").withIndex(2).withValues("no", "yes"); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); } }
@Test public void testNominalAttribute() { NominalAttribute attr = NominalAttribute.defaultAttr() .withName("size").withIndex(1).withValues("small", "medium", "large"); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); }
@Test public void testNominalAttribute() { NominalAttribute attr = NominalAttribute.defaultAttr() .withName("size").withIndex(1).withValues("small", "medium", "large"); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); }
@Test public void testBinaryAttribute() { BinaryAttribute attr = BinaryAttribute.defaultAttr() .withName("clicked").withIndex(2).withValues("no", "yes"); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); } }
@Test public void testNominalAttribute() { NominalAttribute attr = NominalAttribute.defaultAttr() .withName("size").withIndex(1).withValues("small", "medium", "large"); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); }
@Test public void testNumericAttribute() { NumericAttribute attr = NumericAttribute.defaultAttr() .withName("age").withIndex(0).withMin(0.0).withMax(1.0).withStd(0.5).withSparsity(0.4); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); }
@Test public void testNumericAttribute() { NumericAttribute attr = NumericAttribute.defaultAttr() .withName("age").withIndex(0).withMin(0.0).withMax(1.0).withStd(0.5).withSparsity(0.4); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); }
@Test public void testNumericAttribute() { NumericAttribute attr = NumericAttribute.defaultAttr() .withName("age").withIndex(0).withMin(0.0).withMax(1.0).withStd(0.5).withSparsity(0.4); Assert.assertEquals(attr.withoutIndex(), Attribute.fromStructField(attr.toStructField())); }