Natural Language Processing (3) conditional Frequency Distribution

Source: Internet
Author: User
Tags nltk
Natural Language Processing (3) conditional Frequency Distribution

A set of conditional frequency distributed frequencies. Each frequency distribution has a different condition.

The following example shows that CFD is a set of frequency distributions of two conditions (News, romance ).

 1 >>> cfd=nltk.ConditionalFreqDist( 2 ...                     (genre,word) 3 ...                     for genre in [‘news‘,‘romance‘] 4 ...                     for word in brown.words(categories=genre)) 5 >>> cfd 6 <ConditionalFreqDist with 2 conditions> 7 >>> list(cfd[‘news‘])[:4] 8 [‘the‘, ‘,‘, ‘.‘, ‘of‘] 9 >>> list(cfd[‘romance‘])[:4]10 [‘,‘, ‘.‘, ‘the‘, ‘and‘]

You can use plot () and tabulte () to plot the distribution chart and distribution table.

Example: Deal with the news and Romantic styles in the brown circle and find out the most recent and romantic days of the week.

 1 >>> from nltk.corpus import brown 2 >>> days=[‘Monday‘,‘Tuesday‘,‘Wednesday‘,‘Thursday‘,‘Friday‘,‘Saturday‘,‘Saturday‘] 3 >>> cfd=nltk.ConditionalFreqDist( 4 ...                     (genre,word) 5 ...                     for genre in [‘news‘,‘romance‘] 6 ...                     for word in brown.words(categories=genre)) 7 >>> cfd.tabulate(samples=days,cumulative=True) 8         Monday Tuesday Wednesday Thursday Friday Saturday Saturday 9    news   54   97  119  139  180  213  24610 romance    2    5    8    9   12   16   2011 >>> cfd.tabulate(samples=days)12         Monday Tuesday Wednesday Thursday Friday Saturday Saturday13    news   54   43   22   20   41   33   3314 romance    2    3    3    1    3    4    4

 

Common nltk conditional Frequency Distribution Method

Example Description
Cfdist = conditionalfreqdist () Create a conditional frequency distribution from a paired linked list
Cfdist. Conditions () Sorts conditions by letter
Cfdist [condition] Frequency Distribution under this condition
Cfdist [condition] [sample] Frequency of the given sample under this condition
Cfdist. tabulate () Tabulation for conditional Frequency Distribution
Cfdist. tabulate (samples, conditions) Tabulation under specified Samples and conditions
Cfdist. Plot () Plot the conditional Frequency Distribution
Cfdist. Plot (samples, conditions) Drawing under specified Samples and conditions

Natural Language Processing (3) conditional Frequency Distribution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.