K-fold CV + SVM

4 Ansichten (letzte 30 Tage)
ahmed nebli
ahmed nebli am 9 Aug. 2018
i have this matlab codeand i want to perform k-fold cross validation + svm but i had an eror in line 30
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in kfold_test (line 30) predicted_labels(i) = predict_label;
rng(1); %for reproducibility, anchoring randomization
load('dataa2.mat')
dataFeatures = dataa2.view1;
c = cvpartition(size(dataa2.label_gender,1),'KFold',15); %leaveout twali k fold
decision_score = zeros(size(dataa2.label_gender,1),1); %vector of decision values (indep.of treshold) test_labels_vector = zeros(size(dataa2.label_gender,1),1); % store ground truth in test order accuracy = zeros(size(dataa2.label_gender,1),1); %store accuracy from each test predicted_labels = zeros(size(dataa2.label_gender,1),1); %vector to collect test results (labels assigned by SVM)
for i = 1:46 % run SVM 84 times
trainIndex = c.training(i);
testIndex = c.test(i);
train_labels = dataa2.label_gender(trainIndex);
train_data = dataFeatures(trainIndex,:);
test_labels = dataa2.label_gender(testIndex);
test_data = dataFeatures(testIndex,:);
% the classifier
model = svmtrain(train_labels,train_data,'-t 0'); % training the classifier using the trainign data
[predict_label, accuracy, decision_values] = svmpredict(test_labels,test_data,model); % testing the classfier on the left out data (hidden/test data)
predicted_labels(i) = predict_label;
test_labels_vector(i) = test_labels;
end
CM = confusionmat(test_labels_vector,predicted_labels); %returns the confusion matrix CM determined by the known and predicted groups in group and grouphat, respectively % C(i,j) is a count of observations known to be in group i but predicted to be in group j.
True_Negative = CM(1,1); True_Positive = CM(2,2); False_Negative = CM(2,1); False_Positive = CM(1,2); Accuracy_CM = (True_Positive + True_Negative)/(size(dataa2.label_gender,1)) * 100; Sensitivity = (True_Positive)/(True_Positive + False_Negative) * 100; Specificity = (True_Negative)/(True_Negative + False_Positive) * 100; figure=bar(Accuracy_CM,Sensitivity,Specificity);

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by