合页损失,铰链损失_单点铰链损失功能 使用Python的线性代数

本文介绍了铰链损失作为机器学习中最大余量分类的损失函数,特别是在支持向量机(SVM)中的应用。讨论了铰链损失的一般形式,并提供了一个Python函数来计算给定点的铰链损失,强调了函数在代码中的可复用性和模块化优点。
摘要由CSDN通过智能技术生成

合页损失,铰链损失

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算法的主要部分。

The 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 = 𝜭.x

其中, Y是标签, 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 Single point with given 𝜭. Functions provide the reproducibility and Modularity to the code and therefore we dedicated a separate tutorial for Hinge Loss for Single Point.

这是常规的铰链损耗函数 ,在本教程中,我们将定义一个函数,用于计算给定𝜭的单点的铰链损耗。 函数提供了代码的可重复性和模块化性,因此我们专门为单点铰链损耗提供了单独的教程。

用于单点铰链损耗的Python函数 (Python Function for Hinge Loss for Single Point)

# Linear Algebra Learning Sequence
# Hinge Loss using linear algebra

import numpy as np

# Defining a function for Hingle Loss for Single Point
def hingeforsingle(feature, theta, label):
    y = np.matmul(theta/10, feature)
    hingeloss = np.max([0.0, (1 - label*y)])
    return hingeloss

# Main code
feature = np.array([2,4,4,3,6,9,7,4])
theta = np.array([3,3,3,3,-3,-3,-3,-3])

print('Given point with 8 features : ', feature)
print('Theta : ', theta)

label = 1

hingeloss = hingeforsingle(feature, theta, label)
print("\nThe hinge loss for the given point is :", hingeloss)

Output:

输出:

Given point with 8 features :  [2 4 4 3 6 9 7 4]
Theta :  [ 3  3  3  3 -3 -3 -3 -3]

The hinge loss for the given point is : 4.8999999999999995


翻译自: https://www.includehelp.com/python/function-for-hinge-loss-for-single-point.aspx

合页损失,铰链损失

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值