Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

matlab - How to do regression using svmtrain() function in libsvm (what settings)? what is the label matrix form?

Libsvm is a small library for support vector machines written in C. here is the link to the source of libsvm I've used ( https://github.com/cjlin1/libsvm ). Can someone correct the options in the svmtrain() function or label matrix in the following code to perform regression successfully, since the output says optimization finished with #0 iteration.

The goal of the code before svmtrain() function is to arrange water pixels of an underwater color image (some rect in image) into an (m x 3) matrix as data. The label matrix is an ( m x 1 ) vector preset to 1;{ here is the link to the underwater image, equation of red channel compensation }

the output:

optimization finished, #iter = 0
nu = 0.000000
obj = 0.000000, rho = -1.000000
nSV = 0, nBSV = 0

here is the code:

    ##to load image package
    pkg load image
    ## add the path to the matlab folder inside the LIBSVM package source
    addpath('./libsvm-master/libsvm-master/matlab')
    ##load libsvm 
    pkg load statistics
    ##load an under water rgb image
    im = imread('9554.png');
    im=double(im);
    startrow=1;
    startcol=1;
    endrow=100;
    endcol=100;
    ## save rgb pixels in m x 3 form
    data=zeros(endrow*endcol,3,'double');
    for i=startrow:endrow
      for j=startcol:endcol
        data((i-1)*endrow+j,1:3)=im(i,j,1:3);
      end
    end
    ## m x 1 label matrix, all preset to 1
    label_data=ones(size(data,1),1,'double');
    model=svmtrain(label_data,data,'-s 3 -c 1');
question from:https://stackoverflow.com/questions/65868286/how-to-do-regression-using-svmtrain-function-in-libsvm-what-settings-what-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thank you for providing the image and extra details.

I think the problem is simply that you're passing a 'labels' matrix which consists only of a single label. The algorithm detects that there is no data to train with, and stops.

If you make some of the labels into zeros, then the algorithm runs as expected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...