-
Notifications
You must be signed in to change notification settings - Fork 692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DBNInference - Key Error #1744
Comments
@Rajaram1604 Could you please also add how the |
Defining the DBN Model.
Add Edges
making inference
|
@Rajaram1604 In the model, the variable In [22]: print(loan_dbn_model.get_cpds(('CreditScore', 0)).state_names)
{<DynamicNode(CreditScore, 0) at 0x7a572e539450>: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77]} And because the state that is specified in the evidence ( |
@ankurankan, Yes got it. Actually we are generating random numbers between 500 to 800 for the credit score variable by using numpy and training the model by scale down the values(Algorithms might be scale down the state values). I mean state was internally converted into small values between 1 and 77 by algorithm to reduce the consumption memory and etc.. But while make the inference for the particular evidence, we can not scale down the evidence right. The DynamicInference should scale down the particular evidence which should used for make the inference but we end up with the key error. In this case, Could you please suggest me how we can make the inference for the particular evidence. Note: In Bayesian Network model also, during training phase states are scale down but while make the inference with real evidence like {'creditScore':672} which is working fine, I think may be evidence also scale down the value and making inference perfectly. |
Subject of the issue
Getting Key Error while making inference by using DBNInference
Your environment
Steps to reproduce
Fitting the below DataFrame data with DynamicBayesian Network model
Expected behaviour
Making the inference by using DBNInference which I have fitted the model with the above mentioned data , example evidence {("CreditScore", 0): 672}. Expected some results but getting the error. below the code snippet
`
dbn_inference = DBNInference(loan_dbn_model)
results = dbn_inference.query(variables=[("LoanApproval", 0)], evidence={("CreditScore", 0): 672})
`
Actual behaviour
Getting the error below error while making the inference. But while am making the inference with evidence={("CreditScore", 0): 0}) its working, We know that internally scaling down the data and fitting the model. But while make the inference need to use a real data which we have fitted the model.
results = dbn_inference.query(variables=[("LoanApproval", 0)], evidence={("CreditScore", 0): 672})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\pgmpy\inference\dbn_inference.py", line 475, in query
return self.backward_inference(variables, evidence)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\pgmpy\inference\dbn_inference.py", line 385, in backward_inference
potential_dict = self.forward_inference(variables, evidence, "potential")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\pgmpy\inference\dbn_inference.py", line 281, in forward_inference
initial_factor = self._get_factor(start_bp, evidence_0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\pgmpy\inference\dbn_inference.py", line 204, in get_factor
final_factor.reduce([(var, evidence[var])])
File "C:\Python311\Lib\site-packages\pgmpy\factors\discrete\DiscreteFactor.py", line 570, in reduce
phi.values = phi.values[tuple(slice)]
~~~~~~~~~~^^^^^^^^^^^^^^^
IndexError: index 672 is out of bounds for axis 0 with size 81
The text was updated successfully, but these errors were encountered: