C# version of LibSVM toolbox

C# version of LibSVM toolbox

I downloaded the C# version of the support vector machine on the libsvm official website to train and test the existing data. The website is as follows: LibSVM official website .
Insert picture description here
The source code after opening is as follows, the training set and test set are both wine.txt data files.

Insert picture description here
We put our training data and test data in the Dataset folder, and then modify the program's read file wine.txt to libsvmtrain_sample.txt and libsvmtest_sample.txt respectively, and then add the existing data under the Dataset as shown in the figure below. Item, the Dataset contains libsvmtrain_sample.txt and libsvmtest_sample.txt.

Insert picture description here
Insert picture description here
After running the program, the following error occurred. After checking, it was
found that there are no libsvmtrain_sample.txt and libsvmtest_sample.txt under the path LibSVMsharpmaster\LibSVMsharp.Examples.Classification\bin\Debug\Dataset, which means that the program did not read training data and test data;
open libsvmtrain_sample .txt and libsvmtest_sample.txt, and compared with wine.txt, found that the format of the data stored in the file is inconsistent. Using wine.txt data, the results of running the program are normal. So you need to modify the data storage format in the above two files.

Insert picture description here
Use Notepad++ to open libsvmtrain_sample.txt and libsvmtest_sample.txt, make the following changes to the data format of the file, remove the spaces in the first column (long spaces will appear afterwards), and replace the first and second columns with a space .

Insert picture description here
The data storage format has been adjusted.

Insert picture description here
The program reads the training data libsvmtrain_sample.txt and the test data libsvmtest_sample.txt will be stored in the following path:
LibSVMsharp-master
\LibSVMsharp.Examples.Classification
\bin\Debug\Dataset
But the following settings must be made in the program: the file to be read is always Copy to the output directory.

Insert picture description here
At this time, the file read by the program appears under the path, and when the file read error, the file does not exist in this directory.

Insert picture description here
Next, run the program, and the results are as follows: the accuracy of the trained model to classify the test data is 87.5%.
Insert picture description here
Thank you, Teacher Yin, for helping me solve the problem of data format errors.

Guess you like

Origin blog.csdn.net/weixin_45317919/article/details/108598246