How to correct the error - ClassificationSVM
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    vokoyo
 el 16 de Jun. de 2018
  
    
    
    
    
    Comentada: Walter Roberson
      
      
 el 25 de Abr. de 2023
            My Matlab code -
    clear
    load fisheriris
    % Only use the third and fourth features
    x=meas(:,3:4);
    gscatter(x(:,1),x(:,2),species);
    % Only use the last two categories
    x=meas(51:end,3:4);
    group=species(51:end,1);
    gscatter(x(:,1),x(:,2),group);
    % Linear SVM
    svmStruct = fitcsvm(x,group,'showplot',true);
    % Kernel SVM
    svmStruct = fitcsvm(xdata,group,'showplot',true,'kernel_function','rbf');
    % Select different sigma
    svmStruct = fitcsvm(xdata,group,'showplot',true,'kernel_function','rbf','rbf_sigma',0.5);
But here I get the error message such as below -
Error in fitcsvm (line 316)
    obj = ClassificationSVM.fit(X,Y,RemainingArgs{:});
Error in Untitled (line 11)
svmStruct = fitcsvm(x,group,'showplot',true);
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 16 de Jun. de 2018
        
      Editada: Walter Roberson
      
      
 el 16 de Jun. de 2018
  
      svmStruct = fitcsvm(x,group,'HyperparameterOptimizationOptions', struct('showplot',true))
svmStruct = fitcsvm(x,group,'HyperparameterOptimizationOptions', struct('showplot',true), 'KernelFunction','rbf','KernelScale',0.5)
1 comentario
  Walter Roberson
      
      
 el 17 de Jun. de 2018
				ntry = 10;
kftypes = {'gaussian', 'rbf', 'polynomial'};
nkf = length(kftypes);
svmStructs = cell(ntry,1);
for idx = 1 : ntry
  kfidx = randi(nkf);
  kftype = kftypes{kfidx};
  if ismember(kfidx, [1, 2])
    ks = exp(randn());
    opts = {'KernelScale', ks};
  else
    q = randi(20);
    opts = {'PolynomialOrder', q}
  end
  svmStructs{idx} = fitcsvm(x, group, 'HyperparameterOptimizationOptions', struct('showplot',true), 'KernelFunction', kftype, opts{:});
  disp(kftype)
  celldisp(opts);
  pause(2);
end
Más respuestas (5)
  vokoyo
 el 17 de Jun. de 2018
        
      Editada: vokoyo
 el 17 de Jun. de 2018
  
      1 comentario
  Walter Roberson
      
      
 el 17 de Jun. de 2018
				Try different settings for the KernelFunction https://www.mathworks.com/help/stats/fitcsvm.html#bt9w6j6_sep_shared-KernelFunction and for the KernelScale and see what the effects are.
  vokoyo
 el 18 de Jun. de 2018
        
      Editada: vokoyo
 el 18 de Jun. de 2018
  
      
      6 comentarios
  Walter Roberson
      
      
 el 18 de Jun. de 2018
				It sounds as if you are calling svm_3d_matlab_vis without passing in any parameters.
  Don Mathis
    
 el 18 de Jun. de 2018
        FITCSVM does not have an argument named 'showplot'. When I run your original code in R2018a I get this:
Error using classreg.learning.FitTemplate/fillIfNeeded (line 612)
showplot is not a valid parameter name.
Error in classreg.learning.FitTemplate.make (line 124)
            temp = fillIfNeeded(temp,type);
Error in ClassificationSVM.template (line 235)
            temp = classreg.learning.FitTemplate.make('SVM','type','classification',varargin{:});
Error in ClassificationSVM.fit (line 239)
            temp = ClassificationSVM.template(varargin{:});
Error in fitcsvm (line 316)
    obj = ClassificationSVM.fit(X,Y,RemainingArgs{:});
Error in Untitled3 (line 11)
    svmStruct = fitcsvm(x,group,'showplot',true);
  Don Mathis
    
 el 25 de Abr. de 2023
        
      Editada: Don Mathis
    
 el 25 de Abr. de 2023
  
      svmtrain() was replaced by fitcsvm(), and fitcsvm does not have a 'showplot' argument. Making a 2D plot of data points and support vectors in not built-in to fitcsvm, nor the object that it returns, ClassificationSVM.
If you have a 2D input space and you want to plot points and support vectors, you can see an example of how to do that here: https://www.mathworks.com/help/stats/classificationsvm.html#bt7go4d
0 comentarios
Ver también
Categorías
				Más información sobre Classification Ensembles en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





