合页损失,铰链损失_多点铰链损失功能 使用Python的线性代数
合頁損失,鉸鏈損失
Hinge Loss is a loss function used in Machine Learning for training classifiers. The hinge loss is a maximum margin classification loss function and a major part of the SVM algorithm.
鉸鏈損失是機器學習中用于訓練分類器的損失函數。 鉸鏈損失是最大余量分類損失函數,是SVM算法的主要部分。
Hinge loss function is given by:
鉸鏈損耗函數由下式給出:
LossH = max(0,(1-Y*y))
損耗H = max(0,(1-Y * y))
Where, Y is the Label and
其中, Y是標簽,
y = 𝜭.x
y = 𝜭.x
This is the general Hinge Loss function and in this tutorial, we are going to define a function for calculating the Hinge Loss for a multiple point (having one feature) with given 𝜭.
這是常規的Hinge Loss函數,在本教程中,我們將定義一個函數,用于計算給定𝜭的多點(具有一個特征)的Hinge Loss。
用于多點鉸鏈損失的Python代碼 (Python code for hinge loss for multiple points)
# Linear Algebra Learning Sequence # Hinge loss for Multiple Point import numpy as npdef hinge_loss_single(feature_vector, label, theta, theta_0):ydash = label*(np.matmul(theta,feature_vector) + theta_0)hinge = np.max([0.0, 1 - ydash*label])return hingedef hinge_loss_full(feature_matrix, labels, theta, theta_0):tothinge = 0num = len(feature_matrix)for i in range(num):tothinge = tothinge + hinge_loss_single(feature_matrix[i], labels[i], theta, theta_0)hinge = tothingereturn hingefeature_matrix = np.array([[2,2], [3,3], [7,0], [14,47]]) theta = np.array([0.002,0.6]) theta_0 = 0 labels = np.array([[1], [-1], [1], [-1]])hingell = hinge_loss_full(feature_matrix, labels, theta, theta_0)print('Data point: ', feature_matrix) print('\n\nCorresponding Labels: ', labels) print('\n\n Hingle Loss for given data :', hingell)Output:
輸出:
Data point: [[ 2 2][ 3 3][ 7 0][14 47]]Corresponding Labels: [[ 1][-1][ 1][-1]]Hingle Loss for given data : [0.986]翻譯自: https://www.includehelp.com/python/function-for-hinge-loss-for-multiple-points.aspx
合頁損失,鉸鏈損失
總結
以上是生活随笔為你收集整理的合页损失,铰链损失_多点铰链损失功能 使用Python的线性代数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前序遍历m-ary树_在Ruby中使用a
- 下一篇: 调用向量的第i维分量| 使用Python