nltk.probability.ConditionalProbDist

class nltk.probability.ConditionalProbDist[source]

Bases: ConditionalProbDistI

A conditional probability distribution modeling the experiments that were used to generate a conditional frequency distribution. A ConditionalProbDist is constructed from a ConditionalFreqDist and a ProbDist factory:

  • The ConditionalFreqDist specifies the frequency distribution for each condition.

  • The ProbDist factory is a function that takes a condition’s frequency distribution, and returns its probability distribution. A ProbDist class’s name (such as MLEProbDist or HeldoutProbDist) can be used to specify that class’s constructor.

The first argument to the ProbDist factory is the frequency distribution that it should model; and the remaining arguments are specified by the factory_args parameter to the ConditionalProbDist constructor. For example, the following code constructs a ConditionalProbDist, where the probability distribution for each condition is an ELEProbDist with 10 bins:

>>> from nltk.corpus import brown
>>> from nltk.probability import ConditionalFreqDist
>>> from nltk.probability import ConditionalProbDist, ELEProbDist
>>> cfdist = ConditionalFreqDist(brown.tagged_words()[:5000])
>>> cpdist = ConditionalProbDist(cfdist, ELEProbDist, 10)
>>> cpdist['passed'].max()
'VBD'
>>> cpdist['passed'].prob('VBD') 
0.423...
__init__(cfdist, probdist_factory, *factory_args, **factory_kw_args)[source]

Construct a new conditional probability distribution, based on the given conditional frequency distribution and ProbDist factory.

Parameters
  • cfdist (ConditionalFreqDist) – The ConditionalFreqDist specifying the frequency distribution for each condition.

  • probdist_factory (class or function) – The function or class that maps a condition’s frequency distribution to its probability distribution. The function is called with the frequency distribution as its first argument, factory_args as its remaining arguments, and factory_kw_args as keyword arguments.

  • factory_args ((any)) – Extra arguments for probdist_factory. These arguments are usually used to specify extra properties for the probability distributions of individual conditions, such as the number of bins they contain.

  • factory_kw_args ((any)) – Extra keyword arguments for probdist_factory.

__new__(**kwargs)
clear() None.  Remove all items from D.
conditions()

Return a list of the conditions that are represented by this ConditionalProbDist. Use the indexing operator to access the probability distribution for a given condition.

Return type

list

copy() a shallow copy of D
fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, default is returned if given, otherwise KeyError is raised

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values