+
    ÖÇÜhÉ(  ã                   óv   € R t ^ RIHt ^ RIHt ^ RIHtHtHtH	t	  ! R R]4      t
R t]R8X  d
   ]! 4        R# R# )	aê  
A classifier based on the Naive Bayes algorithm.  In order to find the
probability for a label, this algorithm first uses the Bayes rule to
express P(label|features) in terms of P(label) and P(features|label):

|                       P(label) * P(features|label)
|  P(label|features) = ------------------------------
|                              P(features)

The algorithm then makes the 'naive' assumption that all features are
independent, given the label:

|                       P(label) * P(f1|label) * ... * P(fn|label)
|  P(label|features) = --------------------------------------------
|                                         P(features)

Rather than computing P(features) explicitly, the algorithm just
calculates the numerator for each label, and normalizes them so they
sum to one:

|                       P(label) * P(f1|label) * ... * P(fn|label)
|  P(label|features) = --------------------------------------------
|                        SUM[l]( P(l) * P(f1|l) * ... * P(fn|l) )
)Údefaultdict)ÚClassifierI)ÚDictionaryProbDistÚELEProbDistÚFreqDistÚsum_logsc                   óf   a € ] tR t^+t o RtR tR tR tR tRR lt	RR lt
]]3R l4       tR	tV tR
# )ÚNaiveBayesClassifieraÌ  
A Naive Bayes classifier.  Naive Bayes classifiers are
paramaterized by two probability distributions:

  - P(label) gives the probability that an input will receive each
    label, given no information about the input's features.

  - P(fname=fval|label) gives the probability that a given feature
    (fname) will receive a given value (fval), given that the
    label (label).

If the classifier encounters an input with a feature that has
never been seen with any label, then rather than assigning a
probability of 0 to all labels, it will ignore that feature.

The feature value 'None' is reserved for unseen feature values;
you generally should not use 'None' as a feature value for one of
your own features.
c                óZ   € Wn         W n        \        VP                  4       4      V n        R# )aÍ  
:param label_probdist: P(label), the probability distribution
    over labels.  It is expressed as a ``ProbDistI`` whose
    samples are labels.  I.e., P(label) =
    ``label_probdist.prob(label)``.

:param feature_probdist: P(fname=fval|label), the probability
    distribution for feature values, given labels.  It is
    expressed as a dictionary whose keys are ``(label, fname)``
    pairs and whose values are ``ProbDistI`` objects over feature
    values.  I.e., P(fname=fval|label) =
    ``feature_probdist[label,fname].prob(fval)``.  If a given
    ``(label,fname)`` is not a key in ``feature_probdist``, then
    it is assumed that the corresponding P(fname=fval|label)
    is 0 for all values of ``fval``.
N)Ú_label_probdistÚ_feature_probdistÚlistÚsamplesÚ_labels)ÚselfÚlabel_probdistÚfeature_probdists   &&&Ú:/usr/lib/python3/dist-packages/nltk/classify/naivebayes.pyÚ__init__ÚNaiveBayesClassifier.__init__@   s%   € ð"  .ÔØ!1ÔÜ˜N×2Ñ2Ó4Ó5ˆŽó    c                ó   € V P                   # ©N)r   )r   s   &r   ÚlabelsÚNaiveBayesClassifier.labelsU   s   € Ø�|‰|Ðr   c                ó@   € V P                  V4      P                  4       # r   )Úprob_classifyÚmax)r   Ú
featuresets   &&r   ÚclassifyÚNaiveBayesClassifier.classifyX   s   € Ø×!Ñ! *Ó-×1Ñ1Ó3Ð3r   c                ó^  € VP                  4       p\        VP                  4       4       F-  pV P                   F  pW23V P                  9   g   K   K)  	  W K/  	  / pV P                   F   pV P
                  P                  V4      WC&   K"  	  V P                   F„  pVP                  4        Fm  w  r%W23V P                  9   d:   V P                  W23,          pWC;;,          VP                  V4      ,          uu&   KP  WC;;,          \        . 4      ,          uu&   Ko  	  K†  	  \        VR R R7      # )T)Ú	normalizeÚlog)
Úcopyr   Úkeysr   r   r   ÚlogprobÚitemsr   r   )r   r   ÚfnameÚlabelr&   ÚfvalÚfeature_probss   &&     r   r   Ú"NaiveBayesClassifier.prob_classify[   sý   € ð  —_‘_Ó&ˆ
Ü˜*Ÿ/™/Ó+Ö,ˆEØŸœ�Ø�> T×%;Ñ%;Ö;Úñ &ð
 Ò%ñ -ð ˆØ—\”\ˆEØ!×1Ñ1×9Ñ9¸%Ó@ˆG‹Nñ "ð —\”\ˆEØ)×/Ñ/Ö1‘�Ø�> T×%;Ñ%;Ô;Ø$(×$:Ñ$:¸5¸<Õ$H�MØ—N m×&;Ñ&;¸DÓ&AÕA•Nð
 —N¤h¨r£lÕ2•Nó  2ñ "ô " '°T¸tÔDÐDr   c                ó\  aaaa	€ V P                   o\        R 4       V P                  V4       Fû  w  ooVVV3R lo	\        VVV3R lV P                   4       V	3R lRR7      p\        V4      ^8X  d   KH  V^ ,          pVR,          pSVS3,          P                  S4      ^ 8X  d   RpM@RSVS3,          P                  S4      SVS3,          P                  S4      ,          ,          p\        S:R R	S:R
 RRV,          R,          :R RRV,          R,          :R R	V: R2
4       Ký  	  R# )zMost Informative Featuresc                 ó8   <€ SV S3,          P                  S4      # r   )Úprob)ÚlÚcpdistr(   r*   s   &€€€r   Ú	labelprobÚFNaiveBayesClassifier.show_most_informative_features.<locals>.labelprobƒ   s   ø€ Ø˜a ˜hÕ'×,Ñ,¨TÓ2Ð2r   c              3   óh   <"  € T F'  pSSVS3,          P                  4       9   g   K#  Vx € K)  	  R # 5ir   )r   )Ú.0r0   r1   r(   r*   s   & €€€r   Ú	<genexpr>ÚFNaiveBayesClassifier.show_most_informative_features.<locals>.<genexpr>‡   s,   øé € ÐO™L�q¨D°F¸1¸e¸8Õ4D×4LÑ4LÓ4NÑ,N—’›Lùs   ƒ 2¨
2c                 ó   <€ S! V 4      ) V 3# r   © )Úelementr2   s   &€r   Ú<lambda>ÚENaiveBayesClassifier.show_most_informative_features.<locals>.<lambda>ˆ   s   ø€ ¡i°Ó&8Ð%8¸'Ñ$Br   T)ÚkeyÚreverseÚINFz%8.1fz>24z = Ú14Ú z%s:Né   Nz>6z : Ú6z : 1.0Néÿÿÿÿ)r   ÚprintÚmost_informative_featuresÚsortedr   Úlenr/   )
r   Únr   Úl0Úl1Úratior1   r(   r*   r2   s
   &&    @@@@r   Úshow_most_informative_featuresÚ3NaiveBayesClassifier.show_most_informative_features|   s   û€ à×'Ñ'ˆÜÐ)Ô*à×9Ñ9¸!Ö<‰KˆE�4÷3ô ÞO˜DŸLšLÓOÜBØôˆFô
 �6‹{˜aÔÙØ˜•ˆBØ˜•ˆBØ�b˜%�iÕ ×%Ñ% dÓ+¨qÔ0Ø‘àØ˜2˜u˜9Õ%×*Ñ*¨4Ó0°6¸"¸e¸)Õ3D×3IÑ3IÈ$Ó3OÕOõ�ô äœ$ ¨¥¨B§¡°$¸µ)¸R·±Ã%ðIöó) =r   c                ó<  a	a
€ \        V R4      '       d   V P                  RV # \        4       p\        \        4      o	\        R 4      o
V P
                  P                  4        F‘  w  w  r4pVP                  4        Fu  pWF3pVP                  V4       VP                  V4      p\        VS	V,          4      S	V&   \        VS
V,          4      S
V&   S
V,          ^ 8X  g   Kd  VP                  V4       Kw  	  K“  	  \        VV	V
3R lR7      V n        V P                  RV # )a_  
Return a list of the 'most informative' features used by this
classifier.  For the purpose of this function, the
informativeness of a feature ``(fname,fval)`` is equal to the
highest value of P(fname=fval|label), for any label, divided by
the lowest value of P(fname=fval|label), for any label:

|  max[ P(fname=fval|label1) / P(fname=fval|label2) ]
Ú_most_informative_featuresNc                  ó   € R # )g      ð?r9   r9   r   r   r;   Ú@NaiveBayesClassifier.most_informative_features.<locals>.<lambda>¬   s   € ©#r   c                 ó˜   <€ SV ,          SV ,          ,          V ^ ,          V ^,          R9   \        V ^,          4      P                  4       3# )é    )NFT)ÚstrÚlower)Úfeature_ÚmaxprobÚminprobs   &€€r   r;   rR   ¼   sC   ø€ Ø˜HÕ%¨°Õ(9Õ9Ø˜Q•KØ˜Q•KÐ#6Ñ6Ü˜ �Ó$×*Ñ*Ó,ñ	&r   )r=   )ÚhasattrrP   Úsetr   Úfloatr   r'   r   Úaddr/   r   ÚminÚdiscardrG   )r   rI   Úfeaturesr)   r(   Úprobdistr*   ÚfeatureÚprX   rY   s   &&       @@r   rF   Ú.NaiveBayesClassifier.most_informative_featuresš   s  ù€ ô �4Ð5×6Ò6Ø×2Ñ2°2°AÐ6Ð6ô “uˆHô "¤%Ó(ˆGÜ!¡+Ó.ˆGà,0×,BÑ,B×,HÑ,HÖ,JÑ(‘� Ø$×,Ñ,Ö.�DØ$˜m�GØ—L‘L Ô)Ø Ÿ™ dÓ+�AÜ'*¨1¨g°gÕ.>Ó'?�G˜GÑ$Ü'*¨1¨g°gÕ.>Ó'?�G˜GÑ$Ø˜wÕ'¨1Ö,Ø ×(Ñ(¨Ö1ó /ñ -Kô /5Øõô/ˆDÔ+ð ×.Ñ.¨r°Ð2Ð2r   c                óð  € \        4       p\        \         4      p\        \        4      p\        4       pV Fw  w  rxW8;;,          ^,          uu&   VP                  4        FJ  w  ršWHV	3,          V
;;,          ^,          uu&   WY,          P	                  V
4       VP	                  V	4       KL  	  Ky  	  V Fu  pW8,          pV Fd  p	WHV	3,          P                  4       pW¼,
          ^ 8”  g   K*  WHV	3,          R;;,          W¼,
          ,          uu&   WY,          P	                  R4       Kf  	  Kw  	  V! V4      p/ pVP                  4        F'  w  w  r‰pV! V\        WY,          4      R7      pVWèV	3&   K)  	  V ! WÞ4      # )zs
:param labeled_featuresets: A list of classified featuresets,
    i.e., a list of tuples ``(featureset, label)``.
N)Úbins)r   r   r[   r'   r]   ÚNrH   )ÚclsÚlabeled_featuresetsÚ	estimatorÚlabel_freqdistÚfeature_freqdistÚfeature_valuesÚfnamesr   r)   r(   r*   Únum_samplesÚcountr   r   Úfreqdistra   s   &&&              r   ÚtrainÚNaiveBayesClassifier.trainÅ   sU  € ô "›ˆÜ&¤xÓ0ÐÜ$¤SÓ)ˆÜ“ˆó "5ÑˆJØ×! QÕ&Ó!Ø)×/Ñ/Ö1‘�à ¨ Õ.¨t×4¸Õ9Ó4àÕ%×)Ñ)¨$Ô/à—
‘
˜5Ö!ó  2ñ "5ó $ˆEØ(Õ/ˆKÛ�Ø(°¨Õ6×8Ñ8Ó:�ð Õ&¨Ö*Ø$¨E \Õ2°4×8¸KÕ<OÕOÓ8Ø"Õ)×-Ñ-¨dÖ3ó  ñ $ñ # >Ó2ˆð ÐØ(8×(>Ñ(>Ö(@Ñ$‰NˆU˜HÙ  ´°NÕ4IÓ0JÔKˆHØ-5Ð E˜\Ó*ñ )Añ �>Ó4Ð4r   )r   r   r   rP   N)é
   )éd   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   rM   rF   Úclassmethodr   rr   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r	   r	   +   sB   ø‡ € ñò(6ò*ò4òEôBô<)3ðV Ø2=ó .5ó ö.5r   r	   c                  ó^   € ^ RI Hp  V ! \        P                  4      pVP	                  4        R# )rT   )Ú
names_demoN)Únltk.classify.utilr€   r	   rr   rM   )r€   Ú
classifiers     r   Údemorƒ   ü   s"   € Ý-áÔ0×6Ñ6Ó7€JØ×-Ñ-Ö/r   Ú__main__N)rz   Úcollectionsr   Únltk.classify.apir   Únltk.probabilityr   r   r   r   r	   rƒ   rv   r9   r   r   Ú<module>rˆ      s@   ðñõ2 $å )ß PÓ PôI5˜;ô I5òb0ð ˆzÔÙ†Fñ r   