My program crashes without asking the user for sample data, how can I fix this? It worked when I tried the values of smaller datasets.
I have a Higher Education Students Performance Evaluation Dataset (https://archive.ics.uci.edu/ml/datasets/Higher+Education+Students+Performance+Evaluation+Dataset ).

 Akzeptierte Antwort

Image Analyst
Image Analyst am 13 Dez. 2022

0 Stimmen

Not sure - we don't have your code or data. I'd start with carefully examining the arguments you pass to fitcknn.

8 Kommentare

Mustafa Furkan SAHIN
Mustafa Furkan SAHIN am 14 Dez. 2022
Bearbeitet: Mustafa Furkan SAHIN am 14 Dez. 2022
% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 6);
% Specify range and delimiter
opts.DataLines = [1, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["StudentAge","Sex","Graduatedhigh-schooltype","Scholarshiptype","Additionalwork","Regularartisticorsportsactivity","Doyouhaveapartner","Totalsalaryifavailable","Transportationtotheuniversity","AccommodationtypeinCyprus","Mothereducation","Fathereducation","Numberofsisters/brothers(ifavailable)","Parentalstatus","Motheroccupation","Fatheroccupation","Weeklystudyhours","Readingfrequency(non-scientificbooks/journals)","Readingfrequency(scientificbooks/journals)","Attendancetotheseminars/conferencesrelatedtothedepartment","Impactofyourprojects/activitiesonyoursuccess","Attendancetoclasses","Preparationtomidtermexams1","Preparationtomidtermexams2","Takingnotesinclasses","Listeninginclasses","Discussionimprovesmyinterestandsuccessinthecourse","Flip-classroom","Cumulativegradepointaverageinthelastsemester[/4.00]","ExpectedCumulativegradepointaverageinthegraduation[/4.00]","CourseID","OUTPUTGrade"];
opts.VariableTypes = ["double","double","double","double", "double","double", "double", "double", "double","double","double", "double", "double", "double", "double","double", "double", "double", "double","double","double", "double", "double", "double", "double","double", "double", "double", "double","double","double","categorical"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "OUTPUTGrade", "EmptyFieldRule", "auto");
% Import the data
ornek = readtable("DATA.dat", opts); %I converted from numeric to category. so i changed my file type.
% Clear temporary variables
clear opts
%Predict KNN
modelformed = fitcknn(ornek,'OUTPUTGrade~StudentAge+Sex+Graduatedhigh-schooltype+Scholarshiptype+Additionalwork+Regularartisticorsportsactivity+Doyouhaveapartner+Totalsalaryifavailable+Transportationtotheuniversity+AccommodationtypeinCyprus+Mothereducation+Fathereducation+Numberofsisters/brothers(ifavailable)+Parentalstatus+Motheroccupation+Fatheroccupation+Weeklystudyhours+Readingfrequency(non-scientificbooks/journals)+Readingfrequency(scientificbooks/journals)+Attendancetotheseminars/conferencesrelatedtothedepartment+Impactofyourprojects/activitiesonyoursuccess+Attendancetoclasses+Preparationtomidtermexams1+Preparationtomidtermexams2+Takingnotesinclasses+Listeninginclasses+Discussionimprovesmyinterestandsuccessinthecourse+Flip-classroom+Cumulativegradepointaverageinthelastsemester[/4.00]+ExpectedCumulativegradepointaverageinthegraduation[/4.00]+CourseID');
modelformed.NumNeighbors=31;
a1=input('Enter StudentAge: ');
a2=input('Enter Sex: ');
a3=input('Enter Graduatedhigh-schooltype: ');
a4=input('Enter Additionalwork: ');
a5=input('Enter Regularartisticorsportsactivity: ');
a6=input('Enter Doyouhaveapartner: ');
a7=input('Enter Totalsalaryifavailable: ');
a8=input('Enter Transportationtotheuniversity: ');
a9=input('Enter AccommodationtypeinCyprus: ');
a10=input('Enter Mothereducation: ');
a11=input('Enter Fathereducation: ');
a12=input('Enter Numberofsisters/brothers(ifavailable): ');
a13=input('Enter Parentalstatus: ');
a14=input('Enter Motheroccupation: ');
a15=input('Enter Fatheroccupation: ');
a16=input('Enter Weeklystudyhours: ');
a17=input('Enter Readingfrequency(non-scientificbooks/journals): ');
a18=input('Enter Readingfrequency(scientificbooks/journals): ');
a19=input('Enter Attendancetotheseminars/conferencesrelatedtothedepartment: ');
a20=input('Enter Impactofyourprojects/activitiesonyoursuccess: ');
a21=input('Enter Attendancetoclasses: ');
a22=input('Enter Preparationtomidtermexams1: ');
a23=input('Enter Preparationtomidtermexams2: ');
a24=input('Enter Takingnotesinclasses: ');
a25=input('Enter Listeninginclasses: ');
a26=input('Enter Discussionimprovesmyinterestandsuccessinthecourse:');
a27=input('Enter Flip-classroom: ');
a28=input('Enter Cumulativegradepointaverageinthelastsemester[/4.00]: ');
a29=input('Enter ExpectedCumulativegradepointaverageinthegraduation[/4.00]: ');
a30=input('Enter CourseID: ');
predict(modelformed,[Sex,Graduatedhigh-schooltype,Additionalwork,Regularartisticorsportsactivity,Doyouhaveapartner,Totalsalaryifavailable,Transportationtotheuniversity,AccommodationtypeinCyprus,Mothereducation,Fathereducation,Numberofsisters/brothers(ifavailable),Parentalstatus,Motheroccupation,Fatheroccupation,Weeklystudyhours,Readingfrequency(non-scientificbooks/journals),Readingfrequency(scientificbooks/journals),Attendancetotheseminars/conferencesrelatedtothedepartment,Impactofyourprojects/activitiesonyoursuccess,Attendancetoclasses,Preparationtomidtermexams1,Preparationtomidtermexams2,Takingnotesinclasses,Listeninginclasses,Discussionimprovesmyinterestandsuccessinthecourse,Flip-classroom,Cumulativegradepointaverageinthelastsemester,ExpectedCumulativegradepointaverageinthegraduation,CourseID])
i did it this way.There should be no mistake ,but it returns error
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN am 14 Dez. 2022
now i am getting this error
Try getting rid of spaces and dashes in the variable names. And make sure none of the names is more than 63 characters. If that doesn't work, also make it a cell array instead of a string array.
opts.VariableNames = {'StudentAge', 'Sex', 'GraduatedHighSchoolType', .................................};
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN am 14 Dez. 2022
Bearbeitet: Mustafa Furkan SAHIN am 16 Dez. 2022
Thank you for your answer ,but unfortunately it didn't work.
The code I wrote does not read the values of this dataset.
opts = delimitedTextImportOptions("NumVariables", 8);
% Specify range and delimiter
opts.DataLines = [1, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["mcg", "gvh", "lip", "chg", "aac", "alm1", "alm2", "Class"];
opts.VariableTypes = ["double", "double", "double", "double", "double", "double", "double", "categorical"];
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts = setvaropts(opts, "Class", "EmptyFieldRule", "auto");
ecoliKNN = readtable("ecoliKNN.data", opts);
clear opts
modelformed = fitcknn(ecoliKNN,'Class~mcg+gvh+lip+chg+aac+alm1+alm2');
modelformed.NumNeighbors=3;
mcg=input('Enter mcg: ');
gvh=input('Enter gvh: ');
lip=input('Enter lip: ');
chg=input('Enter chg: ');
aac=input('Enter aac: ');
alm1=input('Enter alm1: ');
alm2=input('Enter alm2: ');
predict(modelformed,[mcg,gvh,lip,chg,aac,alm1,alm2])
But the code is reading this dataset (https://archive.ics.uci.edu/ml/machine-learning-databases/ecoli/)
Image Analyst
Image Analyst am 14 Dez. 2022
Make it easy for us to help you, not hard. Attach the dataset and your m-file. Zip them up if you have to.
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN am 14 Dez. 2022
Bearbeitet: Mustafa Furkan SAHIN am 15 Dez. 2022
I have attached all required file types.
Image Analyst
Image Analyst am 15 Dez. 2022
Bearbeitet: Image Analyst am 15 Dez. 2022
Do this:
t = readtable("DATA.csv");
tPredictors = t(:, 2:end);
DATA = table2array(tPredictors)
X = DATA(:, 1:31); % Input ("Predictors")
trueResponseY = DATA(:,32); % True Output (class numbers)
Then go to the Apps tab on the tool ribbon and start up the Classification Learner and start a session using data from the workspace. Tell it tPredictors is your prediction input and trueResponseY are your true response values. Then select all Bayes models, and others if you want, and tell it to train. You'll get this result:
Then go to the Export button and export the compact model into a variable. Save that variable with save() to a mat file. Then you can read in that model and give it your predictors and get the estimated class.
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN am 15 Dez. 2022
Thanks a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by