## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Feb 19 18:22

ankurankan on dev

Improves code quality Don't check the extern folder (compare)

• Feb 19 18:22
ankurankan closed #1234
• Feb 19 18:12
codecov[bot] commented #1234
• Feb 19 18:10
codecov[bot] commented #1234
• Feb 19 18:09
codecov[bot] commented #1234
• Feb 19 18:09
codecov[bot] commented #1234
• Feb 19 18:09
ankurankan synchronize #1234
• Feb 19 18:08
Travis ankurankan/pgmpy@98e0c26 (maintain/quality) passed (1253)
• Feb 19 17:57
ankurankan opened #1234
• Feb 17 16:29
garaud edited #1233
• Feb 17 11:33
garaud opened #1233
• Feb 15 04:13
dliberat commented #1166
• Feb 15 04:06
dliberat commented #1166
• Feb 13 12:29
ankurankan labeled #1228
• Feb 13 12:29
ankurankan labeled #1229
• Feb 13 12:29
ankurankan milestoned #1229
• Feb 13 12:29
ankurankan commented #1229
• Feb 13 12:17

ankurankan on dev

Fixed spelling errors in docstr… (compare)

• Feb 13 12:17
ankurankan closed #1232
• Feb 13 12:17
ankurankan commented #1232
moniisek
@moniisek
I am sorry to bother you, but I have an error when trying to run BeliefPropagation. I used the example of Monty Hall problem, and it works with VariableElimination. The error can be seen here https://github.com/moniisek/bayes/blob/master/example.ipynb
abbasi72
@abbasi72
Hi, I have another error TypeError: values: must contain tuples or array-like elements of the form (hashable object, type int)
Danish A. Alvi
Guys, how can I use the 'start' of pgmpy Hill Climb .estimate() ?
Danish A. Alvi
i get this error
ValueError: 'start' should be a BayesianModel with the same variables as the data set, or 'None'.
although all variables are from the data set
Utkarsh
@khalibartan
@DanishAAlvi_twitter Can you share the code?
and data set too
Danish A. Alvi
Sure but how
Let me ipfs the links of both to yoi
Here is the code

hc = HillClimbSearch(train_data, scoring_method=BicScore(train_data)); # Initialise Hill Climbing Estimator
expert = BayesianModel();
('STEO.PAPR_NONOPEC.M', 'WTISPLC'),
('STEO.PAPR_OPEC.M', 'WTISPLC'),
('STEO.PATC_OECD.M', 'WTISPLC'),
('STEO.PATC_NON_OECD.M', 'WTISPLC'),
('STEO.RGDPQ_OECD.M', 'STEO.PATC_OECD.M'),
('STEO.RGDPQ_NONOECD.M', 'STEO.PATC_NON_OECD.M'),
('STEO.FOREX_WORLD.M', 'WTISPLC')
]);

model = hc.estimate(start=expert, max_indegree=6, tabu_length=1000); # Performs local hill climb search

here is the data
Danish A. Alvi
The problem is that the initial 'expert' structure i define does not show up after the Hill Climber
abbasi72
@abbasi72
Hi, in make the bayesian network , I change my string name to numerical ...and in train data ,I have 12 type but in test data, every where find the number of >9 , the run is stoping and show this error :index 11 is out of bounds for axis 0 with size 10
Am I delete the datas >9?????? or are there any solution ?????
abbasi72
@abbasi72
Utkarsh
@khalibartan
@abbasi72 I'm able to understand what are you trying say.
abbasi72
@abbasi72
Location Place Activity
9 3 8
12 3 8
12 2 8
12 2 8
12 3 8
9 3 8
12 3 8
12 0 9
12 0 9
1 1 8
12 3 8
9 3 9
12 3 1
1 1 1
8 1 3
12 0 3
10 0 3
12 0 3
8 1 1
12 3 4
12 3 4
12 2 4
6 2 4
11 2 4
12 2 4
12 0 8
12 0 8
12 3 8
9 3 8
12 3 8
12 0 9
12 0 9
1 1 9
0 1 2
12 3 9
12 3 9
12 2 9
12 2 9
1 1 9
8 1 1
1 1 9
this is a sample of my data set . I have 0...9 item in my class feature ... but in result only see 2 item that predict...
9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 8, 9, 9, 0, 0, 8, 8, 9, 8, 8, 8, 8, 8, 9, 8, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 8, 8, 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 8, 9, 8, 8, 9, 9, 8, 0, 0, 8, 9, 9, 9, 8, 8, 8, 8, 9, 9, 8, 8, 8, 9,
this is a sample of resultlist that predict ....
how can I use from multi class ???
Utkarsh
@khalibartan
@abbasi72 Can you share your code and dataset?
abbasi72
@abbasi72
this is my code

array=['Activity']
trainstart=time()
bic=BicScore(train)

hc=HillClimbSearch(train, scoring_method=bic)
best_model=hc.estimate()
edges=best_model.edges()
model=BayesianModel(edges)
model.fit(train,estimator=BayesianEstimator, prior_type="BDeu")

trainend=time()-trainstart

print "nodes", model.nodes()
print "edges", model.edges()

flag=0
if(set(model.nodes())-set(array) ==set(model.nodes())):
flag=1
elif(set(model.nodes())-set(array) == set(test.columns)):
teststart=time()
print "before"
draw(model.edges(),name,"bic",folder)
result=model.predict(test).values.ravel()
print result
testend=time()-teststart

pred=list(result)
print pred

else:
indicator=list(set(test.columns)-set(model.nodes()))
print indicator
testchange=test.copy()
for f in range(len(indicator)):
print f
del testchange[indicator[f]]
print testchange
teststart=time()
result=model.predict(testchange).values.ravel()
testend=time()-teststart
pred=list(result)

model_data = XMLBIFWriter(model)

if(flag==0):

fscore,accuracy,precision,recall=calscore(resultlist,pred)

draw(model.edges(),name,"bic",folder)

else:
fscore=accuracy=precision=recall=trainend=testend=0
print "fscore :",fscore
print "accuracy :",accuracy
print "precision :",precision
print "recall :",recall
plt.scatter(pred , resultlist)
return fscore,accuracy,precision,recall,trainend,testend

secondtestindicexls1=pd.ExcelFile("D:\OrdonezB_Sensors.xls")
secondtestindicedf1=secondtestindicexls1.parse("OSB")
secondtestindicexls2=pd.ExcelFile("D:\OrdonezA_Sensors.xls")
secondtestindicedf2=secondtestindicexls2.parse("OSA")
secondtestindicexls3=pd.ExcelFile("D:\label.xlsx")
secondtestindicedf3=secondtestindicexls3.parse("Sheet1")
bic(secondtestindicedf1,secondtestindicedf2,"res11","D:\result of run python\",secondtestindicedf3,"D:\result of run python\")

abbasi72
@abbasi72
Danish A. Alvi
@ankurankan Take a look at my project! Thank you for your help all the way with my journey! pgmpy is a wonderful tool with an unlimited potential, and there is a lot more that can be done with it.
odirar
@odirar
@ankurankan hey everyone, newbie to pgmpy, seem to have hit an issue that im not quite sure how to fix. In trying to implement the example on pg 190 of chapter 5, i seem to be getting empty cpds (and model) for some reason. ive provided some screenshots below to help clarify the issue im having. i think this is due to the versions of networkx, scipy, numpy and pandas that im using but im not sure. can you guys please help?
Utkarsh
@khalibartan
@odirar I see, you haven't added any edges in the model. For parameter estimation you must first specify the structure of model.
odirar
@odirar
@khalibartan ahh see ok thanks. How would i go about doing both structure and parameter learning from a dataset? Would i do it as described in /pgmpy/pgmpy_notebook/notebooks/9. Learning Bayesian Networks from Data.ipynb in the repo? or is there perhaps an alternate way of doing this? thanks again. (https://github.com/pgmpy/pgmpy_notebook/blob/master/notebooks/9.%20Learning%20Bayesian%20Networks%20from%20Data.ipynb)
Utkarsh
@khalibartan
@odirar Yes you can you use that. In case if it raises some import error, checkout docs. We have changed directory structure and notebooks example might not have been updated to reflect those.
odirar
@odirar
@khalibartan ahh ok will do, thank you for the insight, much appreciated :)
odirar
@odirar
@khalibartan hey, sorry to bother you again, but i just wanted to ask, is pgmpy (0.1.6) able to compute joint distributions over multiple variable using variable elimination? or is there any other way of doing this atm? (pgmpy/pgmpy#945)
Utkarsh
@khalibartan
@odirar No currently it doesn't.
z2862658714
@z2862658714

Hello there, I'm trying to work out the ProbModelXML file format by generating a file from a working model I created using the method said on the notebook tutorial (https://github.com/pgmpy/pgmpy_notebook/blob/master/notebooks/8.%20Reading%20and%20Writing%20from%20pgmpy%20file%20formats.ipynb)

model_data = get_probmodel_data(valve_model);
writer = ProbModelXMLWriter(model_data=model_data);
print(writer);

and it give me this error

Traceback (most recent call last):
File "/Users/-/Desktop/Valve.py", line 49, in <module>
model_data = get_probmodel_data(valve_model);
File "/Users/-/anaconda3/lib/python3.5/site-packages/pgmpy/readwrite/ProbModelXML.py", line 266, in get_probmodel_data
model_data['probnet']['edges'][str(edge)] = model.edge[edge[0]][edge[1]]
AttributeError: 'BayesianModel' object has no attribute 'edge'

I tried to fix it by modify line 266 in ProbModelXML.py to

model_data['probnet']['edges'][str(edge)] = model.edges[edge[0]][edge[1]]

and now I'm receiving this error:

Traceback (most recent call last):
File "/Users/-/Desktop/Valve.py", line 49, in <module>
model_data = get_probmodel_data(valve_model);
File "/Users/-/anaconda3/lib/python3.5/site-packages/pgmpy/readwrite/ProbModelXML.py", line 266, in get_probmodel_data
model_data['probnet']['edges'][str(edge)] = model.edges[edge[0]][edge[1]]
File "/Users/-/anaconda3/lib/python3.5/site-packages/networkx/classes/reportviews.py", line 930, in getitem
KeyError: 'n'

It seems like there's an error associated with the indexing (model.edges[edge[0]][edge[1]]), but I'm not sure how to fix it. Would appreciate if anyone could help.

Mariangelly Díaz
hi all, new to pgmpy. Is there a way I can produce a flow diagram of my variables within the package?
Matthias Lung
@mmmlung
Hi. I am starting to study PGM (1 week into Courseras course by Daphne Koller). I am playing with my first toy model using PGMPY : ) Is it possible to modify state names ? I came around PGMPY util.state_name but did not quite understand how it works. I would be grateful for a hint ; )
Jonathan Mugan
@jmugan
Are there any examples of people using pgmpy for expectation maximization (EM) for Bayesian networks with hidden variables?
ranxiao89
@ranxiao89
Hi. How can I access the values from a table from a VariableElimination query result?
sphinx-jiang
@sphinx-jiang
Hi guys, do any of you met my issue: import pgmpy fail in jupyter notebook, but could run it in python file?
For details, I have logged issue:pgmpy/pgmpy#1024
@khalibartan jupyter notebook is supported, right?
hcl734
@hcl734

@jmugan

Are there any examples of people using pgmpy for expectation maximization (EM) for Bayesian networks with hidden variables?

Have you found anything on this?
I would also be interested.