Comments (1)
Please see the following faq by using the matlab interface.
Alternatively you can consider liblinear, which directly gives you w.
Q: How could I generate the primal variable w of linear SVM?
Let's start from the binary class and assume you have two labels -1 and
+1. After obtaining the model from calling svmtrain, do the following to
have w and b:
w = model.SVs' * model.sv_coef;
b = -model.rho;
if model.Label(1) == -1
w = -w;
b = -b;
end
If you do regression or one-class SVM, then the if statement is not
needed.
For multi-class SVM, we illustrate the setting in the following example
of running the iris data, which have 3 classes
[y, x] = libsvmread('../../htdocs/libsvmtools/datasets/multiclass/iris.scale');
m = svmtrain(y, x, '-t 0')
m =
Parameters: [5x1 double]
nr_class: 3
totalSV: 42
rho: [3x1 double]
Label: [3x1 double]
ProbA: []
ProbB: []
nSV: [3x1 double]
sv_coef: [42x2 double]
SVs: [42x4 double]
sv_coef is like:
+-+-+--------------------+
|1|1| |
|v|v| SVs from class 1 |
|2|3| |
+-+-+--------------------+
|1|2| |
|v|v| SVs from class 2 |
|2|3| |
+-+-+--------------------+
|1|2| |
|v|v| SVs from class 3 |
|3|3| |
+-+-+--------------------+
so we need to see nSV of each classes.
m.nSV
ans =
3
21
18
Suppose the goal is to find the vector w of classes 1 vs 3. Then y_i
alpha_i of training 1 vs 3 are
coef = [m.sv_coef(1:3,2); m.sv_coef(25:42,1)];
and SVs are:
SVs = [m.SVs(1:3,:); m.SVs(25:42,:)];
Hence, w is
w = SVs'*coef;
For rho,
m.rho
ans =
1.1465
0.3682
-1.9969
b = -m.rho(2);
because rho is arranged by 1vs2 1vs3 2vs3.
from libsvm.
Related Issues (20)
- How to use the saved trained svm model file manually HOT 1
- how can i improve train speed? HOT 1
- why my memory always HOT 1
- Some dataset problem HOT 2
- static library HOT 1
- gridregression.py
- LIBSVM library not found HOT 1
- gridregression.py 出现 RuntimeError: get no mse HOT 2
- Exception Thrown: read access violation HOT 1
- 使用svm-train.exe做回归(regression),参数c与g如何优化 HOT 1
- How to modify SVR loss function? HOT 1
- Accuracies lower than 50% if the random seed is unlucky HOT 8
- one class svm HOT 1
- Questions about the results of libSVM HOT 6
- Questions about probability estimation of one-class svm HOT 4
- 如何调整nu,使训练集的准确率增加? HOT 6
- cannot find -lgcc: No such file or directory HOT 1
- When using svm-scale , missing values come out. HOT 1
- Try using a custom objective function
- MATLAB Crashes when trying to run "svmtrain" on CentOS HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsvm.