Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary LDA classifier throws error when trying to return probabilities per class #49

Closed
benjybarnett opened this issue Sep 26, 2024 · 4 comments

Comments

@benjybarnett
Copy link

Hi. I am trying to run a simple binary cross-decoding analysis, and I would like classifier output to show the predicted class probabilities.

I am using the following code:

cfgS = [];
cfgS.classifier = 'lda';
cfgS.metric = 'none';
cfgS.preprocess ={'undersample'};
cfgS.output_type = 'prob';
cfgS.repeat = 1;
cfgS.sample_dimension = 1;
cfgS.feature_dimension = 2;
[train_dot_accuracy,~] = mv_classify(cfgS, dot_data, binary_dot_lbls_recode, face_data, face_lbls); 

But I receive the following error:

Output argument "prob" (and possibly others) not assigned a value in the execution with
"test_lda" function.
Error in mv_get_classifier_output (line 35)
        [~, ~, out] = test_fun(cf,Xtest);
Error in mv_classify (line 490)
            cf_output{1,1,ix{:}} = mv_get_classifier_output(cfg.output_type, cf, test_fun, Xtest_ix); 

It looks like the test_LDA function cannot compute the probability. I think because the code in mv_classify is failing to pass on the correct output_type. Although I can't quite figure it out. Would appreciate any insights!

@treder
Copy link
Owner

treder commented Sep 29, 2024

Hi @benjybarnett , the problem occurs because one of LDA hyperparameters (cfg.hyperparameter.prob = 1) needs to be set accordingly.

However, in this case it makes sense to actually adapt the default value for LDA, which I now included in mv_check_inputs. Your example should work now out of the box, can you please pull the latest changes and confirm?

@benjybarnett
Copy link
Author

Hi @treder thanks for looking into this! I see that I should have specified that now..however addressing that with my own cfg.hyperparameter.prob = 1 call or pulling the latest version just causes the following error to appear:

Unrecognized function or variable 'Sw'.
Error in train_lda (line 199)
    cf.Sw   = Sw;
Error in mv_classify (line 486)
        cf= train_fun(cfg.hyperparameter, X_ix, trainlabel); 

This is following the same code snippet as before. Cheers!

@treder
Copy link
Owner

treder commented Oct 1, 2024

I see - I think you have more features than samples right? The problem is that by default LDA chooses the dual form of the solution which has no covariance matrix (but it's needed for the probability calculation). So you would also have to set cfg.hyperparameter.form = 'primal' (the default is auto). Again I changed the default settings in the toolbox so if you pull again you shouldn't need to set this manually (hope it works this time round)

@benjybarnett
Copy link
Author

ah - thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants