필터 지우기
필터 지우기

How to fix table variable related error?

조회 수: 30 (최근 30일)
Sanchit
Sanchit 2023년 7월 25일
댓글: Mrutyunjaya Hiremath 2023년 7월 27일
I am using the following matlab code
MdlReduced = fitrensemble(XX(:,{'td' 'ssr' 'tp'}),MPG,'Method','Bag', ...
'NumLearningCycles',200,'Learners',t);
But this is giving the following error
Error using ()
Unrecognized table variable name 'td'.
Please suggest me how to fix it?
Sanchit
  댓글 수: 2
Saurabh Chaudhary
Saurabh Chaudhary 2023년 7월 25일
can you provide data for XX? Also look the documentation of fitrensemble.
Sanchit
Sanchit 2023년 7월 25일
Thank you very much for your kind suggestion. I have attached sample data file along with code in previous comment. I request you to kindly have look on it and suggest me how to fix it.
Sanchit

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

채택된 답변

Mrutyunjaya Hiremath
Mrutyunjaya Hiremath 2023년 7월 25일
Here It is ...
clc;
clear all;
close all;
data = readtable('sample.csv');
X = data(:, 1:end);
% Get the current variable names
currentVariableNames = data.Properties.VariableNames;
% Define the new variable names (use as many names as you have variables)
newVariableNames = {'d2m','t2m','ev','pev','ssr','ssrd','tp','vpd','rh','gpp'};
% Create a new table with the new variable names
data = array2table(data{:,:}, 'VariableNames', newVariableNames);
t = templateTree('PredictorSelection','interaction-curvature','Surrogate','on', ...
'Reproducible',true); % For reproducibility of random predictor selections
MdlReduced = fitrensemble(data(:,{'d2m' 'ssr' 'tp'}),data(:,'gpp'),'Method','Bag', ...
'NumLearningCycles',200,'Learners',t);
%Compute the R2 of the reduced model.
yHatReduced = oobPredict(MdlReduced);
r2Reduced = corr(MdlReduced.Y,yHatReduced)^2
  댓글 수: 2
Sanchit
Sanchit 2023년 7월 25일
Thank you very much for your kind help. It worked well. Can I request you to kindly help me in one more code with same sample input file. I am attaching the code for your kind help.
Sanchit
Mrutyunjaya Hiremath
Mrutyunjaya Hiremath 2023년 7월 27일
Welcome .. :)

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

추가 답변 (1개)

Steven Lord
Steven Lord 2023년 7월 25일
You expected for your table XX to contain a variable named td, but it doesn't. If you were trying to adapt another example to your needs perhaps the table in the example had that variable but yours does not. You can check if XX has that variable name:
listOfVariableNames = XX.Properties.VariableNames
Does listOfVariableNames contain 'td'?
ismember('td', listOfVariableNames)
Without seeing how you constructed XX it's difficult to offer concrete suggestions for how to solve the problem. If you read the data in from a file perhaps the file headers were not what you expected them to be? If you constructed that table variable using an expression [like td(:, 1)] instead of a plain variable name [like td] then the table variable would not be named using the variable name. Setting the variable name using renamevars could be an option in that scenario.
  댓글 수: 1
Sanchit
Sanchit 2023년 7월 25일
Thank you very much for your prompt suggestions. I am attaching the matlab code along withsample input file. I request you to kindly have a look on it and suggest me how to fix it.
I appreciate your kind help.
Sanchit

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

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by