Error using fitecoc, validatestring in glmfit
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to train an ECOC and use it to predict on future data. It seemed to be working, but I am now getting an error message that I cannot figure out. The code continues to run, it just pops up a bunch of error messages. The error message is very long and goes through a fairly tall calltree, but ends with this:
'Error using glmfit (line 141)↵Expected input to match one of these values:↵↵'identity', 'log', 'logit', 'probit', 'comploglog', 'reciprocal', 'logloglink'↵↵The input, 'link', did not match any of the valid values.'
I have not been able to find any answers, and I cannot figure out what I could have changed in my script to cause it. The calltree goes through all of Matlabs own code, which I have not changed at all. Here is the segment of code I am running (italicized lines generating the error):
t = templateSVM('Standardize',true,'KernelFunction','gaussian'); %create a blank SVM template
Mdl = fitcecoc(x,y,'Learners',t,'FitPosterior',true,... %Train the ECOC classifier using the SVM template
'ClassNames',{'Non-PD','arc','trk','cor'},'Verbose',2);
CVMdl = crossval(Mdl); %cross validate
genError = kfoldLoss(CVMdl) %generalized estimation error
[label,~,~,Posterior] = resubPredict(Mdl,'Verbose',1); %Predict the training-sample labels and class posterior probabilities.
Thank you!
0 个评论
回答(1 个)
Aditya
2023-10-20
Hi Madeline,
I understand that you are encountering an error while working with ‘fitcecoc’ function. I have tested out your code by using sample data, and it executed successfully without any errors. To further assist you, kindly provide the specific data that you are using.
For your reference, I have included the code that I have used for testing.
% Sample data
x = randn(100, 10); % Replace with your own input data
y = randi([1, 4], 100, 1); % Replace with your own class labels
% Convert numeric class labels to cell array of strings
classLabels = {'Non-PD', 'arc', 'trk', 'cor'};
y = classLabels(y);
% Create a blank SVM template
t = templateSVM('Standardize', true, 'KernelFunction', 'gaussian');
% Train the ECOC classifier using the SVM template
Mdl = fitcecoc(x, y, 'Learners', t, 'FitPosterior', true, ...
'ClassNames', {'Non-PD', 'arc', 'trk', 'cor'}, 'Verbose', 2);
% Cross-validate
CVMdl = crossval(Mdl);
genError = kfoldLoss(CVMdl); % Generalized estimation error
% Predict the training-sample labels and class posterior probabilities
[label, ~, ~, Posterior] = resubPredict(Mdl, 'Verbose', 1);
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification Trees 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!