how to using fitcknn instead of knnclassify?
조회 수: 3 (최근 30일)
이전 댓글 표시
can someone help me to solve this
댓글 수: 0
답변 (1개)
Ganesh
2024년 6월 14일
To use the "fitcknn" in place of "knnclassify" you would have to follow the same procudure as using "knnclassify()", except, you are now training a "model" instead of directly predicting the results. The added advantage to this is that, your model can now be used to predict on unknown data sets too. As a final step after training the model, you have to use the "predict()" function to predict the values on your test dataset. The following code has been modified to accomodate "fitcknn" in place of "knnclassify".
data{1,3} = num2str(RangeR); data{2,3} = num2str(RangeG); data{3,3} = num2str(RangeB); data{4,3} = num2str(RangeH); data{5,3} = num2str(RangeS); data{6,3} = num2str(RangeI);
set(handles.uitable2, 'Data', data, 'ForegroundColor', [0 0 0]);
training1 = xlsread('Data Training');
group = training1(:, 25);
training = training1(:, 1:9);
Z = [MeanR MeanG MeanB MeanH MeanS MeanI VarRed VarGreen VarBlue VarH VarS VarI RangeR RangeG RangeB RangeH RangeS RangeI];
Mdl = fitcknn(training, group, 'NumNeighbors', 3); % example using 3 neighbors, adjust as needed
hasil1 = predict(Mdl, Z);
if hasil1 == 1
x = 'MATURE';
elseif hasil1 == 2
x = 'HALF-MATURE';
elseif hasil1 == 3
x = 'IMMATURE';
end
set(handles.edit2, 'string', x);
You may refer to the documentation below for more information on the mentioned functions:
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!