从 libsvm 模型文件中提取 coefficients/weights
Extract coefficients/weights from libsvm model file
我正在使用 libsvm 创建 2-类 分类器。
我希望提取 ./svm-train training.training model.model
生成的模型使用的每个特征的 coefficient/weight
model.model
文件如下所示:
svm_type c_svc
kernel_type rbf
gamma 8
nr_class 2
total_sv 442
rho 21
label 1 -1
nr_sv 188 254
SV
7080.357768871263 0:0 1:0.00643 2:0.01046 3:0.00963 4:0.02777 5:0.04338 19:0.04468
528.7111702760092 0:0 1:0.00058 3:0.00086 6:0.01158 7:0.0028 9:0.08991 13:0.0096
...
391.7649705739246 0:0 1:0.00055 3:0.00082 5:0.04615 7:0.06374 21:0.00374 31:0.00339 33:0.00395 38:0.16343
...
-564.1329424321915 0:0 1:0.00709 2:0.00384 3:0.00709 5:0.00399 9:0.01457 10:0.01244 11:0.0206 17:0.02124 20:0.00565 23:0.00846 27:0.04692 33:0.04271 35:0.02389 36:0.00859 39:0.02014
我如何知道 svm-predict [options] test.test model.model out.out
将使用哪个 coefficients/weights?最后一行的那些?
谢谢,
M.
根据官方FAQ entry,LIBSVM
生成的模型文件包含以下信息:
In the model file, after parameters and other informations such as
labels , each line represents a support vector.
Support vectors are listed in the order of "labels" shown earlier. (i.e., those from the
first class in the "labels" list are grouped first, and so on.) If k
is the total number of classes, in front of a support vector in class
j, there are k-1 coefficients y*alpha where alpha are dual solution of
the following two class problems: 1 vs j, 2 vs j, ..., j-1 vs j, j vs
j+1, j vs j+2, ..., j vs k and y=1 in first j-1 coefficients, y=-1 in
the remaining k-j coefficients. For example, if there are 4 classes,
the file looks like:
+-+-+-+--------------------+
|1|1|1| |
|v|v|v| SVs from class 1 |
|2|3|4| |
+-+-+-+--------------------+
|1|2|2| |
|v|v|v| SVs from class 2 |
|2|3|4| |
+-+-+-+--------------------+
|1|2|3| |
|v|v|v| SVs from class 3 |
|3|3|4| |
+-+-+-+--------------------+
|1|2|3| |
|v|v|v| SVs from class 4 |
|4|4|4| |
+-+-+-+--------------------+
还有一个 example 说明如何读取此数据以便为二元分类器计算 w
。
我正在使用 libsvm 创建 2-类 分类器。
我希望提取 ./svm-train training.training model.model
model.model
文件如下所示:
svm_type c_svc
kernel_type rbf
gamma 8
nr_class 2
total_sv 442
rho 21
label 1 -1
nr_sv 188 254
SV
7080.357768871263 0:0 1:0.00643 2:0.01046 3:0.00963 4:0.02777 5:0.04338 19:0.04468
528.7111702760092 0:0 1:0.00058 3:0.00086 6:0.01158 7:0.0028 9:0.08991 13:0.0096
...
391.7649705739246 0:0 1:0.00055 3:0.00082 5:0.04615 7:0.06374 21:0.00374 31:0.00339 33:0.00395 38:0.16343
...
-564.1329424321915 0:0 1:0.00709 2:0.00384 3:0.00709 5:0.00399 9:0.01457 10:0.01244 11:0.0206 17:0.02124 20:0.00565 23:0.00846 27:0.04692 33:0.04271 35:0.02389 36:0.00859 39:0.02014
我如何知道 svm-predict [options] test.test model.model out.out
将使用哪个 coefficients/weights?最后一行的那些?
谢谢, M.
根据官方FAQ entry,LIBSVM
生成的模型文件包含以下信息:
In the model file, after parameters and other informations such as labels , each line represents a support vector. Support vectors are listed in the order of "labels" shown earlier. (i.e., those from the first class in the "labels" list are grouped first, and so on.) If k is the total number of classes, in front of a support vector in class j, there are k-1 coefficients y*alpha where alpha are dual solution of the following two class problems: 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k and y=1 in first j-1 coefficients, y=-1 in the remaining k-j coefficients. For example, if there are 4 classes, the file looks like:
+-+-+-+--------------------+ |1|1|1| | |v|v|v| SVs from class 1 | |2|3|4| | +-+-+-+--------------------+ |1|2|2| | |v|v|v| SVs from class 2 | |2|3|4| | +-+-+-+--------------------+ |1|2|3| | |v|v|v| SVs from class 3 | |3|3|4| | +-+-+-+--------------------+ |1|2|3| | |v|v|v| SVs from class 4 | |4|4|4| | +-+-+-+--------------------+
还有一个 example 说明如何读取此数据以便为二元分类器计算 w
。