Error in fitlm function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I am using
reg = fitlm(X_train, Y_train);
But it gives following errors;
Error in fitlm (line 122)
model = LinearModel.fit(X,varargin{:});
I request you to kindly have a look on attached matlab code and input file and suggest me how to fix it.
Devender
test()
df = 100×20 table
Var1 POS value MAX sum AVG sum SOS POS EOS Base Duration First half Second half Growth rate Senescence rate Peaks total_cane act_y_ha act_per_ha field_yield total_FS variety
____ _________ _______ _______ ____ ___ ___ ______ ________ __________ ___________ ___________ _______________ _____ __________ ________ __________ ___________ ________ _____________
0 3.1771 149.35 92.117 79 334 729 2.9793 650 255 395 2.6824 -1.5491 2 8719 1026 118.7 11.57 1008.8 {'NCO334' }
1 3.9655 180.34 122.08 19 229 729 3.8176 710 210 500 3.6809 -2.633 3 23962 1653 188.9 11.43 2739 {'CO740' }
2 3.3081 156.67 103.54 99 334 729 3.0564 630 235 395 2.8323 -1.408 1 28828 1386 159 11.47 3307.5 {'NCO334' }
3 3.4482 139.52 85.993 39 229 759 3.2743 720 190 530 2.5075 -2.7583 1 6108 364 31.7 8.72 532.6 {'CO740' }
4 3.8306 176.85 119.2 19 294 729 3.6499 710 275 435 3.5651 -2.2468 2 44705 1739 208.8 12 5365.5 {'NCO334' }
5 3.4701 145.87 111.34 99 319 699 3.2575 600 220 380 3.0761 -1.0609 1 4604 2093 233.1 11.14 512.9 {'Mex54-245'}
6 3.733 196.27 145.09 39 294 789 3.5574 750 255 495 3.2482 -3.4094 3 38435 2159 267.6 12.39 4762.6 {'NCO334' }
7 3.0975 167.82 123.67 -236 114 454 2.8192 690 350 340 2.5781 -2.4782 2 7567 1182 117.6 9.95 752.9 {'Mex54-245'}
8 3.2312 150.91 119.68 129 334 729 2.9267 600 205 395 1.8209 -1.4896 1 5698 1266 143 11.29 643.3 {'B41227' }
9 3.6544 188.29 123.56 79 294 759 3.4433 680 215 465 3.3051 -2.348 3 21706 1632 203.4 12.47 2705.7 {'NCO334' }
10 3.8049 167.1 119.96 129 319 729 3.5039 600 190 410 2.1563 -2.0176 3 5500 1618 189.9 11.74 645.7 {'Mex54-245'}
11 3.7917 162.24 113.38 99 324 699 3.6036 600 225 375 3.4075 -1.1251 2 28625 2157 248.2 11.51 3293.8 {'Mex54-245'}
12 2.6391 109.44 92.363 129 334 669 2.3069 540 205 335 0.48525 -0.70277 1 6729 1373 144.7 10.54 709.1 {'C86/56' }
13 3.525 162.31 123.12 129 229 759 3.2314 630 100 530 1.9618 -1.8762 2 12643 1642 191.3 11.65 1472.7 {'NCO334' }
14 3.3622 168.53 130.99 129 334 759 3.0431 630 205 425 1.839 -1.7134 3 12237 1654 199.5 12.07 1476.5 {'B52298' }
15 4.3618 184.75 134.22 19 294 759 4.1654 740 275 465 3.3812 -3.3908 2 28287 1911 222.7 11.65 3295.8 {'B52298' }
X = 100×13 table
POS value MAX sum AVG sum SOS POS EOS Base Duration First half Second half Growth rate Senescence rate Peaks
_________ _______ _______ ____ ___ ___ ______ ________ __________ ___________ ___________ _______________ _____
3.1771 149.35 92.117 79 334 729 2.9793 650 255 395 2.6824 -1.5491 2
3.9655 180.34 122.08 19 229 729 3.8176 710 210 500 3.6809 -2.633 3
3.3081 156.67 103.54 99 334 729 3.0564 630 235 395 2.8323 -1.408 1
3.4482 139.52 85.993 39 229 759 3.2743 720 190 530 2.5075 -2.7583 1
3.8306 176.85 119.2 19 294 729 3.6499 710 275 435 3.5651 -2.2468 2
3.4701 145.87 111.34 99 319 699 3.2575 600 220 380 3.0761 -1.0609 1
3.733 196.27 145.09 39 294 789 3.5574 750 255 495 3.2482 -3.4094 3
3.0975 167.82 123.67 -236 114 454 2.8192 690 350 340 2.5781 -2.4782 2
3.2312 150.91 119.68 129 334 729 2.9267 600 205 395 1.8209 -1.4896 1
3.6544 188.29 123.56 79 294 759 3.4433 680 215 465 3.3051 -2.348 3
3.8049 167.1 119.96 129 319 729 3.5039 600 190 410 2.1563 -2.0176 3
3.7917 162.24 113.38 99 324 699 3.6036 600 225 375 3.4075 -1.1251 2
2.6391 109.44 92.363 129 334 669 2.3069 540 205 335 0.48525 -0.70277 1
3.525 162.31 123.12 129 229 759 3.2314 630 100 530 1.9618 -1.8762 2
3.3622 168.53 130.99 129 334 759 3.0431 630 205 425 1.839 -1.7134 3
4.3618 184.75 134.22 19 294 759 4.1654 740 275 465 3.3812 -3.3908 2
Y = 100×1
1026
1653
1386
364
1739
2093
2159
1182
1266
1632
Error using classreg.regr.TermsRegression.createFormula
The terms matrix must have one column for each variable in the dataset or table. You may not specify the response as a separate vector with a dataset or table.
The terms matrix must have one column for each variable in the dataset or table. You may not specify the response as a separate vector with a dataset or table.
Error in LinearModel.createFormula (line 1076)
formula = classreg.regr.TermsRegression.createFormula(supplied,modelDef, ...
Error in LinearModel.fit (line 1058)
model.Formula = LinearModel.createFormula(supplied,modelDef,X, ...
Error in fitlm (line 122)
model = LinearModel.fit(X,varargin{:});
Error in test (line 27)
reg = fitlm(X_train, Y_train);
채택된 답변
Walter Roberson
2024년 3월 7일
이동: Walter Roberson
2024년 3월 7일
% Load data
df = readtable('input_file.csv','VariableNamingRule','preserve');
dependent_vars = {'act_y_ha', 'act_per_ha'};
for jj = 1:length(dependent_vars)
var = dependent_vars{jj};
v = {'POS value', 'MAX sum', 'AVG sum', 'SOS', 'POS', 'EOS', ...
'Base', 'Duration', 'First half', 'Second half', 'Growth rate', ...
'Senescence rate', 'Peaks'};
v_to_use = v(ismember(v,df.Properties.VariableNames));
new_T = df(:,v_to_use);
X = new_T;
Y = df{:, var};
% Split data
cv = cvpartition(size(X, 1), 'HoldOut', 0.2);
idxTrain = training(cv);
idxTest = test(cv);
X_train = X{idxTrain, :};
X_test = X{idxTest, :};
Y_train = Y(idxTrain);
Y_test = Y(idxTest);
reg = fitlm(X_train, Y_train, 'linear');
% Prediction
Y_pred = predict(reg, X_test);
% Evaluation
r2_reg = 1 - sum((Y_test - Y_pred).^2)/sum((Y_test - mean(Y_test)).^2);
rmse = sqrt(mean((Y_test - Y_pred).^2));
disp([ char(var), ' ', num2str(r2_reg,2), ' ', num2str(rmse,2)]);
end
Warning: Regression design matrix is rank deficient to within machine precision.
act_y_ha 0.66 2.3e+02
Warning: Regression design matrix is rank deficient to within machine precision.
act_per_ha 0.6 32
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
