当前位置:网站首页>Sklearn through precision_ recall_ Curve get F1 maximum
Sklearn through precision_ recall_ Curve get F1 maximum
2022-07-20 06:14:00 【V, Chao】
20220718 -
In order to check the performance of classifiers , Make use of precision_recall_curve
To get accuracy and recall , And calculate F1 The maximum of , Problem of passing threshold , Check the maximum performance of the classifier , The code is as follows , And then calculate
precision, recall, thresholds = precision_recall_curve(y_test, y_test_predicted_probas)
f1_scores = 2*recall*precision/(recall+precision)
print('Best threshold: ', thresholds[np.argmax(f1_scores)])
print('Best F1-Score: ', np.max(f1_scores))
But in the process , Will meet RuntimeWarning: invalid value encountered in true_divide
, This warning , Then output the highest F1 when , The result is nan.
Before , Because it doesn't happen every time , So I didn't care about it . Now it's time to do experiments on a large scale , I often report mistakes , So Google checked , In essence, the error reporting is generally clear , That is, some values do not meet the division conditions , But I tried to add a very small number , It didn't work .
Then I searched and found the corresponding solution .
precision, recall, thresholds = precision_recall_curve(y_test, y_test_predicted_probas)
numerator = 2 * recall * precision
denom = recall + precision
f1_scores = np.divide(numerator, denom, out=np.zeros_like(denom), where=(denom!=0))
max_f1 = np.max(f1_scores)
max_f1_thresh = thresholds[np.argmax(f1_scores)]
Essentially , Let division avoid these values .
边栏推荐
- Zabbix5.0 configuring enterprise wechat alarm
- 使用pytorch自己构建网络模型实战
- 基于ABP实现DDD--仓储实践
- MySQL help post
- Cordova fragment onactivityresult has no callback
- 【智能硬件】Jetson nana 扩展显存(内存)
- [intelligent hardware] Jetson Nana extended video memory (memory)
- 7.18模拟赛总结
- 「接口测试入门课」打卡学习 day03:理解接口测试的关键逻辑
- "Introduction to interface testing" punch in learning day03: understand the key logic of interface testing
猜你喜欢
MySQL 字符串操作(substr-截取、locate-instr-position子父串判断)
FAST-LIO2代码解析(一)
Shell 基本命令操作(seq-序列、tr-转换)
(2) Fastai 2019 part2 key refining
【体系结构 四 存储结构】
Security researchers found malware targeting industrial operators
Selected questions: force deduction 565 Array nesting
Chapter VIII tasks and functions
TCP实验验证
DDD based on ABP -- warehousing practice
随机推荐
我的创作纪念日
【牛客刷题】/*日常四道编程小题分享*/
Flutter启动流程(Isolate机制+创建流程+线程练习)
使用pytorch自己构建网络模型实战
MySQL help post
1. 课程内容介绍
Shell query Prometheus data
Award winning research | what does the perfect ar development platform look like to make virtual reality?
洛谷P1792 [国家集训队]种树 题解
day03_2_流程控制
Interpretation of HB 5469 combustion test method for non-metallic materials in civil aircraft cabin
An improved one millisecond mobile backbone paper notes
【深度】新派LaaS协议Elephant:重振DeFi赛道发展的关键
View的measure测量过程梳理
Selenium foundation + environment configuration
2022年7月17日 暑假第一周训练
6. [WebGIS practice] software operation -- WebGIS development environment construction
My creation anniversary
Cours d'introduction aux tests d'interface
字节跳动(抖音)软件测试月薪23K岗、技术二面面试题最新出炉