Regression tree and prediction equation
조회 수: 3 (최근 30일)
이전 댓글 표시
Suppose i have 3 independent variables A,B and C and dependent variable T. The variable A is discrete and B,C are continuous. The output variable T is also continuous. In such situation we need to create Regression tree. How can we generate prediction equation for such regression tree in MATLAB?
E.g.
A=[ 50 75 100 125 150 175 ];
B=[ 0.45 0.55 0.75 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1];
C=[3 4 5 6 7 8 9 10 11 12 13 14 15 16 ];
T= [ 1.2 1.8 2.1 2.3 2.5 2.7 2.8 3.1 3.2 3.3];
댓글 수: 5
dpb
2022년 11월 4일
A=[ 50 75 100 125 150 175 ];
B=[ 0.45 0.55 0.75 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1];
C=[3 4 5 6 7 8 9 10 11 12 13 14 15 16 ];
T= [ 1.2 1.8 2.1 2.3 2.5 2.7 2.8 3.1 3.2 3.3];
tABC=array2table([A;B(1:numel(A));C(1:numel(A));T(1:numel(A))].','VariableNames',{'A','B','C','T'})
mdl=fitlm(tABC,'categorical',{'A'})
While it runs, the toy dataset is deficient in that the three independent variables are all almost exact linear combinations of the first so there's only one of the three that is estimable...observe
corrcoef(tABC{:,:})
채택된 답변
the cyclist
2022년 11월 5일
This model is probably nonsense, because of the linear dependencies that @dpb points out. But perhaps your real data will yield a useful model. (Note that I transposed all your variables before putting them in a table.)
A = [ 50 75 100 125 150 175 ]';
Acat = categorical(A);
B = [ 0.45 0.55 0.75 0.8 0.9 1]';
C = [3 4 5 6 7 8]';
T= [ 1.2 1.8 2.1 2.3 2.5 2.7]';
tbl = table(Acat,B,C,T);
mdl=fitrtree(tbl,"T ~ Acat + B + C")
댓글 수: 2
the cyclist
2022년 11월 5일
The model the way I specified it should do what you want. You can then use that model's predict method to predict T for new values.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!