Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Classification Learner App - generate a more generic function for your model training that could take varying size of prediction tables? One step beyond the default function generation

1 回表示 (過去 30 日間)
Andy
Andy 2018 年 5 月 27 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
This is a question with an answer, that could easily translate into a feature implementation. When one generates a function from a Classification Learner App on a found model, typically the Function content is really static:
1) It is tied to the original Prediction Table Column Names / Properties. 2) As a consequence, the function cannot be used on a different table that might have more or less columns [but where we still have y as the last column] (why would you do that is another topic all-together).
I found that modifying the original function file with the below function:
function nameNewExt = aAdjustTrainClassifier(~,trainClassFile)
% aAdjustTrainClassifier
%
%
fidi=fopen(trainClassFile,'r');
[~,name,~]=fileparts(trainClassFile);
nameNew = strcat('aAdjusted_',name);
nameNewExt = strcat(nameNew,'.m');
if exist(nameNewExt, 'file') == 2
% file already exists, no overwrite ...
else
fido=fopen(nameNewExt,'w');
while ~feof(fidi)
l=fgetl(fidi); % read line
if startsWith(l,'predictorNames = ')
% modify line here
l='predictorNames = inputTable.Properties.VariableNames(:,1:end-1);';
elseif startsWith(l,'isCategoricalPredictor = ')
l='isCategoricalPredictor = false(1,length(predictorNames));';
elseif contains(l,strcat('function [trainedClassifier, validationAccuracy] ='," ",name,'(trainingData)'))
l=strcat('function [trainedClassifier, validationAccuracy] ='," ",nameNew,'(trainingData)');
elseif startsWith(l,'trainedClassifier.RequiredVariables = ')
l=strcat('trainedClassifier.RequiredVariables ='," ",'inputTable.Properties.VariableNames(:,1:end-1)');
end
fprintf(fido,'%s\n',l); % 'fgetl returns \n so it's embedded
end
fclose(fido);
end
fclose(fidi);
fclose('all');
end
does the trick. Some static assumptions made (as for my use-case), and this might not work in all instances, however - would be grateful if you could provide feedback / improvements. Another reason for posting is - this could easily translate into a GREAT feature to be implemented.
Thanks

回答 (1 件)

Bernhard Suhm
Bernhard Suhm 2018 年 6 月 12 日
But if your table has fewer columns (predictors) typically you need to retrain the model, or at least have performance deteriorate significantly!?

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by