简体   繁体   中英

train data using libsvm with best C and Gamma

Hi I'm using libsvm (in VS2010) for training my data , I scaled the input and output data successfully using svm-scale.c and my data is ready to be trained ...

Now I have two problems:

1).

as I've read from LIBSVM documentation I realized that first I need to train my scaled data and obtain a model. then use this model for predicting the final result but the problem is when I want to train my system I don't know what is the best choose for my model parameters and specifically (C,g) for training my data !!!. what I do is that first I load my scaled data, then by using a svm_problem I fill svm_nodes with my train data then call this function :

struct svm_model *svm_train(const struct svm_problem *prob, const struct svm_parameter *param );

2). Also I'm not sure about the correct function calling of libsvm functions -> I mean I first use svm_train and then svm_predict to see the result , and I don't know if I should call sth else or not ?!

Model = svm_train(My_data,My_param); //I don't know how to fill my_param

svm_node Test_Vector = svm_scale_data(x); //using the same algorithm as scaled_training data

double result = svm_predict(Model,Test_Vector);

Thanks

If you want to call LIBSVM via C++, you can optimize parameters by letting LIBSVM do cross-validation internally. When doing so, you just need to loop over the parameter tuples (C, gamma) you want to test and let LIBSVM perform cross-validation instead of proper training.

You can get LIBSVM to perform cross-validation with the following API function:

void svm_cross_validation(const struct svm_problem *prob, const struct svm_parameter *param, int nr_fold, double *target);

To answer your other question: yes, it is perfectly fine to call svm_train() followed by svm_predict() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM