How to use the sdgym.synthesizers.utils.DiscretizeTransformer function in sdgym

To help you get started, we’ve selected a few sdgym examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DAI-Lab / SDGym / tests / synthesizers / test_utils.py View on Github external
def test_inverse_transform(self):
        """Transform discrete values back into its original space."""
        # Setup
        n_bins = 2
        instance = DiscretizeTransformer(n_bins=n_bins)
        data = pd.DataFrame({
            'A': [1 / (x + 1) for x in range(10)],
            'B': [x for x in range(10)]
        }).values
        instance.fit(data)
        transformed_data = instance.transform(data)
        expected_result = pd.DataFrame({
            'A': [0.775, 0.325, 0.325, 0.325, 0.325, 0.325, 0.325, 0.325, 0.325, 0.325],
            'B': [2.25, 2.25, 2.25, 2.25, 2.25, 6.75, 6.75, 6.75, 6.75, 6.75]
        })

        # Run
        result = instance.inverse_transform(transformed_data)

        # Check
        np.testing.assert_allclose(result, expected_result)
github DAI-Lab / SDGym / tests / synthesizers / test_utils.py View on Github external
def test_fit(self, kbins_mock):
        # Setup
        n_bins = 2
        instance = DiscretizeTransformer(n_bins=n_bins)
        data = pd.DataFrame({
            'A': [1 / (x + 1) for x in range(10)],
            'B': [x for x in range(10)]
        }).values
        kbins_instance = kbins_mock.return_value

        # Run
        instance.fit(data, [], [])

        # Check
        assert instance.column_index == [0, 1]
        assert instance.discretizer == kbins_instance
        assert instance.meta == [
            {
                'name': 0,
                'type': 'continuous',
github DAI-Lab / SDGym / tests / synthesizers / test_utils.py View on Github external
def test___init__(self):
        """On init attributes are set as None, and n_bins assigned."""
        # Setup
        n_bins = 5

        # Run
        instance = DiscretizeTransformer(n_bins=n_bins)

        # Check
        assert instance.n_bins == 5
        assert instance.meta is None
        assert instance.column_index is None
        assert instance.discretizer is None
github DAI-Lab / SDGym / tests / synthesizers / test_utils.py View on Github external
def test_transform(self):
        """transform continous columns into discrete bins."""
        # Setup
        instance = DiscretizeTransformer(n_bins=2)
        data = pd.DataFrame({
            'A': [x for x in range(10)],
            'B': [2 * x for x in range(10)]
        }).values
        expected_result = np.array([
            [0, 0],
            [0, 0],
            [0, 0],
            [0, 0],
            [0, 0],
            [1, 1],
            [1, 1],
            [1, 1],
            [1, 1],
            [1, 1],
        ])
github DAI-Lab / SDGym / sdgym / synthesizers / clbn.py View on Github external
def fit(self, data, categoricals=tuple(), ordinals=tuple()):
        self.discretizer = DiscretizeTransformer(n_bins=15)
        self.discretizer.fit(data, categoricals, ordinals)
        discretized_data = self.discretizer.transform(data)
        self.model = BayesianNetwork.from_samples(discretized_data, algorithm='chow-liu')