Python library for learning the graphical structure of Bayesian networks, parameter learning, inference and sampling methods.
OTHER License
Published by erdogant about 2 years ago
Published by erdogant about 2 years ago
Published by erdogant over 2 years ago
Published by erdogant over 2 years ago
predict
functionalityscoretype
to parameter_learning
Published by erdogant over 2 years ago
parameter_learning
import bnlearn as bn
DAG = bn.import_DAG('water', verbose=0)
# Sampling
df = bn.sampling(DAG, n=1000)
# Parameter learning
model = bn.parameter_learning.fit(DAG, df, smooth=None)
Published by erdogant over 2 years ago
networkx
. The version of networkx
should be >= 2.7.1import bnlearn as bn
df = bn.import_example('asia')
model = bn.structure_learning.fit(df)
# Plot
bn.plot(model)
# Plot with different layouts
bn.plot(model, params_static={'layout':'spectral_layout'})
bn.plot(model, params_static={'layout':'planar_layout'})
bn.plot(model, params_static={'layout':'kamada_kawai_layout'})
bn.plot(model, params_static={'layout':'spring_layout'})
bn.plot(model, params_static={'layout':'circular_layout', "figsize": (15, 10)})
Published by erdogant over 2 years ago
pyvis
to setup file and requirements.Published by erdogant over 2 years ago
bn.print_CPD()
Published by erdogant over 2 years ago
Published by erdogant over 2 years ago
vec2df
import bnlearn as bn
# Load large example with source-target edges
vec = bn.import_example("stormofswords")
# Convert to dataframe
df = bn.vec2df(vec['source'], vec['target'], weights=vec['weight'])
Published by erdogant over 2 years ago
Example vec2df:
import bnlearn as bn
source=['Cloudy','Cloudy','Sprinkler','Rain']
target=['Sprinkler','Rain','Wet_Grass','Wet_Grass']
weights=[1,2,1,3]
# Convert into sparse datamatrix
df = bn.vec2df(source, target, weights=weights)
# Cloudy Rain Sprinkler Wet_Grass
# 0 True False True False
# 1 True True False False
# 2 True True False False
# 3 False False True True
# 4 False True False True
# 5 False True False True
# 6 False True False True
Published by erdogant almost 3 years ago
Published by erdogant almost 3 years ago
bnlearn.independence_test
functionality that allows to compute edge strength# Example:
# Load asia DAG
df = bn.import_example(data='alarm')
# Structure learning of sampled dataset
model = bn.structure_learning.fit(df)
# Compute edge strength with the chi_square test statistic. Set prune=True to remove the none-significant edges.
model = bn.independence_test(model, df, test='chi_square', prune=False)
# Make plot
bn.plot(model)
Published by erdogant almost 3 years ago
Published by erdogant almost 3 years ago
Let me know if there are accidental new bugs introduced!
Published by erdogant almost 3 years ago
Published by erdogant almost 3 years ago
Published by erdogant almost 3 years ago
Published by erdogant almost 3 years ago
Published by erdogant about 3 years ago