I have a poll result of an election. I want to simulate 50000 draws from a Dirichlet distribution for each poll. But when I run this cell. I get this error but can't figure where I was wrong. Any help would be appreciated.
My code below:
number= 50000
for i in range(len(dAll)):
vector =list(dAll[i][3:7])
random=np.random.dirichlet(vector,number)
postn=[]
for i in range(number): postn.append(random[i].argmax(axis=0))
postn=np.array(postn)
PNPD=100*len(np.where(postn ==0)[0])/number
ProbPNPD.append(PNPD)
PL=100*len(np.where(postn ==1)[0])/number
ProbPL.append(PL)
AD=100*len(np.where(postn ==2)[0])/number
ProbAD.append(AD)
Others=100*len(np.where(postn ==3)[0])/number
ProbOthers.append(Others)
#Probability of victory for each party
setprint=False
if setprint == True:
print('PNPD',PNPD,'%')
print('PL',PL,'%')
print('AD',AD,'%')
print('Others',Others,'%')
Error code:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-16ba25b5e62c> in <module>
4 vector =list(dAll[i][3:7])
5
----> 6 random=np.random.dirichlet(vector,number)
7
8 postn=[]
mtrand.pyx in numpy.random.mtrand.RandomState.dirichlet()
ValueError: alpha <= 0
I don't have any negative numbers in my dataset. check in here
Aucun commentaire:
Enregistrer un commentaire