资源简介
整个libsvm3.1里面有好多个的,有matlab,python等,然后你在你自己的matlab里安装,网上有教程的,matlab那个文件夹里是有.c文件的,需要在matlab里编译过才能生成matlab可用的函数
代码片段和文件信息
#include
#include
#include
#include
#include
#include “svm.h“
struct svm_node *x;
int max_nr_attr = 64;
struct svm_model* model;
int predict_probability=0;
static char *line = NULL;
static int max_line_len;
static char* readline(FILE *input)
{
int len;
if(fgets(linemax_line_leninput) == NULL)
return NULL;
while(strrchr(line‘\n‘) == NULL)
{
max_line_len *= 2;
line = (char *) realloc(linemax_line_len);
len = (int) strlen(line);
if(fgets(line+lenmax_line_len-leninput) == NULL)
break;
}
return line;
}
void exit_input_error(int line_num)
{
fprintf(stderr“Wrong input format at line %d\n“ line_num);
exit(1);
}
void predict(FILE *input FILE *output)
{
int correct = 0;
int total = 0;
double error = 0;
double sump = 0 sumt = 0 sumpp = 0 sumtt = 0 sumpt = 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);
}
}
max_line_len = 1024;
line = (char *)malloc(max_line_len*sizeof(char));
while(readline(input) != NULL)
{
int i = 0;
double target_label predict_label;
char *idx *val *label *endptr;
int inst_max_index = -1; // strtol gives 0 if wrong format and precomputed kernel has start from 0
label = strtok(line“ \t\n“);
if(label == NULL) // empty line
exit_input_error(total+1);
target_label = strtod(label&endptr);
if(endptr == label || *endptr != ‘\0‘)
exit_input_error(total+1);
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));
}
idx = strtok(NULL“:“);
val = strtok(NULL“ \t“);
if(val == NULL)
break;
errno = 0;
x[i].index = (int) strtol(idx&endptr10);
if(endptr == idx || errno != 0 || *endptr != ‘\0‘ || x[i].index <= inst_max_index)
exit_input_error(total+1);
else
inst_max_index = x[i].index;
errno = 0;
x[i].value = strtod(val&endptr);
if(endptr == val || errno != 0 || (*endptr != ‘\0‘ && !isspace(*endptr)))
exit_input_error(total+1);
++i;
}
x[i].index = -1;
if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC))
{
predict_label = svm_predict_probability(modelxprob_estimates);
fprintf(output“%g“predict_label);
for(j=0;j fprintf(output“ %g“prob_estimates[j]);
fprintf(output“\n“);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 368483 2011-05-24 11:57 ACE-Unsupervised Offline segmentation of a time serie‘s dynamic.pdf
文件 67 2011-05-24 11:15 LIBSVM -- A Library for Support Vector Machines.URL
目录 0 2011-03-26 03:25 libsvm-3.1\
文件 1497 2011-03-26 03:25 libsvm-3.1\COPYRIGHT
文件 68901 2011-03-26 03:25 libsvm-3.1\FAQ.html
文件 27670 2003-07-12 04:07 libsvm-3.1\heart_scale
目录 0 2011-03-26 03:26 libsvm-3.1\java\
目录 0 2011-03-26 03:26 libsvm-3.1\java\libsvm\
文件 49854 2011-03-26 03:26 libsvm-3.1\java\libsvm.jar
文件 61931 2011-03-26 03:26 libsvm-3.1\java\libsvm\svm.java
文件 61280 2010-11-05 13:08 libsvm-3.1\java\libsvm\svm.m4
文件 734 2010-09-12 12:11 libsvm-3.1\java\libsvm\svm_model.java
文件 115 2003-10-11 12:30 libsvm-3.1\java\libsvm\svm_node.java
文件 1288 2006-03-03 15:44 libsvm-3.1\java\libsvm\svm_parameter.java
文件 87 2009-02-18 03:20 libsvm-3.1\java\libsvm\svm_print_interface.java
文件 136 2003-10-11 12:30 libsvm-3.1\java\libsvm\svm_problem.java
文件 624 2009-02-18 00:41 libsvm-3.1\java\Makefile
文件 4267 2009-03-17 20:20 libsvm-3.1\java\svm_predict.java
文件 8944 2009-02-19 22:06 libsvm-3.1\java\svm_scale.java
文件 11483 2010-12-13 09:43 libsvm-3.1\java\svm_toy.java
文件 8268 2010-01-27 09:40 libsvm-3.1\java\svm_train.java
文件 81 2003-07-12 04:07 libsvm-3.1\java\test_ap
文件 528 2010-09-12 12:11 libsvm-3.1\Makefile
文件 1087 2010-09-12 12:11 libsvm-3.1\Makefile.win
目录 0 2011-03-16 03:10 libsvm-3.1\matlab\
文件 3988 2011-02-23 23:00 libsvm-3.1\matlab\libsvmread.c
文件 2123 2011-02-23 23:00 libsvm-3.1\matlab\libsvmwrite.c
文件 396 2011-02-23 23:00 libsvm-3.1\matlab\make.m
文件 1481 2011-02-23 23:00 libsvm-3.1\matlab\Makefile
文件 9289 2011-03-16 11:10 libsvm-3.1\matlab\README.txt
文件 9063 2011-03-08 13:25 libsvm-3.1\matlab\svmpredict.c
............此处省略49个文件信息
- 上一篇:python实现VRPTW求解禁忌搜索算法
- 下一篇:Python 抓取网页链接
评论
共有 条评论