资源简介
支持向量机libsvm-2.88(最新版),支持向量机学习的好帮手
代码片段和文件信息
#include
#include
#include
#include
#include “svm.h“
struct svm_node *x;
int max_nr_attr = 64;
struct svm_model* model;
int predict_probability=0;
void predict(FILE *input FILE *output)
{
int correct = 0;
int total = 0;
double error = 0;
double sumv = 0 sumy = 0 sumvv = 0 sumyy = 0 sumvy = 0;
int svm_type=svm_get_svm_type(model);
int nr_class=svm_get_nr_class(model);
double *prob_estimates=NULL;
int j;
if(predict_probability)
{
if (svm_type==NU_SVR || svm_type==EPSILON_SVR)
printf(“Prob. model for test data: target value = predicted value + z\nz: Laplace distribution e^(-|z|/sigma)/(2sigma)sigma=%g\n“svm_get_svr_probability(model));
else
{
int *labels=(int *) malloc(nr_class*sizeof(int));
svm_get_labels(modellabels);
prob_estimates = (double *) malloc(nr_class*sizeof(double));
fprintf(output“labels“);
for(j=0;j fprintf(output“ %d“labels[j]);
fprintf(output“\n“);
free(labels);
}
}
while(1)
{
int i = 0;
int c;
double targetv;
if (fscanf(input“%lf“&target)==EOF)
break;
while(1)
{
if(i>=max_nr_attr-1) // need one more for index = -1
{
max_nr_attr *= 2;
x = (struct svm_node *) realloc(xmax_nr_attr*sizeof(struct svm_node));
}
do {
c = getc(input);
if(c==‘\n‘ || c==EOF) goto out2;
} while(isspace(c));
ungetc(cinput);
if (fscanf(input“%d:%lf“&x[i].index&x[i].value) < 2)
{
fprintf(stderr“Wrong input format at line %d\n“ total+1);
exit(1);
}
++i;
}
out2:
x[i].index = -1;
if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC))
{
v = svm_predict_probability(modelxprob_estimates);
fprintf(output“%g“v);
for(j=0;j fprintf(output“ %g“prob_estimates[j]);
fprintf(output“\n“);
}
else
{
v = svm_predict(modelx);
fprintf(output“%g\n“v);
}
if(v == target)
++correct;
error += (v-target)*(v-target);
sumv += v;
sumy += target;
sumvv += v*v;
sumyy += target*target;
sumvy += v*target;
++total;
}
if (svm_type==NU_SVR || svm_type==EPSILON_SVR)
{
printf(“Mean squared error = %g (regression)\n“error/total);
printf(“Squared correlation coefficient = %g (regression)\n“
((total*sumvy-sumv*sumy)*(total*sumvy-sumv*sumy))/
((total*sumvv-sumv*sumv)*(total*sumyy-sumy*sumy))
);
}
else
printf(“Accuracy = %g%% (%d/%d) (classification)\n“
(double)correct/total*100correcttotal);
if(predict_probability)
free(prob_estimates);
}
void exit_with_help()
{
printf(
“Usage: svm-predict [options] test_file model_file output_file\n“
“options:\n“
“-b probability_estimates: whether to predict probability estimates 0 or 1 (default 0); for one-class SVM only 0 is supported\n“
);
exit(1);
}
int main(int argc char **argv)
{
FILE *input *output;
int i;
// parse options
for(i=1;i {
if(argv[i][0] != ‘-‘) break;
++i;
switch(argv
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 61804 2008-10-29 11:16 libsvm-2.88\svm.cpp
文件 2184 2008-10-15 11:38 libsvm-2.88\svm.h
文件 22334 2008-10-15 11:38 libsvm-2.88\README
文件 1304 2008-02-09 09:36 libsvm-2.88\Makefile.win
文件 7362 2008-10-12 07:25 libsvm-2.88\svm-train.c
文件 1497 2008-10-29 22:51 libsvm-2.88\COPYRIGHT
文件 4062 2008-10-15 11:38 libsvm-2.88\svm-predict.c
文件 60637 2008-10-30 07:43 libsvm-2.88\FAQ.html
文件 27670 2003-07-12 12:07 libsvm-2.88\heart_scale
文件 6700 2008-09-15 12:36 libsvm-2.88\svm-scale.c
文件 497 2008-09-15 12:36 libsvm-2.88\Makefile
文件 10787 2006-03-04 15:40 libsvm-2.88\svm-toy\windows\svm-toy.cpp
文件 9702 2006-03-04 15:40 libsvm-2.88\svm-toy\gtk\callbacks.cpp
文件 6457 2003-07-12 12:07 libsvm-2.88\svm-toy\gtk\interface.c
文件 1765 2003-07-12 12:07 libsvm-2.88\svm-toy\gtk\callbacks.h
文件 398 2003-07-12 12:07 libsvm-2.88\svm-toy\gtk\main.c
文件 203 2003-07-12 12:07 libsvm-2.88\svm-toy\gtk\interface.h
文件 6402 2003-07-12 12:07 libsvm-2.88\svm-toy\gtk\svm-toy.glade
文件 530 2007-10-14 14:29 libsvm-2.88\svm-toy\gtk\Makefile
文件 9133 2008-05-01 20:42 libsvm-2.88\svm-toy\qt\svm-toy.cpp
文件 366 2008-05-01 20:42 libsvm-2.88\svm-toy\qt\Makefile
文件 3034 2005-11-16 20:58 libsvm-2.88\tools\subset.py
文件 2525 2008-02-10 20:12 libsvm-2.88\tools\easy.py
文件 11701 2008-08-08 18:41 libsvm-2.88\tools\grid.py
文件 4642 2008-03-09 22:33 libsvm-2.88\tools\README
文件 2371 2007-11-15 15:57 libsvm-2.88\tools\checkdata.py
文件 147456 2008-10-29 22:44 libsvm-2.88\windows\svm-train.exe
文件 90112 2008-10-29 22:44 libsvm-2.88\windows\svm-scale.exe
文件 110592 2008-10-29 22:44 libsvm-2.88\windows\svm-predict.exe
文件 151552 2008-10-29 22:44 libsvm-2.88\windows\svm-toy.exe
............此处省略37个文件信息
- 上一篇:北京市shp文件
- 下一篇:人行为识别代码,需要的过来看看,多提宝贵意见。
评论
共有 条评论