Specifity, sensibility and confusion matrix of a k-fold

2 visualizaciones (últimos 30 días)
Meriem Serdi
Meriem Serdi el 24 de Mayo de 2020
I'd like to calculate the sensitivity and specificity of my model and display the confusion matrix and i really don't know how because I used a k-fold of 5. Can anyone help me pleaaaase ? here is my code ?
clear variables;
close all;
clc;
%%
%preparing dataset
echantillon=readtable('melanome_naevus.xlsx');
classe=table2cell(echantillon(:,1));
y=grp2idx(classe);
X=table2array(echantillon(:,2:end));
%%
%divide database into test and train
rand_num = randperm(size(X,1));
X_train = X(rand_num(1:round(0.8*length(rand_num))),:);
y_train = y(rand_num(1:round(0.8*length(rand_num))),:);
X_test = X(rand_num(round(0.8*length(rand_num))+1:end),:);
y_test = y(rand_num(round(0.8*length(rand_num))+1:end),:);
%% CV partition
c = cvpartition(y_train,'kFold',5);
%% feature selection
opts = statset('display','iter');
classf = @(train_data, train_labels, test_data, test_labels)...
sum(predict(fitcsvm(train_data, train_labels,'KernelFunction','Polynomial'),...
test_data) ~= test_labels);
[fs, history] = sequentialfs(classf, X_train, y_train, 'cv', c, 'options', opts);
%% Best hyperparameter
X_train_w_best_feature = X_train(:,fs);
Md1 = fitcsvm(X_train_w_best_feature,y_train,'KernelFunction','Polynomial',...
'OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',...
struct('AcquisitionFunctionName','expected-improvement-plus','ShowPlots',true));
%% Final test with test set
X_test_w_best_feature = X_test(:,fs);
test_accuracy_for_iter = sum((predict(Md1,X_test_w_best_feature) == y_test))/length(y_test)*100

Respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by