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 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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!?
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!