How do PCA of toolbox ML data
2 次查看(过去 30 天)
显示 更早的评论
Hello, I have doubts about my code, because the confusion matrix gives me [0 58; 0 60]. but I don't know the values are correct or if the way to reduce dimensions and project the data is correct. The matrix is 118x3300 data, all in temperature. If anyone can guide me with this code or recommend me. I would appreciate it.
obs: the problem is dimension reductions of linear SVM data classification and projecting data
clc; clearvars; close all;
load patMean.mat
data = cat(1,patBen,patMal );
out = [ones(60,1); ones(58,1).*(-1)];
rng(0);
[predictions,accuracy] = trainClassifier(data,out') % export data of toolbox
% iscorrect = out == predictions;
% acc = sum(iscorrect)*100 / length(out)
Al exportar el mejor clasificador deterministico se obtiene la misma precisión que se indicaba en el Toolbox.
Reduccion de dimensiones:
a) PCA:
Se hallan los coeficientes
wt = 1./var(data);
mu = mean(data);
standa = std(data);
[coeff,score, ~ , ~, explained] = pca(data);
[data, mu, sigma] = zscore(data);
sigma(sigma==0) = 1;
idx = find(cumsum(explained) > 99);
numVectors = idx(1); % numero de componentes segun el porcentaje de varianza
pVector = (coeff(:,1:numVectors));
xHa = zeros(size(data));
for i = 1:118
x1 = data(i,:); % Cada paciente se guarda en x1 y sus 3300 variables temperatura
x1 = x1(:); % Todos los pacientes se guardan
b = x1' * pVector; %Los coeficientes se multiplican por los pacientes 3300 coeficientes del primer por los valores del paciente 1
xH = pVector * b'; % Coeficiente por vector de valores a proyectar
xHa(i,:) = xH';
end
rp = zeros(118,1);
for i = 1:118
rp(i) = predictions.predictFcn(xHa(i,:));
end
%Metricas
% Calcula la matriz de confusión
matriz_confusion = confusionmat(out, rp)
sensibilidad = matriz_confusion(2, 2) / sum(matriz_confusion(2, :))
especificidad = matriz_confusion(1, 1) / sum(matriz_confusion(1, :))
% Calcula la precisión
precision = sum(diag(matriz_confusion)) / sum(matriz_confusion(:))
Questions :
- How do use predict, it's correct or something is missing before?
3 个评论
Walter Roberson
2023-11-28
In that case, we have to assume that:
- the confusion matrix values are not correct;
- the way to reduce dimensions and project the data is not correct.
- the data is not correct.
...because we cannot take responsibility for declaring that code is correct when the health of actual patients is on the line.
I recommend that you create some artificial data that you know the results for, or load a public dataset.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!