svm

机器学习损失函数总结——SVM、朴素贝叶斯、HMM、AdaBoost、EM

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-23 03:46:09
损失函数总结(适用算法) 1. 对数损失函数 (朴素贝叶斯,EM,HMM) L(Y , P(Y | X)) = -log P(Y | X) 2. 平方损失函数(最小二乘法) L(y , f(x)) = 〖(y – f(x))〗^2 3. 指数损失函数(AdaBoost) L(y , f(x)) = exp[-yf(x)] 4. 合页损失函数(svm) L(y(wx+b)) = [1-y(wx+b)] + [z] + = z if z>0 else 0 5. 0-1损失函数 L(y , f(x)) = 1 if y ≠f(x) else y=f(x) 6. 交叉熵损失函数 L(y ̂,y)=-(ylog(y ̂ )+(1-y)log⁡(1-y ̂ )) 来源: CSDN 作者: 不会写代码的菜鸡程序猿 链接: https://blog.csdn.net/m0_38022672/article/details/103914839

理解SVM(附代码)

六眼飞鱼酱① 提交于 2020-01-21 12:41:10
参考内容: https://blog.csdn.net/weixin_39605679/article/details/81170300 SVM 支持向量机是一种二分类模型,它的基本模型是定义在特征空间上的间隔最大的分类器,SVM还包含核技巧,这使它可以成为非线性的分类器。SVM的学习策略就是间隔最大化。 算法原理 SVM 学习的基本思想就是求解能够正确划分训练数据集并且几何间隔距离最大的超平面。 对于线性可分的数据,超平面(w*x+b=0)有无穷多个,但是几何间隔最大的超平面是唯一的 几何间隔: 对于给定的数据集和超平面,定义超平面关于样本点(Xi,Yi)的几何间隔为 根据点到直线的距离 扩展到超平面距离为: 这个d 就是分类间隔。 ||W|| 表示w的二范数,即求所有元素的平方和,然后开方,比如对于二维平面: 分类器的好坏评定依据就是分类间隔W=2d的大小,W越大,我们认为超平面分类效果越好,现在问题变成了最大化问题 约束条件: 至此我们已经获得了目标函数的数学形式,但是为了求解w的最大值,我们需要解决下面问题: 1: 如何判断超平面将样本点正确分类。 2 : 我们知道了求距离d的最大值,首先需要找到支持向量上的点,如何从众多的点中 选出支持向量上的点呢? 上面需要面对的问题就是约束条件,也就是我们优化的变量d的取值范围受到了限制和约束条件。SVM算法通过一些巧妙的技巧

How to create training data for libsvm (as an svm_node struct)

谁都会走 提交于 2020-01-21 07:18:35
问题 I am trying to train an svm for a simple xor problem programmatically using libsvm to understand how the library works. The problem (i think) seems to be that i construct svm_node incorrectly; maybe i have trouble understanding the whole pointers to pointers thing. Could anybody help with this? I first construct a matrix for the xor problem then try to assign values from the matrix to svm_node (i am using 2 steps here because my real data will be in matrix format). When testing the model i

How to create training data for libsvm (as an svm_node struct)

限于喜欢 提交于 2020-01-21 07:18:11
问题 I am trying to train an svm for a simple xor problem programmatically using libsvm to understand how the library works. The problem (i think) seems to be that i construct svm_node incorrectly; maybe i have trouble understanding the whole pointers to pointers thing. Could anybody help with this? I first construct a matrix for the xor problem then try to assign values from the matrix to svm_node (i am using 2 steps here because my real data will be in matrix format). When testing the model i

支持向量机(SVM)中的对偶问题

时光总嘲笑我的痴心妄想 提交于 2020-01-18 17:29:49
前言 在SVM中有一个求极小值的问题转换过程,转换为一个对偶问题,但是我不太清楚这个问题为什么可以转换,而且还不太清楚为什么这么转换?不太明确转换后有什么优点,写个文章来了解这些内容。 原始问题转换 min ⁡ 1 2 ∣ ∣ w ∣ ∣ 2 s . t . y i ( x i + b ) > = 1 i=1,2...,n \min \quad \frac{1}{2} ||w||^2 \\ s.t. \quad y_i(x_i+b) >=1 \qquad \text{i=1,2...,n} min 2 1 ​ ∣ ∣ w ∣ ∣ 2 s . t . y i ​ ( x i ​ + b ) > = 1 i=1,2...,n 拉格朗日乘子之后的公式为: F ( w , b , a ) = 1 2 ∣ ∣ w ∣ ∣ 2 + ∑ i = 1 n a i [ 1 − y i ( w x i + b ) ] s . t . a i > = 0 F(w,b,a)= \frac{1}{2} ||w||^2+\sum_{i=1}^{n}a_{i}[1-y_i(wx_i+b)] \\ s.t. \quad a_i>=0 F ( w , b , a ) = 2 1 ​ ∣ ∣ w ∣ ∣ 2 + i = 1 ∑ n ​ a i ​ [ 1 − y i ​ ( w x i ​ + b ) ] s . t

SVM Classifications on set of images of digits in Matlab

本小妞迷上赌 提交于 2020-01-16 08:25:28
问题 I have to use SVM classifier on digits dataset. The dataset consists of images of digits 28x28 and a toal of 2000 images. I tried to use svmtrain but the matlab gave an error that svmtrain has been removed. so now i am using fitcsvm. My code is as below: labelData = zeros(2000,1); for i=1:1000 labelData(i,1)=1; end for j=1001:2000 labelData(j,1)=1; end SVMStruct =fitcsvm(trainingData,labelData) %where training data is the set of images of digits. I need to know how i can predict the outputs

Index out of bounds: Fitting SSVM using Pystruct

故事扮演 提交于 2020-01-16 04:59:06
问题 I am trying to fit an SSVM as shown on the examples page: https://github.com/pystruct/pystruct/blob/master/examples/multi_class_svm.py The code runs fine with the given example, but not with my own data. The input dataset is a csv file with the following columns and rows for example: user_name facility start_date day_of_week monthweek month TestUserA FacilityA 2/1/2015 1 1 2 ... ... ... ... ... ... out of the above columns, the only predictors I use are 'facility' and day_of_week' and I

Implementation of SVM-RFE Algorithm in R

二次信任 提交于 2020-01-15 11:07:16
问题 I'm using the R code for the implementation of SVM-RFE Algorithm from this source http://www.uccor.edu.ar/paginas/seminarios/Software/SVM_RFE_R_implementation.pdf but I made a small modification so that the r code uses the gnum library. The code is the following: svmrfeFeatureRanking = function(x,y){ n = ncol(x) survivingFeaturesIndexes = seq(1:n) featureRankedList = vector(length=n) rankedFeatureIndex = n while(length(survivingFeaturesIndexes)>0){ #train the support vector machine svmModel =

SVC (support vector classification) with categorical (string) data as labels

烈酒焚心 提交于 2020-01-14 13:15:52
问题 I use scikit-learn to implement a simple supervised learning algorithm. In essence I follow the tutorial here (but with my own data). I try to fit the model: clf = svm.SVC(gamma=0.001, C=100.) clf.fit(features_training,labels_training) But at the second line, I get an error: ValueError: could not convert string to float: 'A' The error is expected because label_training contains string values which represent three different categories, such as A , B , C . So the question is: How do I use SVC

python sklearn non linear svm penalty

旧街凉风 提交于 2020-01-14 04:15:10
问题 I am using Python 2.7 with sklearn and using sklearn.svm.SVC with rbf kernel and suffer from over fitting. I tried using the C and Gamma as explained here and it did not do the trick If I understand correctly C and gamma are not l1 and l2 penalty, because C is the penalty for classifying wrong and gamma is the generalization parameter with respect to the data samples. i am looking for something that will penalize the model for complexity like l1 and l2. i want to use regularization and l1 or