机器学习实战-python3勘误
工具
推荐jupyter notebook
使用jupyter notebook之前,命令行、sublime、资源管理器之间来回切换,很不方便。
勘误
一是针对python3的兼容代码,二是书上有些代码就是错的,请酌情修改。
注意python3所有的print后面都要有括号,这个每一章都要修改,下面不再赘述。
代码文件修改后,要重新引入文件
from imp import relaod
reload(bayes)
- P45
getNumLeafs和getTreeDepth函数
myTree.keys()[0]#修改为list(myTree.keys())[0]
- P50
storeTree函数
open(filename,'w')#修改为open(filename,'wb')grabTree函数
open(filename)#修改为open(filename,'rb')
- P66
textParse函数
listOfTokens = re.split(r'\W*', bigString)#改为listOfTokens = re.split(r'\W+', bigString)spamTest函数
trainingSet = range(50)#改为trainingSet = list(range(50))
setofWord2Vec#改为bagofWord2Vec
- P69
calMostFreq函数
freqDict.iteritems()#改为freqDict.items()localWords函数
trainingSet=range(2*minLen)#改为trainingSet=list(range(2*minLen))
- P82
stocGradAscent1函数
dataIndex=range(m)#改为dataIndex=list(range(m))
- P156
crossValidation函数
indexList=range(m)#改为indexList=list(range(m))
- P162
binSplitDataSet函数
去掉mat0和mat1后面的[0]
- P164
chooseBestSplit函数
for splitVal in set(dataSet[:,featIndex])#改为for splitVal in set(dataSet[:,featIndex].T.tolist()[0])
- P178
from Tkinter import *#改为from tkinter import *
- P179
reDraw.canvas.show()#改为reDraw.canvas.draw()
- P186
loadDataSet函数替换为
def loadDataSet(fileName): dataMat = [] fr = open(fileName)for line in fr.readlines():curLine = line.strip().split('\t')temp=[]for i in curLine:temp.append(float(i))dataMat.append(temp)return dataMat
- P205
createC1函数
return map(frozenset,C1)#改为return list(map(frozenset,C1))scanD函数
if not ssCnt.has_key(can)#改为if not can in ssCnt
- P211
ruleFromConseq函数
在m=len(H[0])下面插入
if m==1:H = calcConf(freqSet, H, supportData, brl, minConf)
- P228
createTree函数
for k in headerTabel.keys()#改为for k in list(headerTabel.keys())
- P233
mineTree函数
bigL = [v[0] for v in sorted(headerTable.items(), key=lambda p: p[1])]#改为bigL = [v[0] for v in sorted(headerTable.items(), key=lambda p: p[1][0])]
- P246
loadDataSet函数替换为
def loadDataSet(fileName, delim='\t'):fr = open(fileName)stringArr = [line.strip().split(delim) for line in fr.readlines()]datArr=[]for line in stringArr:data=[]for j in line:data.append(float(j))datArr.append(data)return mat(datArr)
- P266
printMat函数替换为
def printMat(inMat, thresh=0.8):for i in range(32):for k in range(32):if float(inMat[i,k]) > thresh:print (1,end=" ")else: print (0,end=" ")print('\n')
- P274
read_input函数替换为
def read_input(file):for line in file.readlines():yield line.rstrip()#rstrip删除line末尾的字符,默认为空格print >> sys.stderr, "report:still alive"
#改为print (sys.stderr.writelines("report: still alive"))
机器学习实战-python3勘误相关推荐
- 机器学习实战 Python3 实现
之前在学习<机器学习实战>这本书,本来说在 CSDN 上更新自己的学习进度,后来因为代码还要重新贴,就直接在 GitHub 上 备份了. 有学习兴趣的小伙伴可以去 GitHub 上支持一下 ...
- Python3《机器学习实战》学习笔记(八):支持向量机原理篇之手撕线性SVM
原 Python3<机器学习实战>学习笔记(八):支持向量机原理篇之手撕线性SVM 置顶 2017年09月23日 17:50:18 阅读数:12644 转载请注明作者和出处: https: ...
- 【机器学习实战 第九章】树回归 CART算法的原理与实现 - python3
本文来自<机器学习实战>(Peter Harrington)第九章"树回归"部分,代码使用python3.5,并在jupyter notebook环境中测试通过,推荐c ...
- 速收藏,《机器学习实战》Python3环境算法实现代码
↑ 点击上方[计算机视觉联盟]关注我们 [导读]<机器学习实战>是较为广泛地学习机器学习的教材,但其配套代码多由Python2实现,故对书中的代码重新做了整理,全部代码可在python3环 ...
- apriori算法代码_资源 | 《机器学习实战》及代码(基于Python3)
〇.<机器学习实战> 今天推荐给大家的是<机器学习实战>这本书. 机器学习作为人工智能研究领域中一个极其重要的研究方向(一文章看懂人工智能.机器学习和深度学习),在当下极其热门 ...
- python3《机器学习实战系列》学习笔记----3.2 决策树实战
前言 一.ID3算法构造决策树 1.1 背景 1.2 信息增益计算 1.3 递归生成决策树 二.使用Matplotlib注解绘制树形图 2.1 Matplotlib注解 2.2 构造注解树 三.测试和 ...
- Python3《机器学习实战》学习笔记(三):决策树实战篇
转载请注明作者和出处: http://blog.csdn.net/c406495762 运行平台: Windows Python版本: Python3.x IDE: Sublime text3 ...
- Python3《机器学习实战》学习笔记(九):支持向量机实战篇之再撕非线性SVM
转载请注明作者和出处: http://blog.csdn.net/c406495762 **机器学习知乎专栏:**https://zhuanlan.zhihu.com/ml-jack **CSDN博客 ...
- Python3:《机器学习实战》之支持向量机(2)简化版SMO
Python3:<机器学习实战>之支持向量机(2)简化版SMO 转载请注明作者和出处:http://blog.csdn.net/u011475210 代码地址:https://github ...
最新文章
- 【转载】mysql主键的缺少导致备库hang
- 我的微软最有价值专家(Microsoft MVP)之路
- QT5中如何使用SQLite
- C语言再学习 -- 转义字符
- linux远程打开windows程序,为新手讲解Linux和Windows系统的远程桌面访问知识
- asp.net ftp上传文件到服务器,.net 文件上传到服务器上
- flutter怎么手动刷新_Flutter 小技巧实现通用的局部刷新
- 全能型 uWSGI 配置
- tensorflow have no attribute enable_eager_execution() 问题解决
- Java疯狂讲义(第8章——泛型)(读书笔记)
- 魏俊妮《人力资源体系搭建专家》
- 如何在IDEA中配置Tomcat,解决配置时No Artifacts Configured问题
- 夜雨数竞笔记-极限(11)-欧拉常数
- Cluster sampling整群抽样例子
- Python手撸机器学习系列(十六):循环神经网络RNN的实现
- UV系和相机坐标系相互转换
- windows Outlook邮箱无法连接服务器
- 小程序和APP谁将主导未来?
- openwrt重启后,修复dns
- 计算机软考高级好考吗?需要备考多久?