def test_one_hot_encoder_deserialize_transforms_to_np(): encoder = encoders.OneHotEncoder() encoder.fit(np.array(["a", "b", "a"])) encoder = encoders.deserialize(encoders.serialize(encoder)) one_hot = encoder.encode(np.array(["a"])) assert np.array_equal(one_hot, [[1, 0]]) or np.array_equal(one_hot, [[0, 1]])
def from_config(cls, config): obj = super().from_config(config) obj.label_encoder = encoders.deserialize(config['encoder'])
def from_config(cls, config): encoder = config.pop("encoder") obj = super().from_config(config) obj.label_encoder = encoders.deserialize(encoder) return obj