- https://www.mathworks.com/matlabcentral/fileexchange/13358-fuzzy-k-nn
- https://www.mathworks.com/matlabcentral/fileexchange/21326-fuzzy-k-nn
How calculate the class membership of each training sample using Fuzzy-kNN
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
merlin toche
am 11 Mär. 2023
Beantwortet: colordepth
am 20 Sep. 2024
I want to use the FKNN to classify my data, but I can't calculate the class of membership of each training sample. I tried to write a small code, but it does not work, I want to know why that. attached my code, input data
0 Kommentare
Akzeptierte Antwort
colordepth
am 20 Sep. 2024
Hi Merlin,
As per my understanding, you are implementing the Fuzzy K-Nearest Neighbours (FKNN) algorithm to classify your data. There seems to be an issue with calculating the class membership of each test sample, particularly in handling distance calculations and membership degree computations.
In the provided code, the use of “cumsum” for membership calculations do not align with FKNN requirements. Here is a concise snippet that demonstrates how to compute the fuzzy membership for each class:
num_classes = 5;
y_est = zeros(size(x_test, 1), num_classes);
% Calculate fuzzy membership
for i = 1:size(x_test, 1)
membership = zeros(1, num_classes);
for j = 1:k
class_label = y_train(idx(i, j));
weight = 1 / (dists(i, j) .^ (2 / (m - 1)));
membership(class_label + 1) = membership(class_label + 1) + weight;
end
y_est(i, :) = membership / sum(membership);
end
For additional insights and examples on implementing FKNN, you can refer to these resources:
Hope this helps!
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fuzzy Logic Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!