Matlab Code - Data Analysis
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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일
0 개 추천
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
Mustafa Furkan SAHIN
2022년 12월 14일

now i am getting this error
Image Analyst
2022년 12월 14일
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/)
Image Analyst
2022년 12월 14일
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.
Mustafa Furkan SAHIN
2022년 12월 15일
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)
