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 件のコメント

Alexander
Alexander 2023 年 4 月 25 日
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.
Kevin Holly
Kevin Holly 2023 年 4 月 25 日
編集済み: Kevin Holly 2023 年 4 月 25 日
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.
Alexander
Alexander 2023 年 4 月 25 日
i am now getting an error that says X and Y do not have the same number of observations
Kevin Holly
Kevin Holly 2023 年 4 月 26 日
Is it possible that you can share your Excel sheet or one with similar data?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData 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