MultiClass Kernel SVM

这篇博客记录了个人学习多类别核支持向量机(MultiClass Kernel SVM)的过程,特别是在TensorFlow框架下的实现。通过引入径向基函数(RBF)核,讨论如何在分类任务中应用SVM。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

供个人学习记录,来源于:
https://github.com/machinelearningmindset/TensorFlow-Course#why-use-tensorflow

import os 
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' 
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from sklearn import datasets
from tensorflow.python.framework import ops
from tensorflow.examples.tutorials.mnist import input_data
from sklearn.decomposition import PCA

batch_size = 50
num_steps = 1000
log_steps = 50
is_evaluation = True
gamma = -15.0
initial_learning_rate = 0.01

def cross_class_label_fn(A):
    """
    This function take the matrix of size (num_classes, batch_size) and return the cross-class label matrix
    in which Yij are the elements where i,j are class indices.
    :param A: The input matrix of size (num_classes, batch_size).
    :return: The output matrix of size (num_classes, batch_size, batch_size).
    """
    label_class_i = tf.reshape(A, [num_classes, 1, batch_size])
    label_class_j = tf.reshape(label_class_i, [num_classes, batch_size, 1])
    returned_mat = tf.matmul(label_class_j, label_class_i)
    return returned_mat

# Compute SVM loss.
def loss_fn(alpha, label_placeholder):
    term_1 = tf.reduce_sum(alpha)
    alpha_cross = tf.matmul(tf.transpose(alpha), alpha)  #shape(batch_size,batch_size)
    cross_class_label = cross_class_label_fn(label_placeholder)  #shape(num_classes,batch_si
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值