Can someone tell me if there is an error in fitcdiscr function?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jose Sanchez
am 20 Okt. 2018
Kommentiert: Tom Lane
am 9 Nov. 2018
I think the fitcdiscr function has error(s). I tested both the quadratic discrimination option:
rng('default'); X = rand(40,2); GroupLabels = randsample({'HC','MCI'}, 40, true)'; Cost0 = [0 1; 1 0];
DAC = fitcdiscr(X, GroupLabels, 'DiscrimType', 'quadratic', 'Cost', Cost0);
K = DAC.Coeffs(1,2).Const;
L = DAC.Coeffs(1,2).Linear;
Q = DAC.Coeffs(1,2).Quadratic;
and the linear augmented option that reproduce the same quadratic fit:
X1 = X(:,1); X2 = X(:,2); X3 = X1.*X1; X4 = X1.*X2; X5 = X2.*X2;
tbl = table(GroupLabels, X1, X2, X3, X4, X5);
DAC2 = fitcdiscr(tbl, 'GroupLabels ~ X1 + X2 + X3 + X4 + X5', 'Cost', Cost0);
K2 = DAC2.Coeffs(1,2).Const;
L2 = DAC2.Coeffs(1,2).Linear;
Please check the values of K,L,Q and K2,L2. They don't match, not even close and fitting is very differenct between both classifiers.
Also, I think that fitcdiscr is not reading or using properly the specified formula. Previously, I had used the declaration:
DAC2 = fitcdiscr(tbl, 'GroupLabels ~ X1 + X2 + X3 + X5 + X4', 'Cost', Cost0);
That is, switching the 4th and 5th predictors, and the coefficient values were the same in the same order.
But that is wrong (in my opinion) cause coefficients 4th and 5th are now inverted!
Thanks!
0 Kommentare
Akzeptierte Antwort
Bernhard Suhm
am 8 Nov. 2018
LDA fits normal distributions with the same covariance. QDA allows different covariances. Fitting normal distributions including squared and product terms usually won't give the same results as QDA on just the linear terms.
3 Kommentare
Bernhard Suhm
am 8 Nov. 2018
You could review your favorite reference explaining linear versus quadratic discriminant analysis, e.g. on Wikipedia. - Regarding the order, you defined X4 and X5 as something specific, not to reference specific columns in your matrix, that's why the order in your formula doesn't matter.
Tom Lane
am 9 Nov. 2018
To elaborate on Bernhard's response, the formulas generally define the types of terms to be used rather than the order, and this is easier to see in functions that produce coefficients that are displayed directly:
>> fitlm(t,'x1~x3+x2')
ans =
Linear regression model:
x1 ~ 1 + x2 + x3
Estimated Coefficients:
Estimate SE tStat pValue
________ ________ ______ __________
(Intercept) 2.2491 0.24797 9.0702 7.0385e-16
x2 0.59552 0.069328 8.5899 1.1633e-14
x3 0.47192 0.017118 27.569 5.8479e-60
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discriminant Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!