Logistic Regression - Error: The sizes of B and X are incompatible.

조회 수: 2 (최근 30일)
Nirmal
Nirmal 2012년 6월 1일
I am trying to use Logistic regression to predict the class of IRIS data set.
data=LoadIRISData();
class=zeros(150,1);
class(1:50,1)=1;
class(51:100,1)=2;
class(101:150,1)=3;
dataf=[data(1:20,:);data(51:70,:);data(101:120,:)];
classf=[class(1:20,:);class(51:70,:);class(101:120,:)];
betaHatNorm=mnrfit(dataf,classf);
datat=[data(21:50,:);data(71:100,:);data(121:150,:)];
pHatNom = mnrval(betaHatNom,datat);
When I run the code, I get the following error.
??? Error using ==> mnrval at 191
The sizes of B and X are incompatible.
Error in ==> logireg at 15
pHatNom = mnrval(betaHatNom,datat);
I am new with logistic regression, I am not sure, why I get the error. I even tried making the rows number of dataf and datat same but without success.
Thank you.

채택된 답변

Tom Lane
Tom Lane 2012년 6월 1일
If I type
load fisheriris
data = meas
and then run your code after from the "load" line, then it works okay after I correct the spelling of betaHatNorm on the last line. Could it be you have two versions of that variable, and you're picking up the wrong one?
  댓글 수: 1
Nirmal
Nirmal 2012년 6월 1일
one little "r" makes all the difference and I overlooked :|

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by