Can someone tell me if there is an error in fitcdiscr function?

조회 수: 3 (최근 30일)
Jose Sanchez
Jose Sanchez 2018년 10월 20일
댓글: Tom Lane 2018년 11월 9일
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!

채택된 답변

Bernhard Suhm
Bernhard Suhm 2018년 11월 8일
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
Bernhard Suhm
Bernhard Suhm 2018년 11월 8일
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
Tom Lane 2018년 11월 9일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by