【機(jī)器學(xué)習(xí)基礎(chǔ)】用Python畫出幾種常見機(jī)器學(xué)習(xí)二分類損失函數(shù)
在二分類的監(jiān)督學(xué)習(xí)中,支持向量機(jī)、邏輯斯諦回歸與最大熵模型、提升方法各自使用合頁(yè)損失函數(shù)、邏輯斯諦損失函數(shù)、指數(shù)損失函數(shù),分別寫為:
這 3 種損失函數(shù)都是 0-1 損失函數(shù)的上界,具有相似的形狀。(見下圖,由代碼生成)
import numpy as npimport mathimport matplotlib.pyplot as pltplt.rcParams['font.sans-serif'] = ['SimHei']plt.rcParams['axes.unicode_minus'] = Falseplt.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 < 0y_hinge = 1.0 - xy_hinge[y_hinge < 0] = 0plt.plot(x, y_01, 'g-', mec='k', label='(0/1損失)0/1 Loss', lw=2)plt.plot(x, y_hinge, 'b-', mec='k', label='(合頁(yè)損失)Hinge Loss', lw=2)plt.plot(x, boost, 'm--', mec='k', label='(指數(shù)損失)Adaboost Loss', lw=2)plt.plot(x, logi, 'r-', mec='k', label='(邏輯斯諦損失)Logistic Loss', lw=2)plt.grid(True, ls='--')plt.legend(loc='upper right',fontsize=15)plt.xlabel('函數(shù)間隔:$yf(x)$',fontsize=20)plt.title('損失函數(shù)',fontsize=20)plt.show()

往期精彩回顧
獲取一折本站知識(shí)星球優(yōu)惠券,復(fù)制鏈接直接打開:
https://t.zsxq.com/y7uvZF6
本站qq群704220115。
加入微信群請(qǐng)掃碼:
評(píng)論
圖片
表情
