how can I convert knnclassify to fitcknn
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
I have a script from a past graduate student that needs to be updated! i dont know matlab!

How do I swtich from knnclassify to fitcknn?
0 Commenti
Risposte (1)
  Raunak Gupta
    
 il 18 Feb 2020
        Hi, 
You can replace the bottommost line of the code that is  
class = knnclassify(TestingMatrix,SCORE,group,8,'euclidean','nearest'); 
With the following code 
Mdl = fitcknn(SCORE,group,'Distance','euclidean','NumNeighbors',8,'Standardize',1,'BreakTies','nearest'); 
class = predict(Mdl,TestingMatrix); 
For more information or insights for the functions you may look to the following documentations. 
7 Commenti
  Frisda Sianipar
 il 6 Mag 2021
				Ok sir, this is the complete error messege.
Warning: Variable names were modified to make them valid MATLAB identifiers. The original names are saved in
the VariableDescriptions property. 
Warning: Variable names were modified to make them valid MATLAB identifiers. The original names are saved in
the VariableDescriptions property. 
Error using classreg.learning.internal.table2FitMatrix (line 83)
A table used as a response must contain exactly one variable.
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 471)
            [X,Y,vrange,wastable,varargin] = classreg.learning.internal.table2FitMatrix(X,Y,varargin{:});
Error in ClassificationKNN.prepareData (line 878)
                prepareData@classreg.learning.classif.FullClassificationModel(X,Y,varargin{:},'OrdinalIsCategorical',true);
Error in classreg.learning.FitTemplate/fit (line 213)
                    this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationKNN.fit (line 863)
            this = fit(temp,X,Y);
Error in fitcknn (line 261)
    this = ClassificationKNN.fit(X,Y,RemainingArgs{:});
Error in KNNPleaseFix (line 11)
   Mdl = fitcknn(test,latih,'NumNeighbors',5,'Standardize',1);
  Walter Roberson
      
      
 il 6 Mag 2021
				x = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/600525/datatraining.xlsx");
y = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/600520/datatesting.xlsx");
traindata = x{:,2};
traingroup = x{:,3};
testdata = y{:,2};
testgroup = y{:,3};
Mdl = fitcknn(traindata, traingroup,'Distance','euclidean','NumNeighbors',8,'Standardize',1,'BreakTies','nearest');
hasil = predict(Mdl, testdata);
nama = "hasil KNN.xlsx";
y.hasil = hasil;
writetable(y, nama)
does_it_match = strcmp(hasil, testgroup);
correct_percent = mean(does_it_match) * 100
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
