def test_dataframe_econding_1D(self): """ Test that the encoding/decoding works in 1D """ validator = InputValidator() y = validator.validate_target( pd.DataFrame(data=self.y, dtype=bool), is_classification=True, ) np.testing.assert_array_almost_equal(np.array([0, 1, 0]), y) # Result should not change on a multi call y = validator.validate_target(pd.DataFrame(data=self.y, dtype=bool)) np.testing.assert_array_almost_equal(np.array([0, 1, 0]), y) y_decoded = validator.decode_target(y) np.testing.assert_array_almost_equal(np.array(self.y, dtype=bool), y_decoded) # Now go with categorical data validator = InputValidator() y = validator.validate_target( pd.DataFrame(data=['a', 'a', 'b', 'c', 'a'], dtype='category'), is_classification=True, ) np.testing.assert_array_almost_equal(np.array([0, 0, 1, 2, 0]), y) y_decoded = validator.decode_target(y) self.assertListEqual(['a', 'a', 'b', 'c', 'a'], y_decoded.tolist())
def test_dataframe_econding_2D(self): """ Test that the encoding/decoding works in 2D """ validator = InputValidator() multi_label = pd.DataFrame(np.array([[1, 0, 0, 1], [0, 0, 1, 1], [0, 0, 0, 0]]), dtype=bool) y = validator.validate_target(multi_label, is_classification=True) # Result should not change on a multi call y_new = validator.validate_target(multi_label) np.testing.assert_array_almost_equal(y_new, y) y_decoded = validator.decode_target(y) np.testing.assert_array_almost_equal(y, y_decoded)