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

Risposte (1)

Kevin Holly
Kevin Holly il 25 Apr 2023
Modificato: Kevin Holly il 25 Apr 2023
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 Commenti

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 il 25 Apr 2023
Modificato: Kevin Holly il 25 Apr 2023
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 il 25 Apr 2023
Modificato: Alexander il 25 Apr 2023
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?

Accedi per commentare.

Categorie

Richiesto:

il 25 Apr 2023

Commentato:

il 26 Apr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by