Natural Language Processing with Python

Charpter 6.1

suffix_fdist处代码稍微改动。

 import nltk
from nltk.corpus import brown def common_suffixes_fun():
suffix_fdist=nltk.FreqDist()
for word in brown.words():
word=word.lower()
suffix_fdist[word[-1:]] +=1
suffix_fdist[word[-2:]] +=1
suffix_fdist[word[-3:]] +=1
most_freqent_items=[it for it in sorted(suffix_fdist.items(),key=lambda x:(-x[1],x[0]))[:100]]
return [su[0] for su in most_freqent_items] common_suffixes = common_suffixes_fun() def pos_features(word):
features={}
for su in common_suffixes:
features['endswith(%s)' % su]=word.lower().endswith(su)
return features def test_pos():
tagged_words = brown.tagged_words(categories='news')[:5000]
featuresets=[(pos_features(word),tag) for (word,tag) in tagged_words] size= int(len(tagged_words)*0.1)
train_set, test_set = featuresets[size:],featuresets[:size]
classifier=nltk.NaiveBayesClassifier.train(train_set) print nltk.classify.accuracy(classifier,test_set)
classifier.show_most_informative_features(5)

运行结果为:

0.652
Most Informative Features
endswith(o) = True TO : NN = 423.2 : 1.0
endswith(es) = True DOZ : NN = 319.5 : 1.0
endswith(om) = True WPO : NN = 319.5 : 1.0
endswith(as) = True BEDZ : IN = 303.3 : 1.0
endswith(s) = True BEDZ : IN = 303.3 : 1.0

Part of Speech Tagging的更多相关文章

  1. 自然语言15.1_Part of Speech Tagging 词性标注

    QQ:231469242 欢迎喜欢nltk朋友交流 https://en.wikipedia.org/wiki/Part-of-speech_tagging In corpus linguistics ...

  2. 自然语言15_Part of Speech Tagging with NLTK

    https://www.pythonprogramming.net/part-of-speech-tagging-nltk-tutorial/?completed=/stemming-nltk-tut ...

  3. 词性标注 parts of speech tagging

    In corpus linguistics, part-of-speech tagging (POS tagging or POST), also called grammatical tagging ...

  4. 常用python机器学习库总结

    开始学习Python,之后渐渐成为我学习工作中的第一辅助脚本语言,虽然开发语言是Java,但平时的很多文本数据处理任务都交给了Python.这些年来,接触和使用了很多Python工具包,特别是在文本处 ...

  5. 自然语言14_Stemming words with NLTK

    https://www.pythonprogramming.net/stemming-nltk-tutorial/?completed=/stop-words-nltk-tutorial/ # -*- ...

  6. 自然语言12_Tokenizing Words and Sentences with NLTK

    https://www.pythonprogramming.net/tokenizing-words-sentences-nltk-tutorial/ # -*- coding: utf-8 -*- ...

  7. 大数据分析与机器学习领域Python兵器谱

    http://www.thebigdata.cn/JieJueFangAn/13317.html 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开发语言是C/ ...

  8. ML 05、分类、标注与回归

    机器学习算法 原理.实现与实践 —— 分类.标注与回归 1. 分类问题 分类问题是监督学习的一个核心问题.在监督学习中,当输出变量$Y$取有限个离散值时,预测问题便成为分类问题. 监督学习从数据中学习 ...

  9. Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)

    原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...

随机推荐

  1. 判断是ios还是android

    //判断是ios还是androidvar system;var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test( ...

  2. gvim work notes.. a few days' work on 64bit vim and plugin compilations

    (a 600MB+ sized c/c++ compiler which is capable of hi-light and JB styled completion!! and of-course ...

  3. HDU 5833 (2016大学生网络预选赛) Zhu and 772002(高斯消元求齐次方程的秩)

    网络预选赛的题目……比赛的时候没有做上,确实是没啥思路,只知道肯定是整数分解,然后乘起来素数的幂肯定是偶数,然后就不知道该怎么办了… 最后题目要求输出方案数,首先根据题目应该能写出如下齐次方程(从别人 ...

  4. CentOS6下配置Django+Apache+mod_wsgi+Sqlite3过程

    0. 安装环境: CentOs版本:      VMWare中CentOs 6.4 Apache版本:      Httpd 2.2.15 http://httpd.apache.org/ Sqlit ...

  5. 如何用好 Google 搜索引擎?

    1.双引号 把搜索词放在双引号中,代表完全匹配搜索,也就是说搜索结果返回的页面包含双引号中出现的所有的词,连顺序也必须完全匹配.bd和Google 都支持这个指令.例如搜索: “seo方法图片” 2. ...

  6. Android开机启动Activity或者Service方法(转载)

    这段时间在做Android的基础开发,现在有一需求是开机启动,按照网上某些博文教程做了下,始终不成功,一开机总是提示所启动的应用程序意外终止,于是参考了Android SDK doc,终于解决问题,下 ...

  7. 【项目笔记】布局文件报错Suspicious size: this will make the view invisible, probably intended for layout_width

    写着写着就懵逼了,一直以为布局文件没写错啊,horizontal就是竖直啊,原来布局文件报错,不仅仅需要从报错的地方解决问题,还需要从其他地方去分析. 很明显是方向orientation选错了,应该写 ...

  8. 转载 C++学习第9篇---类和类的封装

    http://blog.csdn.net/zuheyawen/article/details/7324340

  9. css position relative obsolution

    层级关系为:<div ——————————— position:relative; 不是最近的祖先定位元素,不是参照物<div—————————-没有设置为定位元素,不是参照物<di ...

  10. C#中String和stringBuilder的区别

    Stringbuilder类是直接用于字符串操作的类,打个比方把(1)string aa="123456";(2)aa+="789"; (3)StringBui ...