How to Split fisher iris data into 60% training and 40% Testing
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello I hope you are doing well.
I want to split the fisher iris dataset betwee 60% training and 40% testing Dataset How can i divide that?
i am using this Example
It used all training examples not test example i want to divide it betwee train and test
load fisheriris
f = figure;
gscatter(meas(:,1), meas(:,2), species,'rgb','osd');
xlabel('Sepal length');
ylabel('Sepal width');
N = size(meas,1);
lda = fitcdiscr(meas(:,1:2),species);
ldaClass = resubPredict(lda);
0 Commenti
Risposte (2)
Chunru
il 6 Dic 2021
Modificato: Chunru
il 6 Dic 2021
load fisheriris
n = size(meas, 1);
%hpartition = cvpartition(n, 'holdout', 0.4); % 40% for test
hpartition = cvpartition(species, 'holdout', 0.4); % 40% for test
idxTrain = training(hpartition);
idxTest = test(hpartition);
pie(categorical(species(idxTrain))); % distribution of training samples
XTrain = meas(idxTrain, :);
TTrain = species(idxTrain);
XTest = meas(idxTest, :);
TTest = species(idxTest);
% Training
lda = fitcdiscr(XTrain(:,1:2), TTrain);
% Prediction
testClass = predict(lda, XTest(:, 1:2));
4 Commenti
Chunru
il 6 Dic 2021
For approximately equal partition:
hpartition = cvpartition(species, 'holdout', 0.4);
yanqi liu
il 7 Dic 2021
yes,sir,may be use the follow split method ,such as
close all;
clear all;
clc;
load fisheriris
cs = categorical(species);
ds = categories(cs);
training_x = [];training_y = [];
testing_x = [];testing_y = [];
for i = 1 : length(ds)
ind = find(cs == ds{i});
% rand suffer
ind = ind(randperm(length(ind)));
% 60% training and 40% testing
training_x = [training_x; meas(ind(1:round(length(ind)*0.6)),:)];
training_y = [training_y; cs(ind(1:round(length(ind)*0.6)),:)];
testing_x = [testing_x; meas(ind(1+round(length(ind)*0.6):end),:)];
testing_y = [testing_y; cs(ind(1+round(length(ind)*0.6):end),:)];
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Classification in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!