+
    ÖÇÜh‡1  ã                   óL   € ^ RI Ht  ! R R4      tR t]R8X  d
   ]! 4        R# R# )é    )ÚFreqDistc                   óp   a € ] tR t^t o RtRR ltR tR tR tRR lt	R t
R	 tR
 tRR ltRR ltRtV tR# )ÚConfusionMatrixan  
The confusion matrix between a list of reference values and a
corresponding list of test values.  Entry *[r,t]* of this
matrix is a count of the number of times that the reference value
*r* corresponds to the test value *t*.  E.g.:

    >>> from nltk.metrics import ConfusionMatrix
    >>> ref  = 'DET NN VB DET JJ NN NN IN DET NN'.split()
    >>> test = 'DET VB VB DET NN NN NN IN DET NN'.split()
    >>> cm = ConfusionMatrix(ref, test)
    >>> print(cm['NN', 'NN'])
    3

Note that the diagonal entries *Ri=Tj* of this matrix
corresponds to correct values; and the off-diagonal entries
correspond to incorrect values.
c                ó  aaa€ \        V4      \        V4      8w  d   \        R4      hV'       d;   \        V4      o\        V4      oVV3R lp\        \	        W,           4      VR7      pM\        \	        W,           4      4      p\        V4       UUu/ uF  w  rgWvbK	  	  pppV U	u. uF  q• U	u. uF  p	^ NK  	  up	NK  	  up	o^ p
\        W4       FS  w  r¼SW‹,          ,          WŒ,          ;;,          ^,          uu&   \        V
SW‹,          ,          WŒ,          ,          4      p
KU  	  WPn        W€n	        SV n
        W n        \        V4      V n        \        V3R l\        \        V4      4       4       4      V n        R# u uppi u up	i u up	i )aw  
Construct a new confusion matrix from a list of reference
values and a corresponding list of test values.

:type reference: list
:param reference: An ordered list of reference values.
:type test: list
:param test: A list of values to compare against the
    corresponding reference values.
:raise ValueError: If ``reference`` and ``length`` do not have
    the same length.
z Lists must have the same length.c                 ó4   <€ SV ,          SV ,          ,           ) # ©N© )ÚvÚ	ref_fdistÚ
test_fdists   &€€Ú>/usr/lib/python3/dist-packages/nltk/metrics/confusionmatrix.pyÚkeyÚ%ConfusionMatrix.__init__.<locals>.key5   s   ø€ Ø" 1�¨
°1­Õ5Ð6Ð6ó    ©r   c              3   óD   <"  € T F  pSV,          V,          x € K  	  R # 5ir   r	   )Ú.0ÚiÚ	confusions   & €r   Ú	<genexpr>Ú+ConfusionMatrix.__init__.<locals>.<genexpr>Q   s   øé € ÐHÑ5G°˜I a�L¨ŸOšOÓ5Gùs   ƒ N)ÚlenÚ
ValueErrorr   ÚsortedÚsetÚ	enumerateÚzipÚmaxÚ_valuesÚ_indicesÚ
_confusionÚ	_max_confÚ_totalÚsumÚrangeÚ_correct)ÚselfÚ	referenceÚtestÚsort_by_countr   Úvaluesr   ÚvalÚindicesÚ_Úmax_confÚwÚgr   r   r   s   &&&&         @@@r   Ú__init__ÚConfusionMatrix.__init__    s@  ú€ ô ˆy‹>œS ›YÔ&ÜÐ?Ó@Ð@÷ Ü  Ó+ˆIÜ! $›ˆJö7ô œC 	Õ 0Ó1°sÔ;‰FäœC 	Õ 0Ó1Ó2ˆFô +4°FÔ*;Ô<Ñ*;™h˜q�3’6Ñ*;ˆÑ<ñ 39Ó9±&¨Q Ó(¡˜A“a¡Ô(±&Ñ9ˆ	ØˆÜ˜	Ö(‰DˆAØ�g•jÕ! '¥*×-°Õ2Ó-Ü˜8 Y¨w­zÕ%:¸7½:Õ%FÓGŠHñ )ð
 ŒàŒà#ˆŒà!Œä˜)“nˆŒäÔH´U¼3¸v»;Ô5GÓHÓHˆŽùó) =ùò )ùÒ9s   ÂE>Â&F	Â.F
Â9F	ÆF	c                óŠ   € Vw  r#V P                   V,          pV P                   V,          pV P                  V,          V,          # )ze
:return: The number of times that value ``li`` was expected and
value ``lj`` was given.
:rtype: int
)r    r!   )r'   Úli_lj_tupleÚliÚljr   Újs   &&    r   Ú__getitem__ÚConfusionMatrix.__getitem__S   s;   € ð ‰ˆØ�M‰M˜"ÕˆØ�M‰M˜"ÕˆØ�‰˜qÕ! !Õ$Ð$r   c                ó<   € R V P                    RV P                   R2# )z<ConfusionMatrix: Ú/z	 correct>)r&   r#   ©r'   s   &r   Ú__repr__ÚConfusionMatrix.__repr__^   s   € Ø# D§M¡M ?°!°D·K±K°=À	ÐJÐJr   c                ó"   € V P                  4       # r   )Úpretty_formatr=   s   &r   Ú__str__ÚConfusionMatrix.__str__a   s   € Ø×!Ñ!Ó#Ð#r   Nc           	     óf  a € S P                   pS P                  pV'       d   \        VV 3R lR7      pV'       d   VRV pV'       d   V Uu. uF  pRV,          NK  	  ppM3\        \	        V4      4       U	u. uF  p	\        V	^,           4      NK  	  pp	\        R V 4       4      p
R\        V
4      ,           R,           pV'       d   ^pRpR	pMN\	        \        S P                  4      4      pR\        V4      ,           R
,           pRV^,
          ,          R,           pRp\        V
4       F˜  pVRV
,          R,           ,          pV Fo  pVV
\	        V4      ,
          8¼  d?   W÷VV
,
          \	        V4      ,           ,          P                  V^,           4      ,          pKX  VRV^,           ,          ,          pKq  	  VR,          pKš  	  VRP                  RV
,          RV^,           \	        V4      ,          ,          4      ,          p\        W†4       EF  w  ppS P                  V,          pWûV,          ,          pV FÖ  pS P                  V,          pVV,          V,          ^ 8X  d
   Wþ,          pM[V'       d7   WýRVV,          V,          ,          S P                  ,          ,          ,          pMWýVV,          V,          ,          ,          pVV8X  d8   VP                  R4      pVRV R,           VV^,           R ,           R,           pKÍ  VR,          pKØ  	  VR,          pEK  	  VRP                  RV
,          RV^,           \	        V4      ,          ,          4      ,          pVR,          pV'       g8   VR,          p\        V4       F  w  ppVRV^,           V3,          ,          pK!  	  V# u upi u up	i )a.  
:return: A multi-line string representation of this confusion matrix.
:type truncate: int
:param truncate: If specified, then only show the specified
    number of values.  Any sorting (e.g., sort_by_count)
    will be performed before truncation.
:param sort_by_count: If true, then sort by the count of each
    label in the reference data.  I.e., labels that occur more
    frequently in the reference label will be towards the left
    edge of the matrix, and labels that occur less frequently
    will be towards the right edge.

@todo: add marginals?
c                 ó`   <€ \        SP                  SP                  V ,          ,          4      ) # r   ©r$   r!   r    ©r
   r'   s   &€r   Ú<lambda>Ú/ConfusionMatrix.pretty_format.<locals>.<lambda>~   s   ø€ ¤s¨4¯?©?¸4¿=¹=ÈÕ;KÕ+LÓ'MÑ&Mr   r   Nz%sc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   ©r   )r   r,   s   & r   r   Ú0ConfusionMatrix.pretty_format.<locals>.<genexpr>Š   s   é € Ð9©= C”s˜3—x�x«=ùó   ‚Ú%zs | z%5.1f%%z     .ÚdÚ Ú.Ú z |z |
z	{}-+-{}+
Ú-g      Y@Ú<Ú>z|
z(row = reference; col = test)
úValue key:
z%6d: %s
)r!   r   r   r%   r   Ústrr   Úreprr"   ÚrjustÚformatr   r    r#   Úrfindr   )r'   Úshow_percentsÚvalues_in_chartÚtruncater*   r   r+   r,   Úvalue_stringsÚnÚvaluelenÚvalue_formatÚentrylenÚentry_formatÚzerostrÚsr   r6   r7   r8   Ú	prevspaceÚvalues   f&&&&                 r   rA   ÚConfusionMatrix.pretty_formatd   s  ø€ ð* —O‘Oˆ	à—‘ˆßÜØÔMôˆF÷ Ø˜I˜XÐ&ˆFçÙ39Ó:±6¨C˜T CŸZ˜Z±6ˆMÐ:ˆMä16´s¸6³{Ô1CÓDÑ1C¨AœS  Q¥žZÑ1CˆMÐDô Ñ9©=Ó9Ó9ˆØœT (›^Õ+¨fÕ4ˆçØˆHØ$ˆLØ‰Gäœ4 §¡Ó/Ó0ˆHØ¤ h£Õ/°#Õ5ˆLØ˜X¨�\Õ*¨SÕ0ˆGð ˆÜ�x–ˆAØ�#˜•. DÕ(Õ(ˆAÛ$�Ø˜¤3 s£8Õ+Ô+Ø˜Q �\¬C°«HÕ4Õ5×;Ñ;¸HÀq½LÓIÕI’Aà˜ ¨1¥Õ-Õ-’Añ	 %ð
 ��KŠAñ !ð 	
ˆ\× Ñ   x¥°¸ÀA½ÌÈVËÕ8TÕ1UÓVÕVˆô ˜=×1‰GˆC�Ø—‘˜bÕ!ˆAØ Õ#Õ#ˆAÛ�Ø—M‘M "Õ%�Ø˜Q•< •? aÔ'Ø•L‘Aß"Ø¨°¸1µ¸aµÕ)@À4Ç;Á;Õ)NÕOÕO‘Aà¨	°!­°Q­Õ7Õ7�AØ˜”6Ø !§¡¨£�IØ˜*˜9˜¨Õ+¨a°	¸Aµ°Ð.@Õ@À3ÕF’Aà˜•H’Añ ð ��J‹Añ! 2ð& 	
ˆ\× Ñ   x¥°¸ÀA½ÌÈVËÕ8TÕ1UÓVÕVˆð 	
Ð.Õ.ˆßØ�ÕˆAÜ% fÖ-‘��5Ø�[ A¨¥E¨5 >Õ1Õ1’ñ .ð ˆùòy ;ùâDs   ÁN)Á7N.c           
     ó6  € V P                   pR p\        \        \        V4      ^,
          4      4      pR\        V4      ,           R,           pTRP                  \	        \        V4      4       Uu. uF  qTWQV,          3,          NK  	  up4      ,          pV# u upi )rV   z  %zd: %s
rR   )r   r   rX   Újoinr%   )r'   r+   rW   ÚindexlenÚ
key_formatr   s   &     r   r   ÚConfusionMatrix.keyÃ   s~   € Ø—‘ˆØˆÜ”tœC ›K¨!�OÓ,Ó-ˆØœT (›^Õ+¨iÕ7ˆ
Øˆr�w‰w¼UÄ3ÀvÃ;Ô=OÓPÑ=O¸ a°­ ^×3Ð3Ñ=OÑPÓQÕQˆØˆ
ùò Qs   Á.B
c                ó~   a a€ S SS3,          p\        V V3R lS P                   4       4      pV^ 8X  d   R# W#,          # )a©  Given a value in the confusion matrix, return the recall
that corresponds to this value. The recall is defined as:

- *r* = true positive / (true positive + false positive)

and can loosely be considered the ratio of how often ``value``
was predicted correctly relative to how often ``value`` was
the true result.

:param value: value used in the ConfusionMatrix
:return: the recall corresponding to ``value``.
:rtype: float
c              3   ó:   <"  € T F  pSSV3,          x € K  	  R # 5ir   r	   )r   Ú
pred_valuer'   rh   s   & €€r   r   Ú)ConfusionMatrix.recall.<locals>.<genexpr>Ü   s   øé € ÐK¹l°
�D˜ 
Ð*×+Ò+»lùó   ƒç        ©r$   r   )r'   rh   ÚTPÚTP_FNs   ff  r   ÚrecallÚConfusionMatrix.recallË   ó9   ù€ ð �%˜�,ÕˆäÕK¸d¿lºlÓKÓKˆØ�AŒ:ÙØ�zÐr   c                ó~   a a€ S SS3,          p\        V V3R lS P                   4       4      pV^ 8X  d   R# W#,          # )a²  Given a value in the confusion matrix, return the precision
that corresponds to this value. The precision is defined as:

- *p* = true positive / (true positive + false negative)

and can loosely be considered the ratio of how often ``value``
was predicted correctly relative to the number of predictions
for ``value``.

:param value: value used in the ConfusionMatrix
:return: the precision corresponding to ``value``.
:rtype: float
c              3   ó:   <"  € T F  pSVS3,          x € K  	  R # 5ir   r	   )r   Ú
real_valuer'   rh   s   & €€r   r   Ú,ConfusionMatrix.precision.<locals>.<genexpr>ò   s   øé € ÐK¹l°
�D˜ UÐ*×+Ò+»lùrs   rt   ru   )r'   rh   rv   ÚTP_FPs   ff  r   Ú	precisionÚConfusionMatrix.precisioná   rz   r   c                ó®   € V P                  V4      pV P                  V4      pVR8X  g   VR8X  d   R# RW#,          ^V,
          V,          ,           ,          # )aç  
Given a value used in the confusion matrix, return the f-measure
that corresponds to this value. The f-measure is the harmonic mean
of the ``precision`` and ``recall``, weighted by ``alpha``.
In particular, given the precision *p* and recall *r* defined by:

- *p* = true positive / (true positive + false negative)
- *r* = true positive / (true positive + false positive)

The f-measure is:

- *1/(alpha/p + (1-alpha)/r)*

With ``alpha = 0.5``, this reduces to:

- *2pr / (p + r)*

:param value: value used in the ConfusionMatrix
:param alpha: Ratio of the cost of false negative compared to false
    positives. Defaults to 0.5, where the costs are equal.
:type alpha: float
:return: the F-measure corresponding to ``value``.
:rtype: float
rt   g      ð?)r€   rx   )r'   rh   ÚalphaÚpÚrs   &&&  r   Ú	f_measureÚConfusionMatrix.f_measure÷   sJ   € ð2 �N‰N˜5Ó!ˆØ�K‰K˜ÓˆØ�Œ8�q˜C”xÙØ�e•i 1 u¥9°¥/Õ1Õ2Ð2r   c                ó„  a € S P                   pV'       d   \        VV 3R lR7      pV'       d   VRV p\        \        R V 4       4      ^4      pRV^,
          ,           RRV,           R2pV FM  pVVR	V 2 R
S P                  V4      R R
S P	                  V4      R R
S P                  WqR7      R R2,          pKO  	  V# )ag  
Tabulate the **recall**, **precision** and **f-measure**
for each value in this confusion matrix.

>>> reference = "DET NN VB DET JJ NN NN IN DET NN".split()
>>> test = "DET VB VB DET NN NN NN IN DET NN".split()
>>> cm = ConfusionMatrix(reference, test)
>>> print(cm.evaluate())
Tag | Prec.  | Recall | F-measure
----+--------+--------+-----------
DET | 1.0000 | 1.0000 | 1.0000
 IN | 1.0000 | 1.0000 | 1.0000
 JJ | 0.0000 | 0.0000 | 0.0000
 NN | 0.7500 | 0.7500 | 0.7500
 VB | 0.5000 | 1.0000 | 0.6667
<BLANKLINE>

:param alpha: Ratio of the cost of false negative compared to false
    positives, as used in the f-measure computation. Defaults to 0.5,
    where the costs are equal.
:type alpha: float
:param truncate: If specified, then only show the specified
    number of values. Any sorting (e.g., sort_by_count)
    will be performed before truncation. Defaults to None
:type truncate: int, optional
:param sort_by_count: Whether to sort the outputs on frequency
    in the reference label. Defaults to False.
:type sort_by_count: bool, optional
:return: A tabulated recall, precision and f-measure string
:rtype: str
c                 ó`   <€ \        SP                  SP                  V ,          ,          4      ) # r   rF   rG   s   &€r   rH   Ú*ConfusionMatrix.evaluate.<locals>.<lambda>:  s    ø€ ¬s°4·?±?À4Ç=Á=ÐQRÕCSÕ3TÓ/UÑ.Ur   r   Nc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   rK   )r   Útags   & r   r   Ú+ConfusionMatrix.evaluate.<locals>.<genexpr>>  s   é € Ð :±T¨c¤ S§ ³TùrM   rP   z"Tag | Prec.  | Recall | F-measure
rS   z -+--------+--------+-----------
rU   z | z<6.4f)rƒ   z.4fÚ
)r   r   r   r€   rx   r†   )r'   rƒ   r^   r*   ÚtagsÚtag_column_lenrf   rŒ   s   f&&&    r   ÚevaluateÚConfusionMatrix.evaluate  sã   ø€ ð@ �|‰|ˆ÷ Ü˜$Ô$UÔVˆDßØ˜	˜�?ˆDäœSÑ :±TÓ :Ó:¸AÓ>ˆð �n qÕ(Õ)Ð*Ð*MØ�^Õ#Ð$Ð$EðGð 	
ó ˆCØØ�q˜Ð(Ð(Ð)¨Ø—>‘> #Ó& uÐ-¨SØ—;‘;˜sÓ# EÐ*¨#Ø—>‘> #�>Ó3°CÐ8¸ð<õŠAñ ð ˆr   )r!   r&   r    r"   r#   r   )F)FTNF)ç      à?)r“   NF)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r2   r9   r>   rB   rA   r   rx   r€   r†   r‘   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      sF   ø‡ € ñô$1Iòf	%òKò$ô]ò~òò,ô,3÷>9ò 9r   r   c                  óB  € R P                  4       p RP                  4       p\        RV 4       \        RV4       \        R4       \        \        W4      4       \        \        W4      P                  RR7      4       \        \        W4      P	                  R4      4       R# )	z DET NN VB DET JJ NN NN IN DET NNz DET VB VB DET NN NN NN IN DET NNzReference =z	Test    =zConfusion matrix:T)r*   ÚVBN)ÚsplitÚprintr   rA   rx   )r(   r)   s     r   Údemor    R  s{   € Ø2×8Ñ8Ó:€IØ-×3Ñ3Ó5€DÜ	ˆ-˜Ô#Ü	ˆ+�tÔÜ	Ð
ÔÜ	Œ/˜)Ó
*Ô+Ü	Œ/˜)Ó
*×
8Ñ
8ÀtÐ
8Ó
LÔMä	Œ/˜)Ó
*×
1Ñ
1°$Ó
7Ö8r   Ú__main__N)Únltk.probabilityr   r   r    r”   r	   r   r   Ú<module>r£      s0   ðõ &÷Bñ BòJ
	9ð ˆzÔÙ†Fñ r   