我正在尝试使用pyitlib
软件包为python估计3个变量的条件熵。
但我遇到错误
我的代码:
import numpy as np
from pyitlib import discrete_random_variable as drv
X=[0,1,1,0,1,0,1,0,0,1,0,0]
Y=[0,1,1,0,0,0,1,0,0,1,1,0]
Z=[1,0,0,1,1,0,0,1,1,0,0,1]
a=drv.entropy_conditional('X','Y','Z')
print(a)
错误:
Warning (from warnings module):
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\lib\arraysetops.py", line 518
mask &= (ar1 != a)
FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
Traceback (most recent call last):
File "C:\Users\user\Downloads\testing.py", line 8, in <module>
a=drv.entropy_conditional('X','Y','Z')
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pyitlib\discrete_random_variable.py", line 3495, in entropy_conditional
fill_value_Alphabet_Y))
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pyitlib\discrete_random_variable.py", line 4689, in _map_observations_to_integers
Fill_values = [L.transform(np.atleast_1d(f)) for f in Fill_values]
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pyitlib\discrete_random_variable.py", line 4689, in <listcomp>
Fill_values = [L.transform(np.atleast_1d(f)) for f in Fill_values]
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\preprocessing\label.py", line 257, in transform
_, y = _encode(y, uniques=self.classes_, encode=True)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\preprocessing\label.py", line 110, in _encode
return _encode_numpy(values, uniques, encode)
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\preprocessing\label.py", line 53, in _encode_numpy
% str(diff))
ValueError: y contains previously unseen labels: [-1]
我正在尝试使用以下公式查找X,Y,Z(上面给出的值)之间的条件互信息:
I(X;Y|Z)=H(X,Z)+H(Y,Z)-H(X,Y,Z)-H(Z)
期望的条件互助信息值为= 0.011