- 博客(5)
- 收藏
- 关注
转载 【Python 10.29】朴素贝叶斯算法思路(naïve Bayes)
Training naïve BayesTo train your naïve Bayes classifier, you have to perform the following steps:1) Get or annotate a dataset with positive and negative tweets2) Preprocess the tweets: process_tweet(tweet) ➞ [w1, w2, w3, ...]: Lowercase Remo
2021-10-29 14:43:28
187
原创 【python 10.27】共现矩阵
代码如下,关键代码已经注释import timeimport xlrdimport numpy as npimport sys#读取excel表格def read(path): data = xlrd.open_workbook(path) sheet_1_by_index = data.sheet_by_index(0) #读取表一 title = sheet_1_by_index.col_values(2) #第三列 n_of_rows = s.
2021-10-27 22:43:31
951
1
原创 【python10.20】词语按照出现次数降序排列
基本思路:首先将list存为set集合,然后计算set中各元素key的出现次数value保存到字典中,最后根据字典dict的value进行排序。text = “/给定/文字/,/内容/不限/”text1=text.split("/")#按照分隔符“/”对整个文本进行切割set1=set(text1)#set函数对text文本进行降重dict1={}#设定一个空值给dict1,方便后续for循环赋值for item in set1: dict1.update({item:t
2021-10-20 21:15:28
1703
原创 【python 10.20】HanoiTower
塔的移动可以用递归函数非常简单地实现。请编写move(n, a, b, c)函数,它接收参数n,表示3个柱子A、B、C中第1个柱子A的盘子数量,然后打印出把所有盘子从A借助B移动到C的方法。解题思路:利用递归,由果倒因,已知n=2的时候打印结果如下“A-->B"“A-->C"“B-->C"代码结果如下:def move(n,a,b,c): if n==1: print(a,"-->",c) else: ..
2021-10-20 21:12:25
234
原创 【python学习10.18】读取excel文件(xlrd)
一、 下载xlrdxlrd需要下载,代码如下:pip install xlrd出现错误:'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件。错误原因:没有加入环境变量解决方法:新建路径,添加环境变量出现警告:WARNING: You are using pip version 21.2.3; however, version 21.3 is available.You should consider upgrading via the 'C:\Users\A.
2021-10-18 23:10:55
549
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人