当前位置:网站首页>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 .^_^
边栏推荐
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
- shell基础知识(退出控制、输入输出等)
- Substance Designer 2021软件安装包下载及安装教程
- The world is exploding, and the Google server has collapsed
- Spirng @Conditional 条件注解的使用
- SSTI 模板注入漏洞总结之[BJDCTF2020]Cookie is so stable
- logstash
- 2022.07.24(LC_6125_相等行列对)
- Table partition of MySQL
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary problem solution (g, J, K, l)
猜你喜欢

ECCV2022 | TransGrasp类级别抓取姿态迁移

Eccv2022 | transclassp class level grab posture migration

零基础学习CANoe Panel(15)—— 文本输出(CAPL Output View )

A turbulent life

2022.07.24 (lc_6124_the first letter that appears twice)

AtCoder Beginner Contest 261 F // 树状数组

massCode 一款优秀的开源代码片段管理器

基于JEECG制作一个通用的级联字典选择控件-DictCascadeUniversal
![[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)](/img/a6/c45a504722f5fd6e3c9fb8e51c6bb5.png)
[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)
![[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+](/img/d8/90116f967ef0f5920848eca1f55cdc.png)
[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
随机推荐
Does MySQL have flush privileges
Shell常用脚本:判断远程主机的文件是否存在
logstash
MySQL implements inserting data from one table into another table
Perf performance debugging
【问题解决】ibatis.binding.BindingException: Type interface xxDao is not known to the MapperRegistry.
我想问DMS有没有定时备份某一个数据库的功能?
massCode 一款优秀的开源代码片段管理器
Software testing interview question: Please list the testing methods of several items?
零基础学习CANoe Panel(14)——二极管( LED Control )和液晶屏(LCD Control)
2022.07.24 (lc_6126_design food scoring system)
零基础学习CANoe Panel(13)—— 滑条(TrackBar )
【问题解决】org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession.1 字节的 UTF-8 序列的字
word样式和多级列表设置技巧(二)
Selenium use -- installation and testing
Can flinkcdc import multiple tables in mongodb database together?
手写一个博客平台~第一天
A hard journey
Eccv2022 | transclassp class level grab posture migration
Lu MENGZHENG's "Fu of broken kiln"