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 cell type decisions lead to np.AxisError in predict_labels_and_prob #17

Closed
chbeltz opened this issue Apr 18, 2022 · 6 comments
Closed

Comments

@chbeltz
Copy link

chbeltz commented Apr 18, 2022

When trying to make a binary cell type decision using CellTypist, I encountered an AxisError in line 131 of models.py, caused by scores.argmax(axis=1). When making binary decisions, sklearn's LogsticRegression.decision_function yields not an ndarray of shape (n_samples, n_classes) but of (n_samples,), making axis=1 and argmax in general problematic.

My suggested solution is first checking the number of dimensions in the output of decision_function and if it is equal to 1, as with binary decisions, emulating the output format expected by CellTypist, conserving the difference in confidence scores between the two available classes for every cell. This is implemented in #18.

@ChuanXu1
Copy link
Collaborator

@chbeltz, thx a lot!! will check and let you know soon.

@ChuanXu1
Copy link
Collaborator

@chbeltz , can I ask why you set the scores of the opposite class to all 0. As I understand, the emulated score matrix can be simply stacked by column-binding the -decision_function vector with the decision_function vector.

@chbeltz
Copy link
Author

chbeltz commented Apr 21, 2022

@ChuanXu1 Sure, it could. However I did not see any reason to believe that would be superior. In fact I did not see anything in the docs leading me to lean either way, seeing as the relative difference in certainty between predictions would remain the same.

Is there anything making your version preferable in your opinion?

@ChuanXu1
Copy link
Collaborator

ChuanXu1 commented Apr 22, 2022

@chbeltz, in a binary case, even with the 'ovr' mode, the classifier outputs the intercept and coefficients for the second class (.classes_[1]). For the first class, the decision score is not output, but it is actually the negative form of the score in the second class. Activated by the sigmoid further, the probability of the first class will be 1 - probability_of_2nd_class. If you turn the opposite to 0, you will get all probabilities of 0.5. Wdyt?

@ChuanXu1
Copy link
Collaborator

@chbeltz, I did not adopt your approach finally, but used the negative scores to make the sum of probabilities in binary cases to 1. Let me know how you think of it? Anyhow, thank you very much for raising the binary cases. cfb3b91

@chbeltz
Copy link
Author

chbeltz commented Apr 24, 2022

Ah, makes sense. Did not think of that. Thanks for the fix.

@chbeltz chbeltz closed this as completed Apr 24, 2022
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