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.
댓글 수: 0
답변 (1개)
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:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Classification Learner App에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!