TFSVM:用TensorFlow实现SVM

较基础的SVM,后续会加上多分类以及高斯核 Talk is cheap, show me the code import tensorflow as tffrom sklearn.base import BaseEstimator, ClassifierMixinimport numpy as npclass TFSVM(BaseEstimator, ClassifierMixin)...
摘要由CSDN通过智能技术生成

较基础的SVM,后续会加上多分类以及高斯核
Talk is cheap, show me the code

import tensorflow as tf
from sklearn.base import BaseEstimator, ClassifierMixin
import numpy as np

class TFSVM(BaseEstimator, ClassifierMixin):

    def __init__(self, 
        C = 1, kernel = 'linear', 
        learning_rate = 0.01, 
        training_epoch = 1000, 
        display_step = 50,
        batch_size = 50,
        random_state = 42):
        #参数列表
        self.svmC = C
        self.kernel = kernel
        self.learning_rate = learning_rate
        self.training_epoch = training_epoch
        self.display_step = display_step
        self.random_state = random_state
        self.batch_size = batch_size

    def reset_seed(self):
        #重置随机数
        tf.set_random_seed(self.random_state)
        np.random.seed(self.random_state)

    def random_batch(self, X, y):
        #调用随机子集,实现mini-batch gradient descent
        indices = np.random.randint(1, X.shape[0], self.batch_size)
       
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值