How to Split fisher iris data into 60% training and 40% Testing
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Chunru
2021 年 12 月 6 日
編集済み: Chunru
2021 年 12 月 6 日
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 件のコメント
Chunru
2021 年 12 月 6 日
For approximately equal partition:
hpartition = cvpartition(species, 'holdout', 0.4);
yanqi liu
2021 年 12 月 7 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Classification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!