Skip to content

Comparison.score.frequency

Comparison.score.frequency

frequency() -> Comparison

Calculates the frequency difference between the reference and comparison corpora.

Example
import wordlevel as wl

cl = wl.Catalog.from_dict_of_freqs(
    {
        "before": {"good": 12, "bad": 8, "happy": 6, "sad": 4},
        "after": {"good": 5, "bad": 7, "happy": 3, "sad": 9},
    }
)

cl = cl.with_comparisons(wl.comp("before", "after").score.frequency())

Each token's contribution is the difference in its raw frequency between the corpora. Specifically, the contribution \(\delta_\tau\) of a token \(\tau\) is:

\[ \delta_\tau = f_\tau^{(C)} - f_\tau^{(R)} \]

where \(f_\tau^{(R)}\) and \(f_\tau^{(C)}\) are the raw frequencies of token \(\tau\) in \(R\) and \(C\) respectively, the reference and comparison corpora. Positive contributions identify tokens that occur more often in the comparison; negative contributions identify tokens that occur more often in the reference.

See Also
Score Description
Comparison.score.proportion Scores corpora by normalized frequencies
Comparison.score.shannon_entropy Scores corpora by normalized frequencies weighted by surprisals

Returns:

Type Description
Comparison

A new Comparison with the corpora scored by frequency differences

Source