Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Bernhard Suhm
le 12 Juin 2018
But if your table has fewer columns (predictors) typically you need to retrain the model, or at least have performance deteriorate significantly!?
0 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!