程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Machine Learning Basics] Draw several common machine learning binary loss functions in Python

編輯:Python


in supervised learning for binary classification,支持向量機、邏輯斯谛回歸與最大熵模型、The boosting methods each use a hinge loss function、Logistic loss function、指數損失函數,are written as:

這 3 All kinds of loss functions are 0-1 損失函數的上界,have a similar shape.(見下圖,由代碼生成)

import
numpy
as
np

import math
import matplotlib. pyplot as plt
plt. rcParams[ 'font.sans-serif'] = [ 'SimHei']
plt. rcParams[ 'axes.unicode_minus'] = False
plt. figure( figsize =( 10, 8))
x = np. linspace( start = - 1, stop = 2, num = 1001, dtype = np. float)
logi = np. log( 1 + np. exp( - x)) / math. log( 2)
boost = np. exp( - x)
y_01 = x < 0
y_hinge = 1.0 - x
y_hinge[ y_hinge < 0] = 0


plt. plot( x, y_01, 'g-', mec = 'k', label = '(0/1損失)0/1 Loss', lw = 2)
plt. plot( x, y_hinge, 'b-', mec = 'k', label = '(合頁損失)Hinge Loss', lw = 2)
plt. plot( x, boost, 'm--', mec = 'k', label = '(指數損失)Adaboost Loss', lw = 2)
plt. plot( x, logi, 'r-', mec = 'k', label = '(Logistic loss)Logistic Loss', lw = 2)
plt. grid( True, ls = '--')
plt. legend( loc = 'upper right', fontsize = 15)
plt. xlabel( '函數間隔:$yf(x)$', fontsize = 20)
plt. title( '損失函數', fontsize = 20)
plt. show()
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.





  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved