@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 testAttributeType() { AttributeType numericType = AttributeType.Numeric(); AttributeType nominalType = AttributeType.Nominal(); AttributeType binaryType = AttributeType.Binary(); Assert.assertEquals(numericType, NumericAttribute.defaultAttr().attrType()); Assert.assertEquals(nominalType, NominalAttribute.defaultAttr().attrType()); Assert.assertEquals(binaryType, BinaryAttribute.defaultAttr().attrType()); }
@Test public void testAttributeType() { AttributeType numericType = AttributeType.Numeric(); AttributeType nominalType = AttributeType.Nominal(); AttributeType binaryType = AttributeType.Binary(); Assert.assertEquals(numericType, NumericAttribute.defaultAttr().attrType()); Assert.assertEquals(nominalType, NominalAttribute.defaultAttr().attrType()); Assert.assertEquals(binaryType, BinaryAttribute.defaultAttr().attrType()); }
@Test public void testAttributeType() { AttributeType numericType = AttributeType.Numeric(); AttributeType nominalType = AttributeType.Nominal(); AttributeType binaryType = AttributeType.Binary(); Assert.assertEquals(numericType, NumericAttribute.defaultAttr().attrType()); Assert.assertEquals(nominalType, NominalAttribute.defaultAttr().attrType()); Assert.assertEquals(binaryType, BinaryAttribute.defaultAttr().attrType()); }