why am i getting error with this code?

testdata = readtable("testdata.xlsx");
predictions = char(trainedModel.predictFcn(testdata));
iscorrect=predictions==cell2mat(string((testdata.Character)));
iscorrect=iscorrect(:,2);
accuracy = sum(iscorrect)*100/30;

댓글 수: 9

Fifteen12
Fifteen12 2023년 2월 8일
What is the error you're getting? Without your test data it's difficult to replicate your issue.
Walter Roberson
Walter Roberson 2023년 2월 8일
Does the predictFcn of the trainedModel accept a table as input?
Why are you comparing only the second character of each predicted value against the table ?
Why are you dividing accuracy by the magic number 30 instead of by the number of rows in incorrect ?
Kregozt
Kregozt 2023년 2월 8일
I am trying to predict the accuracy between 2 models using this code ,am using iris dataset as my sample data. I have used code to get 80% trained data and 20% test data by splitting the dataset by using cvpartition function.
Kregozt
Kregozt 2023년 2월 8일
Everytime I run the code the error is arising at line 2 dont know why. I was referring classification learner app video by matlabhelper on Youtube and tried doing the same in matlab but the code was giving error
Kregozt
Kregozt 2023년 2월 8일
I was diving by 30 because from matlab documentation I learnt that division should be done by the number of rows in test data
Walter Roberson
Walter Roberson 2023년 2월 9일
accuracy = mean(iscorrect) * 100.
try
predictions = trainedModel.predictFcn(testdata);
and show us class(predictions) and size(predictions)
Kregozt
Kregozt 2023년 2월 9일
but i have done the same but only converting the same to character
It would make it easier for us to advise you if you were to call
predictions = trainedModel.predictFcn(testdata);
whos predictions
and show us the output of the whos call.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 8일

0 개 추천

Without looking at your data, it is diffiuclt to address your question properly. Thus, pl., post your sample data.

댓글 수: 1

Kregozt
Kregozt 2023년 2월 8일
I am using IRIS dataset downloaded from kraggle

댓글을 달려면 로그인하십시오.

질문:

2023년 2월 8일

댓글:

2023년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by