如何在Visual StudioVS里使用libsvm工具箱 与博文相关的代码包
博文以图文并茂的方式 细致讲解了如何在Visual Studio(VS2012 & VS2010 使用 libsvm (libsvm 3 18)工具箱的过程 目前互联网搜索数据libsvm工具箱在 VS 中以C++工程呈现的讲解非常稀少而且对初学者有一定的难度 所以在笔者完成工作后写了这篇小记或称为简单教程 呈现给大家
此文件是与教程配套的 cpp 文件
参考博文请移步:http: blog csdn net u014691453 article details 40393137">博文以图文并茂的方式 细致讲解了如何在Visual Studio(VS2012 & VS2010 使用 libsvm (libsvm 3 18)工具箱的过程 目前互联网搜索数据libsvm工具箱在 VS 中以C++工程呈现的讲解非常稀少而且对初学者有一定的难度 所以在笔者完成工 [更多]
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 103695 2014-10-23 15:28 1.txt
文件 12960 2014-10-22 15:33 11.txt
文件 1 2014-10-22 15:33 11_label.txt
文件 22 2014-10-22 20:04 1_label.txt
文件 9454 2014-10-23 10:29 LibSVMtest.cpp
文件 28436 2014-04-01 06:57 README
文件 45280707 2014-10-23 15:26 modle.txt
文件 5536 2014-04-01 06:57 svm-predict.c
文件 8504 2014-04-01 06:57 svm-scale.c
文件 8978 2014-04-01 06:57 svm-train.c
文件 64702 2014-04-01 06:57 svm.cpp
文件 477 2014-04-01 06:57 svm.def
文件 3382 2014-04-01 06:57 svm.h
#include
#include
#include
#include
#include
#include
#include “svm.h“
using namespace std;
#define XLEN 10 //生产测试数据
#define YLEN 10
ofstream outdata;
ifstream indata;
ofstream outdata_lable;
ifstream indata_lable;
int NUM = 1440;
//char default_param[] = “-t 2 -c 100“;
char default_param[] = “-t 2 -c 4 -g 32“;
struct point {
double *feature;
//signed char value;
int value;
};
list point_list;
int current_value = 1;
void clear_all()
{
point_list.clear();
}
void readFile2(char *filechar *file_lable)
{
indata.open(fileios::in);
indata_lable.open(file_lableios::in);
cout <<“read test data begin“< clear_all();
while(!indata.eof())
{
double *line = new double[NUM];
for(int i =0;i {
indata >> line[i];
}
point p;
indata_lable >>p.value;
p.feature = line;
point_list.push_back(p);
}
point_list.pop_back();
cout <<“read test data end size = “< indata.close();
indata_lable.close();
}
void testData()
{
cout <<“ test data begin“<
svm_model *model = svm_load_model(“modle.txt“);
svm_node *x_space = new svm_node[NUM+1];
double d;
int i;
int k =0;
for (list::iterator q = point_list.begin(); q != point_list.end(); q++)
{
for(i =0 ;i {
x_space[i].index = i+1;
x_space[i].value = q->feature[i];
}
x_space[NUM].index = -1;
d = svm_predict(model x_space);
if(d == q->value)
cout <<“right = “< else
{
cout<<“error“<<“ “< k++;
}
}
cout << “error times = “< cout <<“read test data end“< delete [] x_space;
}
//1440
void readFile1(char *filechar *file_lable)
{
indata.open(fileios::in);
indata_lable.open(file_lableios::in);
cout <<“read data begin“<
clear_all();
while(!indata.eof())
{
double *line = new double[NUM];
for(int i =0;i {
indata >> line[i];
}
point p;
indata_lable >>p.value;
p.feature = line;
point_list.push_back(p);
}
point_list.pop_back();
indata.close();
indata_lable.close();
cout <<“read data end“< }
/*void readFile( char * file)
{
//char filename[1024];
FILE *fp = fopen(file“r“);
if(fp)
{
clear_all();
char buf[4096];
while(fgets(bufsizeof(buf)fp))
{
int v;
double xy;
if(sscanf(buf“%d%*d:%lf%*d:%lf“&v&x&y)==3)
{
point p = {xyv};
point_list.push_back(p);
}
else if(sscanf(buf“%lf%*d:%lf“&y&x)==2)
{
point p = {xycurrent_value};
point_list.push_back(p);
}
else
break;
}
fclose(fp);
}
else
{
printf(“can‘t find file“);
}
}*/
void run()
{
if(point_list.empty()) return;
svm_parameter param;
int ij;
// default values
param.svm_type = C_SVC;
param.kernel_type = RBF;
param.deg
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 103695 2014-10-23 15:28 1.txt
文件 12960 2014-10-22 15:33 11.txt
文件 1 2014-10-22 15:33 11_label.txt
文件 22 2014-10-22 20:04 1_label.txt
文件 9454 2014-10-23 10:29 LibSVMtest.cpp
文件 28436 2014-04-01 06:57 README
文件 45280707 2014-10-23 15:26 modle.txt
文件 5536 2014-04-01 06:57 svm-predict.c
文件 8504 2014-04-01 06:57 svm-scale.c
文件 8978 2014-04-01 06:57 svm-train.c
文件 64702 2014-04-01 06:57 svm.cpp
文件 477 2014-04-01 06:57 svm.def
文件 3382 2014-04-01 06:57 svm.h
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)