A frequency distribution for the outcomes of an experiment. A
frequency distribution records the number of times each outcome of an
experiment has occurred. For example, a frequency distribution could be
used to record the frequency of each word type in a document. Formally,
a frequency distribution can be defined as a function mapping from each
sample to the number of times that sample occurred as an outcome.
Frequency distributions are generally constructed by running a number
of experiments, and incrementing the count for a sample every time it is
an outcome of an experiment. For example, the following code will
produce a frequency distribution that encodes how often each word occurs
in a text:
int
|
B(self)
Returns:
The total number of sample values (or bins) that have counts greater than zero. |
|
|
int
|
N(self)
Returns:
The total number of sample outcomes that have been recorded by this
FreqDist. |
|
|
int
|
Nr(self,
r,
bins=None)
Returns:
The number of samples with count r. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new empty dictionary
|
__init__(self,
samples=None)
Construct a new frequency distribution. |
|
|
iter
|
__iter__(self)
Return the samples sorted in decreasing order of frequency. |
|
|
|
|
|
|
|
|
|
|
|
|
string
|
__repr__(self)
Returns:
A string representation of this FreqDist. |
|
|
|
None
|
__setitem__(self,
sample,
value)
Set this FreqDist's count for the given sample. |
|
|
|
string
|
__str__(self)
Returns:
A string representation of this FreqDist. |
|
|
|
|
|
list of float
|
|
|
|
|
|
|
| _sort_keys_by_value(self) |
|
|
|
None
|
clear(self)
Remove all items from D. |
|
|
FreqDist
|
copy(self)
Create a copy of this frequency distribution. |
|
|
int
|
count(self,
sample)
Return the count of a given sample. |
|
|
|
float
|
freq(self,
sample)
Return the frequency of a given sample. |
|
|
list
|
hapaxes(self)
Returns:
A list of all samples that occur once (hapax legomena) |
|
|
|
None
|
inc(self,
sample,
count=1)
Increment this FreqDist's count for the given sample. |
|
|
list of tuple
|
items(self)
Return the items sorted in decreasing order of frequency. |
|
|
iter of any
|
iteritems(self)
Return the items sorted in decreasing order of frequency. |
|
|
iter
|
iterkeys(self)
Return the samples sorted in decreasing order of frequency. |
|
|
iter
|
itervalues(self)
Return the values sorted in decreasing order. |
|
|
list of any
|
keys(self)
Return the samples sorted in decreasing order of frequency. |
|
|
any or None
|
max(self)
Return the sample with the greatest number of outcomes in this
frequency distribution. |
|
|
|
|
plot(self,
*args,
**kwargs)
Plot samples from the frequency distribution displaying the most
frequent sample first. |
|
|
|
v, remove specified key and return the corresponding value
|
pop(self,
other)
If key is not found, d is returned if given, otherwise KeyError is
raised |
|
|
|
(k, v), remove and return some (key, value) pair as a
|
popitem(self,
other)
2-tuple; but raise KeyError if D is empty. |
|
|
list
|
samples(self)
Returns:
A list of all samples that have been recorded as outcomes by this
frequency distribution. |
|
|
|
|
|
|
|
|
|
|
tabulate(self,
*args,
**kwargs)
Tabulate the given samples from the frequency distribution
(cumulative), displaying the most frequent sample first. |
|
|
|
None
|
update(self,
samples)
Update the frequency distribution with the provided list of samples. |
|
|
list of any
|
values(self)
Return the samples sorted in decreasing order of frequency. |
|
|
|
Inherited from dict:
__cmp__,
__contains__,
__delitem__,
__getattribute__,
__len__,
__new__,
__sizeof__,
fromkeys,
get,
has_key,
setdefault,
viewitems,
viewkeys,
viewvalues
Inherited from object:
__delattr__,
__format__,
__reduce__,
__reduce_ex__,
__setattr__,
__subclasshook__
|