Hello, I am trying to get the diagnostic values from my model using the pysmile wrapper. But currently, I am struggling on figuring out how to do this.
Based on the answers below, I have generated this code so far:
Code: Select all
net = pysmile.Network()
net.read_file("Survival.xdsl")
for i in range(len(current_features)):
net.set_evidence(current_features[i], mapped_values[current_features[i]])
net.update_beliefs()
beliefs = net.get_node_value("SURVIVAL_12")
# Iterate through the outcomes
for i in range(0, len(beliefs)):
outcome = net.get_outcome_id("SURVIVAL_12", i)
probability = beliefs[i]
print(f"{outcome} = {probability}")
net.set_node_diag_type("SURVIVAL_12", pysmile.NodeDiagType.FAULT)
net.set_fault_outcome("SURVIVAL_12", "Yes", True)
for i in range(len(current_features)):
net.set_node_diag_type(current_features[i], pysmile.NodeDiagType.OBSERVATION)
diag_net = pysmile.DiagNetwork(net)
diag_result = diag_net.update()
diagnostic_values = diag_result.get_node_value("SURVIVAL_12")
for i, outcome in enumerate(diag_net.get_outcome_ids("SURVIVAL_12")):
value = diagnostic_values[i]
print(f"{outcome}: {value}")
Running this code, I get the following output:
Code: Select all
No = 0.0028522731146181338
Yes = 0.9971477268853817
Traceback (most recent call last):
File "pysmiletest.py", line 151, in <module>
test()
File "pysmiletest.py", line 144, in test
diagnostic_values = diag_result.get_node_value("SURVIVAL_12")
AttributeError: 'pysmile.DiagResults' object has no attribute 'get_node_value'
Any suggestions on how I can access the diag_result and/or if I am doing something wrong in the code here?
The current features in the model I have include several health-related variables such as heart rate, gender, age, blood pressure, etc., and these variables all predict Survival.
Any insight and help would be appreciated!