jmschrei / pomegranate

Fast, flexible and easy to use probabilistic modelling in Python.
http://pomegranate.readthedocs.org/en/latest/
MIT License
3.38k stars 590 forks source link

Why Bayesian network requires non-negative data #1111

Open xiuwenibm opened 4 months ago

xiuwenibm commented 4 months ago

I created a BayesianNetwork and fit the data:

model = BayesianNetwork(algorithm="chow-liu", max_parents=max_parents) model.fit(data)

In fit method, it calls _learn_structure method, however, in _learn_structure, it does the parameter check: X = _check_parameter(_cast_as_tensor(X), "X", min_value=0, ndim=2, dtypes=(torch.int32, torch.int64))

The min_value = 0, so if there is a negtive value in my dataset, the check will raise an error. But BayesianNetwork should work for negative values too.

jmschrei commented 4 months ago

Currently, the implemented Bayesian networks have to be categorical. This means that the data have to correspond to integer categories ranging from 0 to n-1 (inclusive) when there are n categories, and so are non-negative.

xiuwenibm commented 4 months ago

Got it! Thanks! So for continuous values, I just need to bin them and then apply Bayesian networks