Matlab Code - Data Analysis
显示 更早的评论
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 ).
采纳的回答
Image Analyst
2022-12-13
Not sure - we don't have your code or data. I'd start with carefully examining the arguments you pass to fitcknn.
8 个评论
Mustafa Furkan SAHIN
2022-12-14
编辑:Mustafa Furkan SAHIN
2022-12-14
% 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

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
2022-12-14
编辑:Mustafa Furkan SAHIN
2022-12-16
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/)
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
2022-12-14
编辑:Mustafa Furkan SAHIN
2022-12-15
I have attached all required file types.
Image Analyst
2022-12-15
编辑:Image Analyst
2022-12-15
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.
Thanks a lot
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Classification Trees 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
