【Python 走进NLP】NLP词频统计和处理停用词,可视化

2024-09-07 06:58

本文主要是介绍【Python 走进NLP】NLP词频统计和处理停用词,可视化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

# coding=utf-8
import requests
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from lxml import  etree
import time
time1=time.time()
import  bs4
import nltk
from bs4 import  BeautifulSoup
from nltk.corpus import stopwords############################抓取文本数据###########################
response = requests.get('http://php.net/')
html = response.content
# print (html)
soup = BeautifulSoup(html,"html5lib")
# 这需要安装html5lib模块
text = soup.get_text(strip=True)
tokens = [t for t in text.split()]
# print (tokens)################################处理停用词(英文停止词)#################
clean_tokens = list()
sr = stopwords.words('english')
for token in tokens:if token not in sr:clean_tokens.append(token)# ###############统计词频#################################freq = nltk.FreqDist(clean_tokens)
for key,val in freq.items():print (str(key) + ':' + str(val))########################词频可视化频率分布图:######################
freq.plot(20, cumulative=False)
# 需要安装matplotlib库

这里写图片描述

"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/NLP1.py
August.:1
theChangeLog.17:1
onour:4
better.01:1
ExtensionsHuman:1
recorded:5
ModeCommand:1
Character:1
31th:1
7.1.8.:1
list:15
report:5
7.0:2
7.1:3
TracingFunction:1
14th:1
development.Fast,:1
ExtensionsDatabase:1
ExtensionsXML:1
web:1
InvolvedHelpGetting:1
page)/Focus:1
Candidate:14
ProcessingVariable:1
ReferenceBasic:1
Interfaces:1
ExtensionsCredit:1
Relase:4
7.0.24:2
blog:1
source:15
StartedIntroductionA:1
Apache:1
atwindows.php.net/qa/.The:4
2.:1
team:10
7.0.23.:1
Protocols:1
helpjNext:1
7.1.9.:1
CollectionDTrace:1
pageGScroll:1
WrappersSecurityIntroductionGeneral:1
PHP.netContactOther:1
read:10
SecurityFilesystem:1
Register:1
XFormsHandling:1
moduleSession:1
ManipulationAuthentication:1
Release:11
7.0.23:2
ExtensionsFile:1
Control:1
ExtensionsDate:1
ProcessingCryptography:1
Encoding:1
12th:1
fixes:4
PHPCookiesSessionsDealing:1
Related:4
calling:1
7.2.0:15
papersMidwest:1
ThanksSocial:1
ExtensionsNon-Text:1
popular:2
found:15
ReferenceAffecting:1
PHP:48
handlingPersistent:1
2017User:1
A:5
VariablesPredefined:1
onwindows.php.net/download/.:5
media@official_phpCopyright:1
upgrading:5
System:1
Shortcuts?This:1
relative:1
Only:1
BehaviourAudio:1
GlobalsUser:1
28th:1
PHPKeeping:1
contains:1
ExceptionsPredefined:1
parametersSupported:1
users:10
Engine:1
theChangeLog.28:1
IN:5
encouraged:10
announces:10
better.03:1
PreprocessorDownloadsDocumentationGet:1
please:10
syntaxTypesVariablesConstantsExpressionsOperatorsControl:1
availability:10
2017Forum:1
everything:1
3:6
version:5
features:5
7.1.10:2
new:5
Line:1
IS:5
announced:2
PHP.net:1
CGI:1
full:5
considerationsInstalled:1
September.:2
This:8
ExplainedPredefined:1
pPrevious:1
release:10
fixed.:2
upgrade:5
GroupMy:1
general-purpose:1
Formats:1
GenerationMail:1
PREVIEW:5
ServicesSearch:1
helping:5
search:1
News:1
language:1
ExtensionsKeyboard:1
October.:1
sGoto:1
theChangeLog.14:1
RC3.:1
better.28:1
7.1.10.:1
menu:2
NOT:5
ObjectsNamespacesErrorsExceptionsGeneratorsReferences:1
changes:5
options:1
conferencesphp[world]:1
first:3
DataMagic:1
ourwiki.Thank:1
sitesMirror:1
ExtensionsSession:1
Group:1
ExtensionsText:1
Aug:4
simple:1
OutputProcess:1
pragmatic,:1
carefully,:5
tracking:5
ReleasedThe:9
incompatibilities:5
improvements:1
world.Download5.6.31·Release:1
Basic:1
release,:3
EntriesConferences:1
The:6
tutorialLanguage:1
notes.:5
©:1
ExtensionsCompression:1
usageGarbage:1
Processing:1
visit:10
RC2.:1
Jul:1
next:2
Beta:3
2:2
2017PHP:10
SupportImage:1
flexible:1
better.Older:1
AnnouncementThe:1
Card:1
files:5
7.2.0.:4
complete:5
Language:1
Database:1
These:5
Notes·Upgrading7.1.10·Release:1
20th:1
Submitted:1
PHPUpcoming:1
nNext:1
included.:3
gScroll:1
PHP::1
Time:1
version.For:5
line:1
bug:3
thedownloadpage,:5
7.1.9:2
Sep:5
bugfix:3
7.1.8:2
ServicesCommand:1
second:2
us:5
better.31:1
ServicesWindows:1
ConnectionsSafe:1
QuotesHiding:1
MIME:1
powers:1
Archive:1
scripting:1
1.:1
DO:5
page,:5
3.:2
ExtensionsOther:2
final:1
hGoto:1
theChangeLog.06:1
2001-2017:1
onwindows.php.net/qa/.The:1
July.:1
filesConnection:1
bottomg:1
binaryInstalled:1
changes,:5
file:1
SecurityDatabase:1
You:5
ClassesContext:1
StructuresFunctionsClasses:1
information:5
Several:2
releases:5
Type:1
make:5
thebug:5
-:5
search(current:1
archive.For:5
ExtensionsServer:1
1:2
also:10
authentication:1
itemkPrevious:1
PRODUCTION!For:5
ExtensionsMathematical:1
Alpha:4
EventsSpecial:1
several:3
USE:5
planned:5
development:10
CurrentFeaturesHTTP:1
test:5
Windows:10
pageg:1
downloads:10
policy:1
IT:5
theNEWSfile,:5
Specific:2
beta:2
theChangeLog.31:1
system.THIS:5
immediate:10
suited:1
Notes·Upgrading7.0.24·Release:1
topg:1
Notes·Upgrading29:1
uploadsUsing:1
PHP's:1
wiki.Thank:4
SecurityError:1
man:2
DEVELOPMENT:5
All:10
ManipulationGUI:1
remote:1
especially:1
third:2
released:3
ReportingUsing:1
theUPGRADINGfile:5
Hypertext:1
Dynamic:1
bugs:7
websites:1
itemg:1
sitesPrivacy:1
homepageg:1
sources:5
ourdownloads:5
ExtensionsWeb:1
7.0.24.:1
binaries:10
boxPHP:1

这篇关于【Python 走进NLP】NLP词频统计和处理停用词,可视化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144381

相关文章

无人叉车3d激光slam多房间建图定位异常处理方案-墙体画线地图切分方案

墙体画线地图切分方案 针对问题:墙体两侧特征混淆误匹配,导致建图和定位偏差,表现为过门跳变、外月台走歪等 ·解决思路:预期的根治方案IGICP需要较长时间完成上线,先使用切分地图的工程化方案,即墙体两侧切分为不同地图,在某一侧只使用该侧地图进行定位 方案思路 切分原理:切分地图基于关键帧位置,而非点云。 理论基础:光照是直线的,一帧点云必定只能照射到墙的一侧,无法同时照到两侧实践考虑:关

python: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

hdu1496(用hash思想统计数目)

作为一个刚学hash的孩子,感觉这道题目很不错,灵活的运用的数组的下标。 解题步骤:如果用常规方法解,那么时间复杂度为O(n^4),肯定会超时,然后参考了网上的解题方法,将等式分成两个部分,a*x1^2+b*x2^2和c*x3^2+d*x4^2, 各自作为数组的下标,如果两部分相加为0,则满足等式; 代码如下: #include<iostream>#include<algorithm

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

【生成模型系列(初级)】嵌入(Embedding)方程——自然语言处理的数学灵魂【通俗理解】

【通俗理解】嵌入(Embedding)方程——自然语言处理的数学灵魂 关键词提炼 #嵌入方程 #自然语言处理 #词向量 #机器学习 #神经网络 #向量空间模型 #Siri #Google翻译 #AlexNet 第一节:嵌入方程的类比与核心概念【尽可能通俗】 嵌入方程可以被看作是自然语言处理中的“翻译机”,它将文本中的单词或短语转换成计算机能够理解的数学形式,即向量。 正如翻译机将一种语言

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

nudepy,一个有趣的 Python 库!

更多资料获取 📚 个人网站:ipengtao.com 大家好,今天为大家分享一个有趣的 Python 库 - nudepy。 Github地址:https://github.com/hhatto/nude.py 在图像处理和计算机视觉应用中,检测图像中的不适当内容(例如裸露图像)是一个重要的任务。nudepy 是一个基于 Python 的库,专门用于检测图像中的不适当内容。该

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

flume系列之:查看flume系统日志、查看统计flume日志类型、查看flume日志

遍历指定目录下多个文件查找指定内容 服务器系统日志会记录flume相关日志 cat /var/log/messages |grep -i oom 查找系统日志中关于flume的指定日志 import osdef search_string_in_files(directory, search_string):count = 0