ó <¿CVc@sddlmZddlmZddlZddlmZddlmZyddl m Z Wne k rydZ nXddl mZmZddlmZmZd „Zd „Zd „Zd d „Zd„Zd„Zd„ZedkrþeƒndS(iÿÿÿÿ(tprint_function(tfabsN(tshuffle(treduce(tbetai(txrangetizip(tLazyConcatenationtLazyMapcCsTt|ƒt|ƒkr'tdƒ‚nttd„t||ƒDƒƒƒt|ƒS(s, Given a list of reference values and a corresponding list of test values, return the fraction of corresponding values that are equal. In particular, return the fraction of indices ``0(s(tlent ValueErrortfloattsumR(t referencettest((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pytaccuracyscCslt|dƒ s t|dƒ r/tdƒ‚nt|ƒdkrEdStt|j|ƒƒƒt|ƒSdS(sÌ Given a set of reference values and a set of test values, return the fraction of test values that appear in the reference set. In particular, return card(``reference`` intersection ``test``)/card(``test``). If ``test`` is empty, then return None. :type reference: set :param reference: A set of reference values. :type test: set :param test: A set of values to compare against the reference set. :rtype: float or None t intersections!reference and test should be setsiN(thasattrt TypeErrorR tNoneRR(RR((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyt precision*s cCslt|dƒ s t|dƒ r/tdƒ‚nt|ƒdkrEdStt|j|ƒƒƒt|ƒSdS(sÖ Given a set of reference values and a set of test values, return the fraction of reference values that appear in the test set. In particular, return card(``reference`` intersection ``test``)/card(``reference``). If ``reference`` is empty, then return None. :type reference: set :param reference: A set of reference values. :type test: set :param test: A set of values to compare against the reference set. :rtype: float or None Rs!reference and test should be setsiN(RRR RRR(RR((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pytrecall@s gà?cCsnt||ƒ}t||ƒ}|dks6|dkr:dS|dksR|dkrVdSd||d||S(s- Given a set of reference values and a set of test values, return the f-measure of the test values, when compared against the reference values. 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* = card(``reference`` intersection ``test``)/card(``test``) - *r* = card(``reference`` intersection ``test``)/card(``reference``) The f-measure is: - *1/(alpha/p + (1-alpha)/r)* If either ``reference`` or ``test`` is empty, then ``f_measure`` returns None. :type reference: set :param reference: A set of reference values. :type test: set :param test: A set of values to compare against the reference set. :rtype: float or None igð?iN(RRR(RRtalphatptr((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyt f_measureVscCsTt|ƒt|ƒkr'tdƒ‚ntd„t||ƒDƒƒ}|t|ƒS(sº Given a list of reference values and a corresponding list of test probability distributions, return the average log likelihood of the reference values, given the probability distributions. :param reference: A list of reference values :type reference: list :param test: A list of probability distributions over values to compare against the corresponding reference values. :type test: list(ProbDistI) s Lists must have the same length.css$|]\}}|j|ƒVqdS(N(tlogprob(R tvaltdist((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pys †s(R R RR(RRttotal_likelihood((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pytlog_likelihoodvs  c s¡|jddƒ}t|ttjtdt|ƒt|ƒdƒƒƒ}|jdd„ƒ}|jdtƒ}|rˆtd|ƒnt ||ƒ||ƒƒ}|rÉtd|ƒtd d ƒnd }t ||gƒ‰t t t|ƒt|ƒƒƒ}xt|ƒD]} |r=| d d kr=td| ƒnt |ƒ|t‡fd†|t|ƒ ƒƒ} |t‡fd†|t|ƒƒƒ} t | | ƒ} | |krÀ|d7}n|r| d d krtd| ƒtdt|dƒ| dƒtd d ƒqqWt|dƒ|d} |r”td| ƒtr”xCddddddgD]&}td|t|||ƒfƒqdWq”n| ||fS(sn Returns an approximate significance level between two lists of independently generated test values. Approximate randomization calculates significance by randomly drawing from a sample of the possible permutations. At the limit of the number of possible permutations, the significance level is exact. The approximate significance level is the sample mean number of times the statistic of the permutated lists varies from the actual statistic of the unpermuted argument lists. :return: a tuple containing an approximate significance level, the count of the number of times the pseudo-statistic varied from the actual statistic, and the number of shuffles :rtype: tuple :param a: a list of test values :type a: list :param b: another list of independently generated test values :type b: list tshufflesiçit statisticcSstt|ƒƒt|ƒS(N(RRR (tlst((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyt£stverboses shuffles: %dsactual statistic: %ft-i<g0Žä.ÿ++i is shuffle: %dcsˆ|S(N((ti(R$(se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyR%¹scsˆ|S(N((R((R$(se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyR%ºsspseudo-statistic: %fssignificance: %fg{®Gáz„?gš™™™™™©?gš™™™™™¹?g333333Ã?gÐ?gà?sprob(phi<=%f): %f(tgettminRtoperatortmulRR tFalsetprintRRtlisttrangeRRRR(tatbtkwargsR"tstatR&t actual_stattctindicesR(t pseudo_stat_at pseudo_stat_bt pseudo_statt significancetphi((R$se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyt approxrandŠsB8" ((   *cCsêtddƒdjƒ}djƒ}td|ƒtd|ƒtdt||ƒƒtddƒt|ƒ}t|ƒ}td|ƒtd|ƒtd t||ƒƒtd t||ƒƒtd t||ƒƒtddƒdS( NR'iKs DET NN VB DET JJ NN NN IN DET NNs DET VB VB DET NN NN NN IN DET NNs Reference =s Test =s Accuracy:s Test = s Precision:s Recall:s F-Measure:(R.tsplitRtsetRRR(RRt reference_setttest_set((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pytdemoÐs        t__main__(t __future__RtmathRR+trandomRt functoolsRtscipy.stats.statsRt ImportErrorRt nltk.compatRRt nltk.utilRRRRRRR!R=RBt__name__(((se/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/metrics/scores.pyts&        F