Type ConditionalFreqDist
object
--+
|
ConditionalFreqDist
A collection of frequency distributions for a single experiment run
under different conditions. Conditional frequency distributions are used
to record the number of times each sample occured, given the condition
under which the experiment was run. For example, a conditional frequency
distribution could be used to record the frequency of each word (type) in
a document, given its length. Formally, a conditional frequency
distribution can be defined as a function that maps from each condition
to the FreqDist
for the experiment under that condition.
The frequency distribution for each condition is accessed using the
indexing operator:
>>> cfdist[3]
<FreqDist with 73 outcomes>
>>> cfdist[3].freq('the')
0.4
>>> cfdist[3].count('dog')
2
When the indexing operator is used to access the frequency
distribution for a condition that has not been accessed before,
ConditionalFreqDist
creates a new empty
FreqDist
for that condition.
Conditional frequency distributions are typically constructed by
repeatedly running an experiment under a variety of conditions, and
incrementing the sample outcome counts for the appropriate conditions.
For example, the following code will produce a conditional frequency
distribution that encodes how often each word type occurs, given the
length of that word type:
>>> cfdist = ConditionalFreqDist()
>>> for word in tokenize.whitespace(sent):
... condition = len(word)
... cfdist[condition].inc(word)
__init__(self)
(Constructor)
Construct a new empty conditional frequency distribution. In
particular, the count for every sample, under every condition, is
zero.
-
- Overrides:
__builtin__.object.__init__
|
__getitem__(self,
condition)
(Indexing operator)
Return the frequency distribution that encodes the frequency of each
sample outcome, given that the experiment was run under the given
condition. If the frequency distribution for the given condition has
not been accessed before, then this will create a new empty
FreqDist for that condition.
-
- Parameters:
condition -
The condition under which the experiment was run.
(type=any)
- Returns:
-
The frequency distribution that encodes the frequency of each
sample outcome, given that the experiment was run under the given
condition.
(type=FreqDist )
|
__repr__(self)
(Representation operator)
-
- Returns:
-
A string representation of this
ConditionalFreqDist .
(type=string )
- Overrides:
__builtin__.object.__repr__
|
conditions(self)
-
- Returns:
-
A list of the conditions that have been accessed for this
ConditionalFreqDist . Use the indexing operator to
access the frequency distribution for a given condition. Note
that the frequency distributions for some conditions may contain
zero sample outcomes.
(type=list )
|