# LinearModel.fit results to array

조회 수: 5 (최근 30일)
OoM 2013년 8월 26일
Hi,
I would like to ask about results from LinearModel.fit function. I used the function and it ran smoothly. However, I could not extract the result properly.
I have a 100 set of X and Y. What I would like to have is a array showing coefficient and R-square of all. I basically try to do a loop and have LinearModel.fit function inside. My problem is I could not write out coefficient from mdl.Coefficients and r-square from mdl.Rsquared.Ordinary value to save into my array.
I crated array 100 x 1 to save R-square value from each set. To sum up, how can I save the values of results from each set to array?
Thank you.

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

### 답변 (3개)

Leah 2013년 8월 26일
I was able to do it, i made a dataset mid to hold everything
md = LinearModel.fit()
mid.Intercept=md.Coefficients.Estimate(1);
for c=2:length(md.CoefficientNames)
mid.(md.CoefficientNames{c})=md.Coefficients.Estimate(c);
end
##### 댓글 수: 2없음 표시없음 숨기기
OoM 2013년 8월 26일
Thank you very much.
OoM 2013년 8월 26일
gave me
mid =
Rsq: 0.8690
It is in struct format. Any way to transform it to array
Rsq = [0.8690]

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

the cyclist 2013년 8월 26일
mdl.Coefficients
is a variable of type dataset.
mdl.Coefficients.Estimate
will be an array of doubles, which I think is what you need.
##### 댓글 수: 2없음 표시없음 숨기기
OoM 2013년 8월 26일
I tried to call only mdl.Coefficients.Estimate. It does not work.
the cyclist 2013년 8월 27일
Does calling this code give you a 5x1 double for mdl.Coefficients.Estimate?
X = ingredients; % predictor variables
y = heat; % response
mdl = LinearModel.fit(X,y)
mdl.Coefficients.Estimate

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

OoM 2013년 8월 26일
I am able to get R-squared from
rsq = mdl.Rsquared.Ordinary
rsq =
0.8690
and only coefficient from
Coefficient = mdl.Coefficients.Estimate(:,1)
Coefficient =
1.0e+05 *
1.4231
-0.0012

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

### 카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by