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 个)

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
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.
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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by