首页 文章 精选 留言 我的

精选列表

搜索[学习],共10000篇文章
优秀的个人博客,低调大师

python零基础应该怎样学习入门Python?

前言Python 语言应该如何入门,记得我几年前也碰到过这样的问题,当时网上随便搜了一下饥不择食的找了一些书开始啃起来,结果发现很疑惑,感觉吃力,走了很多弯路。若不得法还会降低初学者的兴趣,现在我就说说自己对python 入门的理解. 学Python和学其他的语言其实是相同的,我给新同事讲课的时候就说学编程和练武功其实是很相似,入门大致这样几步: 找本靠谱的书, 找个靠谱的师傅, 找一个地方开始练习。 学语言也是的:选一本通俗易懂的书,找一个好的视频资料,然后自己装一个IDE工具开始边学变写。下面我具体来讲讲: 1.找一本靠谱的书,难度一定要是入门级别,千万不能太复杂,不要一下子陷进去,会打乱节奏,学东西要循序渐进,不能一口吃个胖子.打个比方,学过java的同学都听过大名鼎鼎的thinking in java,这边书很厚很全,若一上来就学,肯定会吃力,时间长了就会失去兴趣,因此对初学者来说,一定要找一个通熟易懂的,简单的书。入门的书非常关键。 入门的书很多,但是我个人强烈推荐"A Byte of Python",这本书我读了2遍,作者写的思路非常清晰,对每一个知识点讲解的很到位,不多不少,刚刚好,对初学者来说,力道刚刚好。而且是全英文,对提高自己的英语水平,很有帮助. 2.找一个好的视频资源,当然若你周围有Python高手就更好了,可以多交流多请教。视频资源我推荐imooc,当然有人说还有jikexueyuan,网易公开课,这几家我都看过一些,各有千秋,我建议初学者还是选择imooc,他家的Python讲解的很仔细,而且音频的质量比较高,最关键是的可以在web上直接编程练习,都不用自己安装编译器,非常方便。居家旅行必备啊~~ 3.多编写程序,这似乎是废话,但是确实是一句实话。学编程一定要亲身去编写,没有什么捷径.一开始哪怕你把书里面的例子一字不落敲一遍,也好过你只是去看书,而不动手。 而且学Python最好是坚持编,每天抽小半个小时,学一些知识点,不断的坚持.大概快的话几个星期基本就能入门了。 以上就是我对Python入门的感悟,希望对初学者能有一点帮助,能帮到一些人少走一点弯路.也就不枉我大半夜在这里码字了~~

优秀的个人博客,低调大师

Python零基础学习笔记(三十九)—— time

#UTC(世界协调时间):格林尼治天文时间,世界标准时间,在中国来说是UTC+8(东八区) #DST(夏令时):是一种节约能源而人为规定的时间制度,在夏季调快一个小时 ''' 时间的表示形式: 1、时间戳 以整形或浮点型表示时间的一个以秒为单位的时间间隔 时间间隔的基础值是从1970年1月1号0点开始算起的 2、元组 一种Python的数据结构表示,这个元组有9个整形内容 year month day hours minutes seconds weekday Julia day fiag(1 【夏令时】或 -1【】 或 0【正常】) 3、格式化字符串 %y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数(0-23) %I 12小时制小时数(01-12) %M 分钟数(00=59) %S 秒(00-59) %a 本地简化星期名称 %A 本地完整星期名称 %b 本地简化的月份名称 %B 本地完整的月份名称 %c 本地相应的日期表示和时间表示 %j 年内的一天(001-366) %p 本地A.M.或P.M.的等价符 %U 一年中的星期数(00-53)星期天为星期的开始 %w 星期(0-6),星期天为星期的开始 %W 一年中的星期数(00-53)星期一为星期的开始 %x 本地相应的日期表示 %X 本地相应的时间表示 %Z 当前时区的名称 ''' import time #以浮点数形式返回当前时间的时间戳,不需要参数(UTC) c = time.time() print(c) #将时间戳转为UTC时间元组 t = time.gmtime(c) print(t) #将时间戳转为本地时间元组 b = time.localtime(c) print("b =", b) #将本地时间元组转换为时间戳 m = time.mktime(b) print(m) #将时间元组转换成字符串 s = time.asctime(b) print(s) #将时间戳转为字符串 h = time.ctime(c) print(h) #将时间元组转换为指定格式的字符串,参数2 为时间元祖,如果没有参数2, 默认转换为当前时间 q = time.strftime("%Y-%m-%d %H:%M:%S",b) print(q) #将时间字符串转换为时间元组 i = time.strptime(q, "%Y-%m-%d %H:%M:%S") print(i) #延迟一个时间,整形或浮点型 #time.sleep(1) #返回当前程序的cpu时间 #Unix系统始终返回全部的运行时间 #Windows从第二次开始,都是以第一个调用此函数的开始时间戳作为基数 j = time.clock() print(j) time.sleep(2) j1 =time.clock() print("%d" % j1) time.sleep(2) j2 =time.clock() print("%d" % j2)

优秀的个人博客,低调大师

Python零基础学习笔记(三十六)—— 递归

''' 递归调用:一个函数,调用了自身,成为递归调用 递归函数:一个会调用自身的函数 凡是循环能干的事,递归都能干 ''' ''' 方式: 1、写出临界条件 2、找这一次和上一次的关系 3、假设当前函数已经能用,调用自身计算行一次的结果,再求出本次的结果 ''' #输入一个数,求 1+2+3+……+ n 的和 def sum1(n): sum = 0 for x in range(1, n + 1): sum += x return sum res = sum1(10) print("res =", res) #递归方法 def sum2(n): if n == 1: return 1 else: return n + sum2(n - 1) res1 = sum2(10) print(res1)

优秀的个人博客,低调大师

Python零基础学习笔记(三十)—— 读文件

''' 过程: 1、打开文件 2、读文件内容 3、关闭文件 ''' ''' 1、打开文件 open(path, flag[, encoding]) path:要打开文件的路径 flag:打开方式 r(read) 以只读方式打开文件,文件的描述符放在文件的开头 rb 以为进制格式打开文件用于只读,文件的描述符放在文件的开头 r+ 打开一个文件用于读写,文件的描述符放在文件的开头 w 打开一个文件只用于写入,如果该文件已经存在会覆盖,不存在则创建新文件 wb 打开一个文件只用于写入二进制,如果该文件已经存在会覆盖,不存在则创建新文件 w+ 打开一个文件用于读写,如果该文件已经存在会覆盖,不存在则创建新文件 a 打开一个文件用于追加,如果文集那存在,文件描述符将会放到文件末尾 a+ encoding:编码格式 errors:错误处理 ''' #打开文件 path = r"E:\File.txt" #f = open(path, "r", encoding = "utf-8",errors = "ignore") f = open(path, "r") ''' 2、读文件内容 ''' #读文件的所有内容 str1 = f.read() print("str1 =", str1) #读文件中指定字符数 f.seek(0) #修改描述符的位置 str2 = f.read(5) print("str2 =", str2) #读取整行,包括"\n"字符 f.seek(0) str3 = f.readline() print("str3 =", str3) #读取所有行并返回列表 f.seek(0) str4 = f.readlines() print("str4 =", str4) #读取指定字符数 f.seek(0) str5 = f.readline(20) print("str5 =", str5) #修改描述符的位置 f.seek(0) ''' 3、关闭文件 ''' f.close() ''' 完整过程 ''' #第一种 try: f1 = open(path,"r") print(f1.read()) finally: if f1: f1.close() #更为简单的方法 with open(path, "r", encoding= "gbk", errors="ignore") as f2: print(f2.read())

优秀的个人博客,低调大师

Python零基础学习笔记(二十)—— tuple元组

#创建空元组 tuple1 = () print(tuple1) #创建带有元素的元组 tuple2 = (1, 2, 3, "jjking", True) #元素类型可以不同 print(tuple2) #定义只有1 个元素的元组 tuple3 = (1 ) #后面必须加逗号 print(tuple3) print(type(tuple3)) ''' 元组元素的访问 格式: 元组名[下标] 注意:下标不能越界 ''' tuple4 = (1, 2, 3, 4, 5) print(tuple4[3]) #获取最后一个元素 print(tuple4[-1]) #获取倒数第二个元素 print(tuple4[-2]) #修改元组,实际上修改的是元素里面的数据 tuple5 = (1, 2, 3, 4, [1, 2, 3], 5) print(tuple5) tuple5[4][2] = 4 print(tuple5) #删除元组 del tuple5 #print(tuple5) 因为被删除了所以打印不出来,会报错 #元组的操作 t1 = (1 ,2, 3, 4) t2 = (5, 6) t3 = t1 + t2 print(t3) #元组重复 print(t3 *3) #判断元素是否在元组中 print( 3 in t3) #元组的截取 #格式:元组名[ 开始下标:结束下标 ] #从开始下标开始截取,到结束下标之前,默认从头到尾 print(t3[1:4]) #二维元组:元素为一维元组的元组 t4 = ((1, 2, 3), (4, 5, 6), (7, 8, 9)) print(t4) print(t4[2][1]) '''元组的方法''' #len() 返回元组中元素的个数 print(len(t4)) #max() 返回元组中的最大值 print(max(t1)) #min() 返回元祖中的最小值 print(min(t1)) #列表转元组 list2 = [1, 2, 3, 4, 5] t5 = tuple(list2) print(t5) #元组转列表 list1 = list(t3) print(list1) ''' 一旦初始化元组里面的元素就不能修改了 和列表的区别就是不可变 这就提高了数据的安全性 所以说能用元组尽量用元组 ''' #元组的遍历 for i in (1, 2, 3, 4,5): print(i)

优秀的个人博客,低调大师

Python零基础学习笔记(十五)—— list(列表)

''' 本质;一种有序的集合 格式: 列表名 = [列表选项1, 列表选项2, ...列表选项n] ''' list1 = [23, 22, 24, 22, 25] print(list1) #元素数据可以不同 list2 = [1, 233, "name", "jjking", True] ''' 列表元素的访问 取值: 格式:列表名[下标] 注意:列表下标不要越界 ''' print(list1[2]) #列表操作: #列表组合 list3 = list1 + list2 print(list3) #列表的重复 print(list2 * 5) #判断元素是否在列表中 print(1 in list2) #列表截取 [2:3) print(list2[2:3]) #二维列表 list4 = [[123],[2,2,3],[1,2,3],[4,5,6,8]] print(list4[2][2]) #列表方法 list5 = [1,2,3,4,5,6] #appeng() 在列表末尾添加新的元素 list5.append(7) print(list5) list5.append([8,9]) print(list5) #extend() 在末尾一次性追加另一个列表中的多个值 list5.extend([1,2,3]) print(list5) #insert() 在下标处添加一个元素,元数据向后顺延 list5.insert(2,10) print(list5) #pop() 删除下标处的元素,默认为最后一个下标,并返回删除的数据 list5.pop() print(list5) list5.pop(2) print(list5) print(list5.pop(2)) #remove() 移除列表中的某个元素 list5.remove(5) list5.remove([8, 9]) print(list5) #clear() 清除列表中所有的数据 list6 = [1,2,3] list6.clear() print(list6) #index() 从列表中找出某个值的第一个匹配的索引值,可以加开始和结束的下标范围 print(list5.index(2)) print(list5.index(2, 4,8)) #len() 列表中的元素 print(len(list5)) #max() 获取列表中的最大值,只能是在一维列表,不然会报错 print(max(list5)) #min() 获取列表中的最小值,只能是在一维列表,不然会报错 print(min(list5)) #count() 某元素出现的次数 print(list5.count(2)) #浅拷贝 内存地址是一样的 lis7 = list5 print(id(list5)) print(id(lis7)) #copy() 深拷贝 内存的拷贝 内存的地址是不一样的 print(id(list5.copy())) #reverse() 倒序 list5.reverse() print(list5) #sort() 从小到大排序 list5.sort() print(list5) #元组转换成列表 list8 = list((1,2,3,4)) print(list8)

优秀的个人博客,低调大师

Python零基础学习笔记(十四)—— while语句

''' while 语句: 格式: while 表达式: 语句 逻辑:当程序遇到while语句的时候,首先计算【表达式】的值 如果【表达式】的值为假,那么结束整个while语句 如果表达式的值为真,则执行【语句】,循环调用,直到为假停止 ''' #从1打印到小于5的数 num = 1 while num < 5: print("num = %d"% num) num += 1 #计算1+2+3+...+100 sum = 0 num = 1 while num <= 100: sum += num num += 1 #print("sum = %d" % sum) print("sum = %d"% sum) #打印字符串里的每一个字符 str = "My name is jjking." index = 0 while index <= len(str): print(str[index]) index += 1 运行结果: num = 1 num = 2 num = 3 num = 4 sum = 5050 M y n a m e i s j j k i n g .

优秀的个人博客,低调大师

【NLP学习笔记】(一)Gensim基本使用方法

安装: pip install gensim本文内容主要翻译自https://radimrehurek.com/gensim/tut1.html#from-strings-to-vectors,中间加了些自己的理解,不理解之处大家可以直接看原文档。 1、第一步、准备训练语料 为了简单起见,我们假设列表documents代表语料库,每一句话代表一个文档,documents中有9个元素,也就是说该语料库由九个文档组成。 from gensim import corpora documents = ["Human machine interface for lab abc computer applications", "A survey of user opinion of computer system response time", "The EPS user interface management system", "System and human system engineering testing of EPS", "Relation of user perceived response time to error measurement", "The generation of random binary unordered trees", "The intersection graph of paths in trees", "Graph minors IV Widths of trees and well quasi ordering", "Graph minors A survey"] 2、第二步、预处理 分词(tokenize the documents)、去除停用词和在语料中只出现一次的词。处理语料的方式有很多,这里只是简单地通过空格(whitespace)去分词,然后把每个词变为小写,最后去除一些常用的词和只出现一次的词。 # remove common words and tokenize stoplist = set('for a of the and to in'.split()) #遍历documents,将其每个元素的words置为小写,然后通过空格分词,并过滤掉在stoplist中的word。 texts = [[word for word in document.lower().split() if word not in stoplist] for document in documents] # remove words that appear only once,collection是python的一个工具库 from collections import defaultdict frequency = defaultdict(int) for text in texts: for token in text: frequency[token] += 1 texts = [[token for token in text if frequency[token] > 1] for text in texts] from pprint import pprint # pprint可以使输出更易观看。 pprint(texts) #输出结果: [['human', 'interface', 'computer'], ['survey', 'user', 'computer', 'system', 'response', 'time'], ['eps', 'user', 'interface', 'system'], ['system', 'human', 'system', 'eps'], ['user', 'response', 'time'], ['trees'], ['graph', 'trees'], ['graph', 'minors', 'trees'], ['graph', 'minors', 'survey']] 3、第三步、文本向量化 如何从文档中提取特征有很多方法。这里简单使用词袋模型(bag-of- words)来提取文档特征,该模型通过计算每个词在文档中出现的频率,然后将这些频率组成一个向量,从而将文档向量化。首先我们需要用语料库训练一个词典,词典包含所有在语料库中出现的单词。 #定义一个词典,里面包含所有语料库中的单词,这里假设上文中输出的texts就是经过处理后的语料库。 dictionary = corpora.Dictionary(texts) dictionary.save('./gensim_out/deerwester.dict') # 因为实际运用中该词典非常大,所以将训练的词典保存起来,方便将来使用。 print(dictionary) # 输出:Dictionary(35 unique tokens: ['abc', 'applications', 'computer', 'human', 'interface']...) # dictionary有35个不重复的词,给每个词赋予一个id print(dictionary.token2id)#输出:{'abc': 0, 'applications': 1, 'computer': 2, 'human': 3, 'interface': 4, 'lab': 5, 'machine': 6, 'opinion': 7, 'response': 8, 'survey': 9, 'system': 10, 'time': 11, 'user': 12, 'eps': 13, 'management': 14, 'engineering': 15, 'testing': 16, 'error': 17, 'measurement': 18, 'perceived': 19, 'relation': 20, 'binary': 21, 'generation': 22, 'random': 23, 'trees': 24, 'unordered': 25, 'graph': 26, 'intersection': 27, 'paths': 28, 'iv': 29, 'minors': 30, 'ordering': 31, 'quasi': 32, 'well': 33, 'widths': 34} 上面已经构建了单词词典,我们可以通过该词典用词袋模型将其他的文本向量化.假设新文本是“Human computer interaction“,则输出向量为[(2, 1), (3, 1)],(2,1)中的“2”表示computer在词典中的id为2,“1”表示Human在该文档中出现了1次,同理,(3,1)表示Human在词典中的id为3,出现次数为1,输出向量中元组的顺序应该是按照id大小排序。interaction不在词典中,所以直接被忽略了。 new_doc = "Human computer interaction" #用dictionary的doc2bow方法将文本向量化 new_vec = dictionary.doc2bow(new_doc.lower().split()) corpora.MmCorpus.serialize('./gensim_out/deerwester.mm',new_vec) # 讲训练结果存储到硬盘中,方便将来使用。 print(new_vec)#输出[(2, 1), (3, 1)] 4、优化 上面训练过程中,语料库完全驻留在内存中,如果语料库很大,那将是个灾难,假设硬盘中存储着数百万的语料,我们可以一次取出一个文档,这样同一时间只有一个文档在内存中。获取mycorpus.txt #获取语料 class MyCorpus(object): def __iter__(self): for line in open('mycorpus.txt'): #每一个line代表语料库中的一个文档 yield dictionary.doc2bow(line.lower().split()) corpus_memory_friendly = MyCorpus()# 没有将corpus加载到内存中 print(corpus_memory_friendly)#输出:<__main__.MyCorpus object at 0x10d5690> #遍历每个文档 for vector in corpus_memory_friendly: # load one vector into memory at a time print(vector) 输出结果: [(0, 1), (1, 1), (2, 1)] [(0, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1)] [(2, 1), (5, 1), (7, 1), (8, 1)] [(1, 1), (5, 2), (8, 1)] [(3, 1), (6, 1), (7, 1)] [(9, 1)] [(9, 1), (10, 1)] [(9, 1), (10, 1), (11, 1)] [(4, 1), (10, 1), (11, 1)] 同样的,构建词典dictionary过程中也需要这种memory-friendly的方式训练 # iteritems用来遍历对象中的每个item from six import iteritems #初步构建所有单词的词典 dictionary = corpora.Dictionary(line.lower().split() for line in open('mycorpus.txt') ) #去出停用词,stop_ids表示停用词在dictionary中的id stop_ids = [dictionary.token2id[stopword] for stopword in stoplist if stopword in dictionary.token2id] #只出现一次的单词id once_ids = [tokenid for tokenid, docfreq in iteritem(dictionary.dfs) if docfreq ==1] #根据stop_ids与once_ids清洗dictionary dictionary.filter_token(stop_ids + once_ids) # 去除清洗后的空位 dictionary.compactify() print(dictionary)#输出:Dictionary(12 unique tokens) 5、存储训练结果的几种方式 corpora.MmCorpus.serialize(path, result) corpora.SvmLightCorpus.serialize(path, result) corpora.BleiCorpus.serialize(path, result) corpora.LowCorpus.serialize(path, result)值得注意的时第一种,Market Matrix format,用法举例 #假设训练结果为下面的corpus corpus = [[(1, 0.5)], []] # make one document empty, for the heck of it #存储 corpora.MmCorpus.serialize('./gensim_out/corpus.mm', corpus) #加载 corpus = corpora.MmCorpus('./gensim_out/corpus.mm') print(corpus)#输出:MmCorpus(2 documents, 2 features, 1 non-zero entries) #查看加载后的结果有两种方法:1.转成list2.遍历corpus,这种方法堆内存更加友好。 print(list(corpus)) # calling list() will convert any sequence to a plain Python list #输出:[[(1, 0.5)], []] for doc in corpus: print(doc) #输出:[(1, 0.5)][]

优秀的个人博客,低调大师

【NLP学习笔记】(二)gensim使用之Topics and Transformations

本文主要翻译自:https://radimrehurek.com/gensim/tut2.html 这个教程会向大家展示如何将代表文档的向量转换成另一种向量,做这件事的目的主要有两个: 发现语料中的隐藏结构,比如词与词之间的联系,然后用一种全新的方式、一种更能表现语义的方式(semantic way)来描述文档。 使文档的表示更加紧凑,这样可以提高效率和功效,因为新的表达方式消耗更少的资源,并且去除了噪音。 一、回顾 在之前的gensim基础使用中,我们介绍了如何将语料提取特征后转换为向量(基于词袋模型),上一章中的结果: # 清洗后的语料库,只有九句话,代表九个文档 [['human', 'interface', 'computer'], ['survey', 'user', 'computer', 'system', 'response', 'time'], ['eps', 'user', 'interface', 'system'], ['system', 'human', 'system', 'eps'], ['user', 'response', 'time'], ['trees'], ['graph', 'trees'], ['graph', 'minors', 'trees'], ['graph', 'minors', 'survey']] # 根据上面语料训练的词典,每个词都有一个id {'computer': 0, 'eps': 8, 'graph': 10, 'human': 1, 'interface': 2, 'minors': 11, 'response': 3, 'survey': 4, 'system': 5, 'time': 6, 'trees': 9, 'user': 7} # 根据词典基于词袋模型,训练上面语料的结果,(0,1.0)的意思是id为0的单词,即“computer”在第一篇文章中出现了1次。其它类似。 [[(0, 1.0), (1, 1.0), (2, 1.0)], [(0, 1.0), (3, 1.0), (4, 1.0), (5, 1.0), (6, 1.0), (7, 1.0)], [(2, 1.0), (5, 1.0), (7, 1.0), (8, 1.0)], [(1, 1.0), (5, 2.0), (8, 1.0)], [(3, 1.0), (6, 1.0), (7, 1.0)], [(9, 1.0)], [(9, 1.0), (10, 1.0)], [(9, 1.0), (10, 1.0), (11, 1.0)], [(4, 1.0), (10, 1.0), (11, 1.0)]] 二、加载上一章中结果(保存的字典和语料向量) from gensim import corpora, models, similarities import os if(os.path.exists('./gensim_out/deerwester.dict')): dictionary = corpora.Dictionary.load('./gensim_out/deerwester.dict') corpus = corpora.MmCorpus('./gensim_out/deerwester.mm') print("使用之前已经存储的字典和语料向量") else: print("请先通过上一章生成deerwester.dict和deerwester.mm") #pprint(dictionary.tokenz`2id) #pprint(corpus) 三、初始化一个转换模型(Creating a transformation) 转换模型是标准的python对象,通常需要传入一个语料库进行初始化。我们使用教程1中的旧语料库来初始化(训练)转换模型。也就是上面加载的corpus, 不同的转换模型一般需要不同的初始化参数; 在TfIdf的情况下,“训练”仅包括通过提供的语料库一次并计算其所有词频和逆文档频率。 训练其他模型,例如潜在语义分析或潜在狄利克雷分析,涉及更多,因此也会消耗更多时间。 tfidf = models.TfidfModel(corpus) #初始化一个模型 doc_bow = [(0, 1), (1, 1)] print(tfidf[doc_bow])#输出:[(0, 0.70710678), (1, 0.70710678)] 上面已经创建了tfidf模型,我们应该将其作为一个只读对象来看待,用它可以将旧的向量表示(上一节中的词袋模型)转换为新的向量表示(比如tf-idf权重)假设新文本为:“Human computer interaction”doc_bow是新文本经过上一章的清洗、分词、基于词袋模型转换后的结果,(0, 1)表示id为0,即“computer”。1表示“computer”在新文本中出现了1次;(1, 1)表示id为1,即“human”也出现了1次。tfidf模型将新文本从词袋向量模型([(0, 1), (1, 1)])转换为了词频-逆文档频率权重向量([(0, 0.70710678), (1, 0.70710678)]),即“computer”的权重为0 0.70710678,“human”的权重为0.70710678 四、序列化转换后的结果 调用model_name[corpus]仅在旧的语料库文档流周围创建一个包装器 ,实际转换在文档迭代期间即时完成。 我们无法在调用corpus_transformed = model [corpus]时转换整个语料库,因为这意味着将结果存储在内存中,这与gensim的内存独立的目标相矛盾。 如果您将多次迭代转换的corpus_transformed,并且转换成本很高,请先将生成的语料库序列化到磁盘然后再使用它。 #用tfidf转换语料库corpus corpus_tfidf = tfidf[corpus] #initialize an LSI transformation(初始化LSI模型) lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=2) #create a double wrapper over the original corpus: bow->tfidf->fold-in-lsicorpus_lsi = lsi[corpus_tfidf] lsi.print_topics(2) #输出:topic #0(1.594): -0.703*"trees" + -0.538*"graph" + -0.402*"minors" + -0.187*"survey" + -0.061*"system" + -0.060*"response" + -0.060*"time" + -0.058*"user" + -0.049*"computer" + -0.035*"interface" topic #1(1.476): -0.460*"system" + -0.373*"user" + -0.332*"eps" + -0.328*"interface" + -0.320*"response" + -0.320*"time" + -0.293*"computer" + -0.280*"human" + -0.171*"survey" + 0.161*"trees" 根据上面结果可以看出“trees”, “graph” and “minors都是相关联的词汇,并且对第一个主题的贡献度最高,第二个主题,更多的是关注其他的词汇 for doc in corpus_lsi: print(doc) #输出结果(可以看出前五个文档与第二个主题关联度更高): [(0, -0.066), (1, 0.520)] # "Human machine interface for lab abc computer applications" [(0, -0.197), (1, 0.761)] # "A survey of user opinion of computer system response time" [(0, -0.090), (1, 0.724)] # "The EPS user interface management system" [(0, -0.076), (1, 0.632)] # "System and human system engineering testing of EPS" [(0, -0.102), (1, 0.574)] # "Relation of user perceived response time to error measurement" [(0, -0.703), (1, -0.161)] # "The generation of random binary unordered trees" [(0, -0.877), (1, -0.168)] # "The intersection graph of paths in trees" [(0, -0.910), (1, -0.141)] # "Graph minors IV Widths of trees and well quasi ordering" [(0, -0.617), (1, 0.054)] # "Graph minors A survey" 保存模型与加载模型 lsi.save('./gensim_out/model.lsi') #保存 same for tfidf, lda, ... lsi = models.LsiModel.load('/tmp/model.lsi') #加载 gensim中可用的转换模型 1.Term Frequency * Inverse Document Frequency, Tf-Idf model = models.TfidfModel(corpus, normalize=True) 2.Latent Semantic Indexing, LSI (or sometimes LSA) model = models.LsiModel(tfidf_corpus, id2word=dictionary, num_topics=300) model.add_documents(another_tfidf_corpus) #now LSI has been trained on tfidf_corpus + another_tfidf_corpus lsi_vec = model[tfidf_vec] #convert some new document into the LSI space, without affecting the model ... model.add_documents(more_documents) #tfidf_corpus + another_tfidf_corpus + more_documents lsi_vec = model[tfidf_vec] ... 3.Random Projections, RP model = models.RpModel(tfidf_corpus, num_topics=500) 4.Latent Dirichlet Allocation, LDA model = models.LdaModel(corpus, id2word=dictionary, num_topics=100) 5.Hierarchical Dirichlet Process, HDP model = models.HdpModel(corpus, id2word=dictionary)

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册