当前位置:网站首页>How to understand metrics in keras
How to understand metrics in keras
2022-07-25 12:59:00 【51CTO】
Keras The library provides a method to calculate and report a set of standard indicators when training deep learning models . In addition to providing standard indicators for classification and regression problems ,Keras It also allows you to define and report your own custom metrics during in-depth learning . If you want to better capture the performance metrics of the model during training , This will be particularly useful .
In this tutorial , You will learn how to use built-in metrics , And how to Keras Define and use your own indicators when training the deep learning model . After completing this tutorial , You will learn :
- Keras How indicators work and how to use them when training models .
- How to use working examples in Keras Regression and classification indicators are used in .
- How to use working examples in Keras Define and use your own custom metrics .
1 Keras indicators
Keras Allows you to list indicators to be monitored during model training . You can specify by “metrics” Parameters are... On the model compile() Function provide function name ( Or function name alias ) List to do this . for example :
The specific indicators you list can be Keras Name of function ( Such as mean_squared_error) Or string aliases of these functions ( Such as “mse”).
The measurements are recorded on each of the training data sets epoch At the end of . If a validation data set is also provided , The recorded metrics are also calculated for the validation dataset .
All indicators are output and called in detail fit() Report in the history object returned by the function . In both cases , The name of the measurement function is used as the key of the measurement . For the indicators of the validation data set ,“val_” The prefix is added to the key .
Loss function and clearly defined Keras Indicators can be used as training indicators .
2 Keras Regression index
Here is what you can do in Keras List of indicators used for regression problems in .
- Mean square error :mean_squared_error、MSE or
- Mean absolute error :mean_absolute_error, MAE, mae
- Mean absolute percentage error :mean_absolute_percentage_error、MAPE、mape
- Cosine proximity :cosine_proximity, cosine
The above four indicators , The smaller the value. , The better the fitting degree of the model , But it does not mean that the prediction effect of the model is better , It can only be assumed that the model with good fitting effect has better prediction effect . In other words, it's not too rigorous but easy to remember : The smaller the above index value , The better the model predicts .
The following example demonstrates this of a simple artificial regression problem 4 Built in regression indicators .
Be careful : Your results may vary due to the randomness of the algorithm or evaluation process or differences in numerical accuracy . Consider running the example several times and comparing the average results .
Running this example will run on each epoch Print measurements at the end .
Then create during training 4 A line chart of indicators .

Please note that , The indicator is to use the string alias value [‘mse‘, ‘mae‘, ‘mape‘, ‘cosine‘] designated , And use their extension function names as history Key value reference on object .
We can also use the extended name to specify the indicator , As shown below :
If the function name is imported into the script , We can also specify them directly .
You can also use the loss function as a measure . for example , You can put the mean square logarithmic error (mean_squared_logarithmic_error,MSLE or msle) The loss function is used as a measure , As shown below :
3 Keras Classification index
Here is what you can do in Keras List of indicators used to classify problems in .
- Binary precision :binary_accuracy,acc
- Classification accuracy :categorical_accuracy, acc
- Sparse classification accuracy :sparse_categorical_accuracy
- Top k Categorical Accuracy:top_k_categorical_accuracy( You need to specify one k Parameters )
- sparse Top k Classification accuracy :sparse_top_k_categorical_accuracy( You need to specify k Parameters )
Accuracy is special . Whether your problem is a two class problem or a multi class problem , You can specify “accuracy” Indicators to report accuracy .
The following is an example of a binary classification problem , It demonstrates the built-in accuracy index .
Be careful : Your results may vary due to the randomness of the algorithm or evaluation process or differences in numerical accuracy . Consider running the example several times and comparing the average results .
Running this example will report the accuracy at the end of each training period .

4 stay Keras Custom indicators in
You can also call compile() Function and define your own indicators in “metrics” Specify the function name in the function list of the parameter .
I haven't used custom indicators yet , I haven't even seen others use . Therefore, there are few guesses about the application of custom indicators . When you choose Custom indicators , Ask yourself at least three questions : Can common indicators really not meet the demand ? Are the commonly used indicators used to measure the model selected correctly , Is there a classification index to measure the regression problem ? My math is good enough to understand correctly “metrics” What functions in the function list of parameters are used for ? At least I was blocked by the first question . In the future, I will add some custom indicators .^_^
边栏推荐
- Leetcode 1184. distance between bus stops
- [rust] reference and borrowing, string slice type (& STR) - rust language foundation 12
- 程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠
- 吕蒙正《破窑赋》
- 跌荡的人生
- 如何理解Keras中的指标Metrics
- Monit installation and use
- Use of Spirng @conditional conditional conditional annotation
- word样式和多级列表设置技巧(二)
- conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题
猜你喜欢

Azure Devops (XIV) use azure's private nuget warehouse

2022.07.24 (lc_6126_design food scoring system)
![[today in history] July 25: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone](/img/f6/d422367483542a0351923f2df27347.jpg)
[today in history] July 25: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone

【问题解决】org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession.1 字节的 UTF-8 序列的字

【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12
软件测试流程包括哪些内容?测试方法有哪些?

7行代码让B站崩溃3小时,竟因“一个诡计多端的0”

Detailed explanation of flex box

If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing

MLX90640 红外热成像仪测温传感器模块开发笔记(五)
随机推荐
Mysql 远程连接权限错误1045问题
yum和vim须掌握的常用操作
Force deduction 83 biweekly T4 6131. The shortest dice sequence impossible to get, 303 weeks T4 6127. The number of high-quality pairs
Spirng @Conditional 条件注解的使用
Kyligence was selected into Gartner 2022 data management technology maturity curve report
What does the software testing process include? What are the test methods?
Azure Devops (XIV) use azure's private nuget warehouse
2022.07.24(LC_6124_第一个出现两次的字母)
Word style and multi-level list setting skills (II)
AtCoder Beginner Contest 261 F // 树状数组
Go: Gin custom log output format
公安部:国际社会普遍认为中国是世界上最安全的国家之一
【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021
web安全入门-UDP测试与防御
跌荡的人生
[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)
The programmer's father made his own AI breast feeding detector to predict that the baby is hungry and not let the crying affect his wife's sleep
Excuse me, using data integration to import data from PostgreSQL to MySQL database, emoj appears in some data fields
conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题
Shell常用脚本:判断远程主机的文件是否存在