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 日
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 についてさらに検索
参考
2022 年 12 月 13 日
2022 年 12 月 16 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
