svm

Find right features in multiclass svm without PCA

走远了吗. 提交于 2019-12-22 01:15:11
问题 I'm classifing users with a multiclass svm (one-against-on), 3 classes. In binary, I would be able to plot the distribution of the weight of each feature in the hyperplan equation for different training sets. In this case, I don't really need a PCA to see stability of the hyperplan and relative importance of the features (reudced centered btw). What would the alternative be in multiclass svm, as for each training set you have 3 classifiers and you choose one class according to the result of

labeling data in SVM opencv c++

半腔热情 提交于 2019-12-22 00:13:28
问题 I'm trying to implement SVM in opencv for features that I have extracted features by using SIFT. I have extracted features for 2 different objects (each object has features of 10 different images which in total I got more than 3000 features for one object) and I put those features in one file (yaml file).. My problem is: I don't know how to label them? so I need to label these two files (as I said each file is the type of yaml and it contains matrix 3260*128 and the second yaml file for the

Predicting with chi squared kernel for multilabel using sklearn

孤者浪人 提交于 2019-12-21 23:15:22
问题 I'm trying to get predictions for an SVM using a precomputed chi-squared kernel. However, I am getting issues when trying to run clf.predict(). min_max_scaler = preprocessing.MinMaxScaler() X_train_scaled = min_max_scaler.fit_transform(features_train) X_test_scaled = min_max_scaler.transform(features_test) K = chi2_kernel(X_train_scaled) svm = SVC(kernel='precomputed', cache_size=1000).fit(K, labels_train) y_pred_chi2 = svm.predict(X_test_scaled) The error I am getting is the following:

学习SVM,这篇文章就够了!(附详细代码)

ε祈祈猫儿з 提交于 2019-12-21 15:14:07
支持向量机 (SVM),一个神秘而众知的名字,在其出来就受到了莫大的追捧,号称最优秀的分类算法之一,以其简单的理论构造了复杂的算法,又以其简单的用法实现了复杂的问题,不得不说确实完美。 本系列旨在以基础化的过程,实例化的形式一探SVM的究竟。曾经也只用过集成化的SVM软件包,效果确实好。因为众人皆说原理复杂就对其原理却没怎么研究,最近经过一段时间的研究感觉其原理还是可以理解,这里希望以一个从懵懂到略微熟知的角度记录一下学习的过程。其实网络上讲SVM算法的多不胜数,博客中也有许多大师级博主的文章,写的也很简单明了,可是在看过之后,总是感觉差点什么,当然对于那些基础好的可能一看就懂了,然而对于像我们这些基础薄弱的,一遍下 来也 只能马马虎虎,过一两天后又忘了公式怎么来的了。 比如说在研究SVM之前,你是否听说过拉格朗日乘子法?你是否知道什么是对偶问题?你是否了解它们是怎么解决问题的?这些不知道的话,更别说什么是KKT条件了。话说像拉格朗日乘子法,在大学里面学数学的话,不应该没学过,但是你学会了吗?你知道是干什么的吗?如果那个时候就会了,那你潜质相当高了。作为一个过来人,我将以简单实例化形式记录自己的学习过程,力图帮助新手级学习者少走弯路。 1、 关于拉格朗日乘子法和KKT条件 1)关于拉格朗日乘子法 首先来了解拉格朗日乘子法,为什么需要拉格朗日乘子法呢?记住,有需要拉格朗日乘子法的地方

Negative decision_function values

跟風遠走 提交于 2019-12-21 06:15:21
问题 I am using support vector classifier from sklearn on the Iris dataset. When I call decision_function it returns negative values. But all samples in test dataset after classification has right class. I think that decision_function should return the positive value when the sample is an inlier and negative if the sample is an outlier. Where I am wrong? from sklearn import datasets from sklearn.svm import SVC from sklearn.model_selection import train_test_split iris = datasets.load_iris() X =

Bag of words training samples

天大地大妈咪最大 提交于 2019-12-21 05:42:24
问题 I have implemented Bag Of Words, everything is working smoothly. But, I'm confused about some steps and how to implement it. I could create the bow descriptors as the last step in Bag of words to create the samples, as it shown here bowDE.compute(img, keypoints, bow_descriptor); .. The things is that i'm confused about the next steps. I know that in BOW that I have to train and test a class (car) with non-class (cola), what I created in bow_descriptor vector is only for the class car, so I

Extract decision boundary with scikit-learn linear SVM

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 05:17:20
问题 I have a very simple 1D classification problem: a list of values [0, 0.5, 2] and their associated classes [0, 1, 2]. I would like to get the classification boundaries between those classes. Adapting the iris example (for visualization purposes), getting rid of the non-linear models: X = np.array([[x, 1] for x in [0, 0.5, 2]]) Y = np.array([1, 0, 2]) C = 1.0 # SVM regularization parameter svc = svm.SVC(kernel='linear', C=C).fit(X, Y) lin_svc = svm.LinearSVC(C=C).fit(X, Y) Gives the following

String Subsequence Kernel and SVM using Python

孤人 提交于 2019-12-21 05:17:16
问题 How can I use Subsequence String Kernel (SSK) [Lodhi 2002] to train a SVM (Support Vector Machine) in Python? 回答1: This is an update to gcedo's answer to work with the current version of shogun (Shogun 6.1.3). Working example: import numpy as np from shogun import StringCharFeatures, RAWBYTE from shogun import BinaryLabels from shogun import SubsequenceStringKernel from shogun import LibSVM strings = ['cat', 'doom', 'car', 'boom','caboom','cartoon','cart'] test = ['bat', 'soon', 'it is your

支持向量机(SVM)算法的matlab的实现

戏子无情 提交于 2019-12-21 03:55:31
支持向量机(SVM)的matlab的实现 支持向量机是一种分类算法之中的一个,matlab中也有对应的函数来对其进行求解;以下贴一个小例子。这个例子来源于我们实际的项目。 clc; clear; N=10; %以下的数据是我们实际项目中的训练例子(例子中有8个属性) correctData=[0,0.2,0.8,0,0,0,2,2]; errorData_ReversePharse=[1,0.8,0.2,1,0,0,2,2]; errorData_CountLoss=[0.2,0.4,0.6,0.2,0,0,1,1]; errorData_X=[0.5,0.5,0.5,1,1,0,0,0]; errorData_Lower=[0.2,0,1,0.2,0,0,0,0]; errorData_Local_X=[0.2,0.2,0.8,0.4,0.4,0,0,0]; errorData_Z=[0.53,0.55,0.45,1,0,1,0,0]; errorData_High=[0.8,1,0,0.8,0,0,0,0]; errorData_CountBefore=[0.4,0.2,0.8,0.4,0,0,2,2]; errorData_Local_X1=[0.3,0.3,0.7,0.4,0.2,0,1,0]; sampleData=[correctData;errorData

支持向量机(SVM)——python3实现

早过忘川 提交于 2019-12-21 03:55:20
  今天看完soft-margin SVM就又搜了下相关的代码,最后搜到 这个 ,第一次看懂了SVM的实现。   关于代码中cvxopt的使用,可以看下 这个 简单的介绍。   这里还是将代码贴在这里,里面加了自己的一下注释。 1 # -*- coding: utf-8 -*- 2 """ 3 Created on Tue Nov 22 11:24:22 2016 4 5 @author: Administrator 6 """ 7 8 # Mathieu Blondel, September 2010 9 # License: BSD 3 clause 10 11 import numpy as np 12 from numpy import linalg 13 import cvxopt 14 import cvxopt.solvers 15 16 def linear_kernel(x1, x2): 17 return np.dot(x1, x2) 18 19 def polynomial_kernel(x, y, p=3): 20 return (1 + np.dot(x, y)) ** p 21 22 def gaussian_kernel(x, y, sigma=5.0): 23 return np.exp(-linalg.norm(x-y)**2 / (2 *