You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

confusion matrix.py 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- coding: utf-8 -*-
  2. # ---
  3. # jupyter:
  4. # jupytext_format_version: '1.2'
  5. # kernelspec:
  6. # display_name: Python 3
  7. # language: python
  8. # name: python3
  9. # language_info:
  10. # codemirror_mode:
  11. # name: ipython
  12. # version: 3
  13. # file_extension: .py
  14. # mimetype: text/x-python
  15. # name: python
  16. # nbconvert_exporter: python
  17. # pygments_lexer: ipython3
  18. # version: 3.5.2
  19. # ---
  20. # # 混淆矩阵(confusion matrix)
  21. #
  22. # 混淆矩阵是用来总结一个分类器结果的矩阵。对于k元分类,其实它就是一个$k \times k$的表格,用来记录分类器的预测结果。
  23. #
  24. # 对于最常见的二元分类来说,它的混淆矩阵是2乘2的,如下
  25. # ![confusion_matrix1](images/confusion_matrix1.png)
  26. #
  27. # * `TP` = True Postive = 真阳性
  28. # * `FP` = False Positive = 假阳性
  29. # * `FN` = False Negative = 假阴性
  30. # * `TN` = True Negative = 真阴性
  31. #
  32. # 你要的例子来了。。。比如我们一个模型对15个样本进行预测,然后结果如下。
  33. #
  34. # * 预测值:1 1 1 1 1 0 0 0 0 0 1 1 1 0 1
  35. # * 真实值:0 1 1 0 1 1 0 0 1 0 1 0 1 0 0
  36. #
  37. # ![confusion_matrix2](images/confusion_matrix2.png)
  38. #
  39. #
  40. # 这个就是混淆矩阵。混淆矩阵中的这四个数值,经常被用来定义其他一些度量。
  41. #
  42. #
  43. # ### 准确度
  44. # ```
  45. # Accuracy = (TP+TN) / (TP+TN+FN+TN)
  46. # ```
  47. #
  48. # 在上面的例子中,准确度 = (5+4) / 15 = 0.6
  49. #
  50. #
  51. #
  52. # ### 精度(precision, 或者PPV, positive predictive value)
  53. # ```
  54. # precision = TP / (TP + FP)
  55. # ```
  56. # 在上面的例子中,精度 = 5 / (5+4) = 0.556
  57. #
  58. #
  59. #
  60. # ### 召回(recall, 或者敏感度,sensitivity,真阳性率,TPR,True Positive Rate)
  61. #
  62. # ```
  63. # recall = TP / (TP + FN)
  64. # ```
  65. #
  66. # 在上面的例子中,召回 = 5 / (5+2) = 0.714
  67. #
  68. #
  69. #
  70. # ### 特异度(specificity,或者真阴性率,TNR,True Negative Rate)
  71. # ```
  72. # specificity = TN / (TN + FP)
  73. # ```
  74. #
  75. # 在上面的例子中,特异度 = 4 / (4+2) = 0.667
  76. #
  77. #
  78. #
  79. # ### F1-值(F1-score)
  80. # ```
  81. # F1 = 2*TP / (2*TP+FP+FN)
  82. # ```
  83. # 在上面的例子中,F1-值 = 2*5 / (2*5+4+2) = 0.625
  84. #
  85. #
  86. #

机器学习越来越多应用到飞行器、机器人等领域,其目的是利用计算机实现类似人类的智能,从而实现装备的智能化与无人化。本课程旨在引导学生掌握机器学习的基本知识、典型方法与技术,通过具体的应用案例激发学生对该学科的兴趣,鼓励学生能够从人工智能的角度来分析、解决飞行器、机器人所面临的问题和挑战。本课程主要内容包括Python编程基础,机器学习模型,无监督学习、监督学习、深度学习基础知识与实现,并学习如何利用机器学习解决实际问题,从而全面提升自我的《综合能力》。