Training and group matrices for classifying data
Ältere Kommentare anzeigen
I am getting this error when trying to classify matrix data:
Error using classify (line 220) TRAINING must have more observations than the number of groups.
My classification data matrix is 10x5, my training matrix is 2x5, and my group vector is of length 2:
classificationFeatureValues =
1.0e+004 *
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
training =
1.0e+004 *
0.0005 0.0683 0.0063 3.3502 0.0113
0.0006 0.0761 0.0065 3.7003 0.0114
group =
1 2
I can't seem to find the error here...
Steve
Akzeptierte Antwort
Weitere Antworten (4)
Ilya
am 24 Jul. 2012
0 Stimmen
classify needs to estimate either the pooled-in covariance matrix (for linear discriminant) or covariance matrix for each class (for quadratic discriminant). You can't estimate covariance if you have one observation per class. What is observed variance for a single observation?
With so little data, you should use all of it for training and estimate classification error by cross-validation. If you have 2011b or later, I would recommend ClassificationDiscriminant for an easier workflow.
2 Kommentare
steve
am 25 Jul. 2012
Ilya
am 25 Jul. 2012
Sorry, I couldn't understand what you are saying about your acquisition.
Given the signature
classify(SAMPLE,TRAINING,GROUP)
You cannot perform discriminant analysis when your TRAINING matrix has only one observation (row) per class (distinct value in GROUP). The more observations you have for training, the more accurate your model is going to be. Take a look at examples in classify help or doc to see how GROUP and TRAINING are formed.
Greg Heath
am 26 Jul. 2012
For the quadratic classifier, CLASSIFY requires full rank covariance matrices for each group. However, for the linear classifier, it only requires the pooled covariance matrix to have full rank.
Neither of these conditions hold. If you combine the training and test data and use format short g you will get
close all, clear all, clc
ClassificationFeatureValues = 1.0e+004 *[...
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114
0.0006 0.0761 0.0065 3.7003 0.0113
0.0005 0.0683 0.0063 3.3502 0.0114 ]
Training =1.0e+004 *[...
0.0005 0.0683 0.0063 3.3502 0.0113
0.0006 0.0761 0.0065 3.7003 0.0114]
group = [ 1 2 ]
format short g
x = [ClassificationFeatureValues; Training]
x =
6 761 65 37003 113
5 683 63 33502 114
6 761 65 37003 113
5 683 63 33502 114
6 761 65 37003 113
5 683 63 33502 114
6 761 65 37003 113
5 683 63 33502 114
6 761 65 37003 113
5 683 63 33502 114
5 683 63 33502 113
6 761 65 37003 114
If you look closely at the 12 5-dimensional data points You will see that they collapse into two points. Therefore the data is only 1-dimensional and no formal classification is needed.
I usually recommend that, before classifier design, you should get a "feel" for the data via
1. plots and outlier checks
2. SVD condition and rank checks
3. Clustering
For example
>> svdx = svd(x)
svdx =
1.223e+005
24.571
0.69704
1.4925e-013
1.2842e-016
>> condx = cond(x)
condx = 9.5233e+020
>> tol = max(size(x)) * eps(norm(x))
tol = 1.7462e-010
>> rankx = rank(x,tol))
rankx = 3 % Too conservative
>> svdx/max(svdx)
ans =
1
0.00020092 % Essentially one-dimensional
5.6997e-006
1.2204e-018
1.0501e-021
Perhaps using your raw data will make the analysis more interesting.
Hope this helps.
Greg
steve
am 26 Jul. 2012
2 Kommentare
steve
am 26 Jul. 2012
Ilya
am 26 Jul. 2012
Again:
You cannot perform discriminant analysis when your TRAINING matrix has only one observation (row) per class (distinct value in GROUP).
If you type 'help classify', the very first example gives you:
load fisheriris
x = meas(51:end,1:2); % for illustrations use 2 species, 2 columns
y = species(51:end);
Could you please look at the content of y. There are two distinct values there, 'versicolor' and 'virginica'. These are classes. Rows 1:50 in x are for class 'versicolor', and so you have 50 observations for this class. Rows 51:100 are for class 'virginica', and you have 50 observations for that class too.
steve
am 31 Jul. 2012
0 Stimmen
1 Kommentar
Oleg Komarov
am 31 Jul. 2012
Please use comments. Who are you addressing with this question? If it is a standalone question open a new thread, however this doesn't sound like a MATLAB question and you might have more chances asking in math/stat forums.
Kategorien
Mehr zu Classification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!