Comments (12)
你说的是对的,这个肯定是错误。不止这里有问题,12-3.py也有这个问题。作者好像对于FreqDist这个理解有误了。
dist_max=set(fdist[0:50])
作者理解的是fdist应该是从大到小的排列,所以才会用[0:50],但是实际上fdist是无序排列的。这也导致了之后的代码都是错的
from 1book.
多谢楼上的回答。
from 1book.
多谢楼上的楼上解答了,囧
from 1book.
请问大家改对以后算出的准确率是多少啊,我的是100%....
from 1book.
@UnnameBao 我也是100%哎
from 1book.
@UnnameBao @lhwlhw90 请问你们是怎么改正的?求代码,我机器学习刚入门,求指教
from 1book.
@aviraonepiece 我是这样改的
把
fdist = FreqDist(dist).keys()
dist_max=set(fdist[0:50])
dist_min = set(fdist[-50:])
改成
fdist = sorted(FreqDist(dist).items(),key = operator.itemgetter(1),reverse = True) #获得操作命令使用频率并排序
dist_max = set([item[0] for item in fdist[:50]]) #取出前50个操作命令的指令
dist_min = set([item[0] for item in fdist[-50:]]) #取出前50个操作命令的指令
from 1book.
@UnnameBao 十分感谢!!!!!!follow
from 1book.
可以利用pandas来做:
import pandas as pd
fdist=nltk.FreqDist(dist)
ser=pd.Series(fdist)
sersort = ser.sort_values()#按照升序排列
dist_min = sersort.index[0:50].tolist()#取出频率最小的前50个操作命令
dist_max = sersort.index[-50:].tolist()#取出频率最大的最后50个操作命令
from 1book.
@xiaoyuge16 学习了,pandas了解的少。
from 1book.
到这里才发现代码是python2,orz。
FreqDist.keys()在python3返回的不再是一个列表了
需要自己转换一下
from 1book.
我用的python3.8,这部分代码我改成这样:
fdist = FreqDist(dist)
keys = np.array(fdist.most_common(len(fdist)))[:,0].tolist()
dist_max = keys[:50] #取出频率最大的前50个操作命令
dist_min = keys[-50:] #取出频率最小的前50个操作命令
改完以后算出的准确率是100%,就很迷。。
from 1book.
Related Issues (20)
- 样本无法读取 HOT 1
- 所有包都按书里说的安装成功,但是运行还是有错误。 HOT 2
- 使用K近邻算法检测异常操作(一)的标识文件在哪里获取? HOT 1
- 求助代码
- P201中的x和_y,以及系统的输入输出问题
- 2017年11月第一版第三次印刷的书从第126直接跳到143了 HOT 1
- 第14章神经网络算法识别MNIST手写数字案例中数据集不能在线下载 HOT 1
- 书中的一些问题还有一个疑问!!!(2017年11月第1版第3次印刷)
- 关于1book MasqueradeDat/label.txt一点疑问 HOT 3
- 报错了,在win7上,咋整
- 大神,有关于这本书的微信读者群吗?
- 15-3.py与书本上的代码块不符,有没更新的?
- 关于code部分(5-4.py)有点问题咨询
- It is obvious between the original images and cloaked ones HOT 1
- 请问三本书的代码内容是否更新到python3版本
- 与书上的结果不同
- HMM识别XSS攻击(1) HOT 4
- P132中倒数第四行勘误 HOT 2
- 勘误
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 1book.