Machine Learning with MATLAB 4.7, Further Practice

1 次查看(过去 30 天)
The question is to find a confusion chart. Before that, there were two tasks to complete.
Pre-existing code:
rng(0)
load creditData
creditRatings
mdlFull
fullLoss = kfoldLoss(mdlFull)
Construct a tree model for Task 1:
tModel = fitctree(creditRatings, "Rating")
p = predictorImportance(tModel)
bar(p)
xticklabels(creditRatings.Properties.VariableNames(1:end-1))
xtickangle(60)
[~,iSorted] = sort(p)
selected = [iSorted(1:3) width(creditRatings)]
mdl = fitctree(creditRatings(:,selected), "Rating", "KFold", 7)
mdlLoss = kfoldLoss(mdl)
Task 2 (which I don't think is relevant to the Further Practice) was to construct an ensemble model:
mdlEns = fitcensemble(creditRatings(:, selected), "Rating", "Method", "Bag", "Learners", "tree", "NumLearningCycles", 50, "KFold", 7)
lossEns = kfoldLoss(mdlEns)
For the further practice, I attempted to get a prediction (there is no dataTest/dataTrain presented) but kep getting the error "Check for missing argument or incorrect argument data type in call to function 'predict'". The following lines each gave the error.
prediction = predict(mdl, creditRatings)
prediction = predict(mdl, creditRatings.Rating)
%confusionchart(creditRatings.Rating, prediction)
Perhaps the data needs to be divided by the user? I read that either the model type isn't "ClassificationTree", or the data should be a table. double or single. As far as I can tell, I have used a tree model, and creditRatings is a table.
anonfun = @(XTrain,yTrain,XTest,yTest) nnz(yTest ~= predict(fitfunction(XTrain,yTrain),XTest))
Am unsure how to call yTrain though from this function.

回答(1 个)

Vishesh
Vishesh 2023-9-21
I understand that you are getting following error when calling "predict" function in your script:
Check for missing argument or incorrect argument data type in call to function 'predict'
Please refer to the following MATLAB answer for a solution to resolve this error:
Also, please refer to the following MATLAB answer for guidance to split your data into training and testing data:

类别

Help CenterFile Exchange 中查找有关 Classification Learner App 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by