Comments (4)
A new function set_cpd
has been implemented in this commit and will be made available in the next release.
from causalnex.
Hi @helderc
It is possible to update the CPT after some serious pandas gymnastics - have a look at such function below. Essentially you will have to recreate a multi-index dataframe of the same format as the BN.cpds[node_you_want_to_change]
@benhorsburgh - An implementation to update CPTs of same nature as pomegranate library would be welcome! - https://pomegranate.readthedocs.io/en/latest/Distributions.html
def _set_CPDS(bn):
'''
Updates and returns the bayesian network with updated CPDs
:param bn:
:return:
'''
# Overwrite BN CPDS with those saved
for node, cpd in bn.cpds.items():
df = pd.read_csv(f"./data/output/CPDS/{node}.csv")
# For DataFrames only containing priors (node_name, value)
if len(df.columns) == 2:
df = df.set_index(node)
df.columns = ['']
else:
df = df.pivot_table(index=node, columns=[i for i in df.columns if i not in [node, 'value']], values='value')
if len(df.columns.names) == 1:
df.columns = pd.MultiIndex(levels=[df.columns.values], codes=[range(3)], names=[df.columns.names])
# Update the CPDS with those specified
bn.cpds[node].update(df)
return bn
from causalnex.
Hey @helderc. At present, there isn't a way to manually define them.
I agree it would be interesting to have this feature, and I think it would be relatively easy to add. We're currently looking into a possible implementation.
Out of curiosity, what sort of things would you use this to explore? This may help inform an implementation.
from causalnex.
Hi @benhorsburgh.
I would like to use this feature mostly as a didactic way to implement a Bayes net and do some inference.
So basically, would be to perform calculations based on made-up examples.
Thank you all.
from causalnex.
Related Issues (20)
- the same process different results HOT 1
- Can't install causalnex using poetry on new Apple M1 chip HOT 1
- EMSingleLatentVariable is producing random error at random times HOT 1
- Add GitHub Actions installation jobs across environments HOT 1
- Unsuitability of Notears for causal inference HOT 3
- How do I save the fitted Bayesian model locally HOT 2
- get_target_subgraph function is not working HOT 1
- vis.show() UnicodeEncodeError HOT 9
- Find out the number of cycles HOT 1
- 01_first_tutorial.ipynb hangs on `from_pandas(...)`
- [Feature Request]: Support pandas >= 2.0
- [Bug]: Pycharm cannot use causalnex HOT 1
- [help]: I am unable to display images while using viz. show()
- [Feature Request]: batch_size for notears with GPU
- [Bug]: Inconsistent Use of CUDA Devices When Using GPU with notears
- [Bug]: Classification Model always predicting 0 HOT 1
- [Bug]: fix typo in 04_user_guide.md
- [Feature Request]: Support Python 3.11
- [Bug]: causalnex.discretiser.MDLPSupervisedDiscretiserMethod does not import MDLP
- An issue with plotting[Bug]: HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from causalnex.