Classifying data using machine learning
Afficher commentaires plus anciens
Using the fisheriris dataset in MATLAB, I want to use the first 30 datasets of each species for training and then predict the species of the other 20 based on the training data. I tried using the predict function, but it requires the training data vector and the prediction data vector to have the same dimensions. Is there a different function I can use that works the same way as the predict function and allows me to input vectors of varying sizes for training and prediction?
Here is the code I used:
N = size(meas,1);
newLabels = cell(90,1);
newLabels(1:30,1) = species(1:30,1);
newLabels(31:60,1) = species(51:80,1);
newLabels(61:90,1) = species(101:130,1);
trainData = cell(90,2);
trainData = str2double(trainData);
trainData(1:30,1) = meas(1:30,1);
trainData(31:60,1) = meas(51:80,1);
trainData(61:90,1) = meas(101:130,1);
trainData(1:30,2) = meas(1:30,2);
trainData(31:60,2) = meas(51:80,2);
trainData(61:90,2) = meas(101:130,2);
toPredict = cell(90,2);
toPredict = str2double(toPredict);
toPredict(1:30,1) = meas(21:50,1);
toPredict(31:60,1) = meas(71:100,1);
toPredict(61:90,1) = meas(121:150,1);
toPredict(1:30,2) = meas(21:50,2);
toPredict(31:60,2) = meas(71:100,2);
toPredict(61:90,2) = meas(121:150,2);
lda = fitcdiscr(trainData(:,1:2),newLabels);
ldaClass = predict(lda,toPredict);
ldaResubErr = resubLoss(lda);
figure
ldaResubCM = confusionchart(newLabels,ldaClass);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Classification Ensembles dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!