gentang / intro_ds Goto Github PK
View Code? Open in Web Editor NEWCode to accompany Mastering Data Science from PT press
License: Apache License 2.0
Code to accompany Mastering Data Science from PT press
License: Apache License 2.0
唐老师,
在阅读到程序清单5-7时,我有个疑惑:
def evaluation(re):
"""
计算预测结果的查准查全率以及f1
参数
----
re :DataFrame,预测结果,里面包含两列:真实值‘lable_code’、预测值‘pred’
"""
bins = np.array([0, 0.5, 1])
label = re["label_code"]
pred = re["pred"]
tp, fp, fn, tn = np.histogram2d(label, pred, bins=bins)[0].flatten()
precision = tp / (tp + fp) # 0.951
recall = tp / (tp + fn) # 0.826
f1 = 2 * precision * recall / (precision + recall) # 0.884
print("查准率: %.3f, 查全率: %.3f, f1: %.3f" % (precision, recall, f1))
tp, fp, fn, tn = np.histogram2d(label, pred, bins=bins)[0].flatten()
我查阅了np.histogram2d的帮助文档,我觉得返回的顺序应当是tn,fp,fn,tp呀?
这是我认为返回的H:
H[0][0]对应TN,H[0][1]对应FP,H[1][0]对应FN,H[1][1]对应TP。
我也用一个小例子试了一下(这个例子里的tp=3, fp=2, fn=1, tn=1)
bins=np.array([0, 0.5, 1])
x=pd.Series([0, 1, 0, 1, 1, 1, 0])
y=pd.Series([1, 1, 0, 0, 1, 1, 1])
a, b, c, d = np.histogram2d(x,y,bins=bins)[0].flatten()
运行结果如下:
In [119]: a,b,c,d
Out[119]: (1.0, 2.0, 1.0, 3.0)
我不知道是否np.histogram2d的帮助文档没有理解到位?还请唐老师指点一二。
从csdn过来,非常感谢辛劳和无私的付出,看到这个repo都是源码,不如选择使用notebook来发布课程,这样可以方便学员快速运行代码和看到效果
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.