[Python] How to get "is_active_trail" in pgmpy working?

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I'm unable to get the code on this webpage to run. I don't see the function "is_active_trail" in pgmpy. Has it been changed or removed? How best to get the code to work?

    from pgmpy.models import BayesianModel
    model = BayesianModel()
    model.add_nodes_from(['rain', 'traffic_jam'])
    model.add_edge('rain', 'traffic_jam')
    model.add_edge('rain', 'traffic_jam')
    model.add_edge('accident', 'traffic_jam')
    model.nodes()
    from pgmpy.factors.discrete import TabularCPD
    cpd_rain = TabularCPD('rain', 2, [[0.4], [0.6]])
    cpd_accident = TabularCPD('accident', 2, [[0.2], [0.8]])
    cpd_traffic_jam = TabularCPD(
    'traffic_jam', 2,
    [[0.9, 0.6, 0.7, 0.1],
    [0.1, 0.4, 0.3, 0.9]],
    evidence=['rain', 'accident'],
    evidence_card=[2, 2])

    model.add_cpds(cpd_rain, cpd_accident, cpd_traffic_jam)
    model.get_cpds()

    model.add_node('long_queues')
    model.add_edge('traffic_jam', 'long_queues')
    cpd_long_queues = TabularCPD('long_queues', 2,
    [[0.9, 0.2],
    [0.1, 0.8]],
    evidence=['traffic_jam'],
    evidence_card=[2])
    model.add_cpds(cpd_long_queues)
    model.add_nodes_from(['getting_up_late',
    'late_for_school'])
    model.add_edges_from(
    [('getting_up_late', 'late_for_school'),
    ('traffic_jam', 'late_for_school')])
    cpd_getting_up_late = TabularCPD('getting_up_late', 2,
    [[0.6], [0.4]])
    cpd_late_for_school = TabularCPD(
    'late_for_school', 2,
    [[0.9, 0.45, 0.8, 0.1],
    [0.1, 0.55, 0.2, 0.9]],
    evidence=['getting_up_late',
    'traffic_jam'],
    evidence_card=[2, 2])
    model.add_cpds(cpd_getting_up_late, cpd_late_for_school)
    model.get_cpds()

    model.check_model()

    model.is_active_trail('accident', 'rain')



    error:

    /usr/local/lib/python3.7/dist-packages/pgmpy/models/BayesianModel.py:10: FutureWarning: BayesianModel has been renamed to BayesianNetwork. Please use BayesianNetwork class, BayesianModel will be removed in future. FutureWarning,


    AttributeError Traceback (most recent call last) in () 46 model.check_model() 47 ---> 48 model.is_active_trail('accident', 'rain')

    AttributeError: 'BayesianModel' object has no attribute 'is_active_trail'

    Continue reading...

Compartilhe esta Página