Error Troubleshooting Classification Models

Im getting this error when i run my code
This is the code i am running
data = readmatrix('project.xlsx')
Tbl = array2table(data);
varNames = ["Number","Amplitude","PSD","Recurrence_Rate","Recurrance_Points","Determinism","Ratio_Determinism_Recurrence_Rate","Average_Diagonal_Length","Average_Vertical_Length","Laminarity","Divergence","Entropy","Trapping_Time","OSA_Label"];
mdl = fitcdiscr(Tbl, Number)
Please help troubleshoot this

답변 (1개)

Kevin Holly
Kevin Holly 2023년 4월 25일
편집: Kevin Holly 2023년 4월 25일

0 개 추천

I believe you meant this:
mdl = fitcdiscr(Tbl, "Number")
instead of
mdl = fitcdiscr(Tbl, Number)
Edit: Also what does your table look like? Does it have those variable names?

댓글 수: 6

yes my excel spreadsheet has those variable names and i did what you suggested and I am getting the same error
Kevin Holly
Kevin Holly 2023년 4월 25일
편집: Kevin Holly 2023년 4월 25일
What does your table look like in MATLAB? Does a column have all NaN values?
Edit: Also, if your spreadsheet has the variable names in them, you could just use the readtable function.
Alexander
Alexander 2023년 4월 25일
편집: Alexander 2023년 4월 25일
yes there are some columns that all have NaN values.
What happens if you remove those columns?
data = rand(8,3);
Tbl = array2table(data)
Tbl = 8×3 table
data1 data2 data3 ________ ________ _______ 0.23731 0.46833 0.54526 0.078655 0.59081 0.92126 0.10231 0.081329 0.33098 0.35795 0.56482 0.90856 0.72278 0.6245 0.53955 0.27269 0.060516 0.36081 0.28477 0.64597 0.58377 0.58245 0.66949 0.16396
You can remove a column programmatically as such:
Tbl.data2 = []
Tbl = 8×2 table
data1 data3 ________ _______ 0.23731 0.54526 0.078655 0.92126 0.10231 0.33098 0.35795 0.90856 0.72278 0.53955 0.27269 0.36081 0.28477 0.58377 0.58245 0.16396
FYI, you could use the import tool to import your data and then generate a function to import similar data files in the future. See link below.
i am now getting an error that says X and Y do not have the same number of observations
Is it possible that you can share your Excel sheet or one with similar data?

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

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

질문:

2023년 4월 25일

댓글:

2023년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by