Skip to content

feat: Add getters for naive bayes structs #74

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

Merged
merged 11 commits into from
Feb 25, 2021

Conversation

morenol
Copy link
Collaborator

@morenol morenol commented Jan 22, 2021

This is related to #73:

Things that are done in this PR

  • Add a getter equivalent to the scikitlearn attributes of the GaussianNB class for classes_, class_prior_, var_, and theta_.
  • Rename sigma to var, in order to have a similar naming that in scikitlearn (sigma is deprecated)

@morenol morenol force-pushed the lmm/naive_bayes_getters branch from 823dee3 to 64548dc Compare January 22, 2021 23:50
@codecov-io
Copy link

codecov-io commented Jan 22, 2021

Codecov Report

Merging #74 (aa4c144) into development (bd5fbb6) will increase coverage by 0.05%.
The diff coverage is 93.05%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development      #74      +/-   ##
===============================================
+ Coverage        83.77%   83.83%   +0.05%     
===============================================
  Files               75       75              
  Lines             7803     7850      +47     
===============================================
+ Hits              6537     6581      +44     
- Misses            1266     1269       +3     
Impacted Files Coverage Δ
src/naive_bayes/categorical.rs 76.51% <66.66%> (-0.23%) ⬇️
src/naive_bayes/bernoulli.rs 71.42% <92.30%> (+1.42%) ⬆️
src/naive_bayes/gaussian.rs 85.18% <93.10%> (+0.97%) ⬆️
src/naive_bayes/multinomial.rs 75.63% <96.29%> (+4.49%) ⬆️
src/svm/svc.rs 89.93% <0.00%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd5fbb6...aa4c144. Read the comment docs.

@morenol morenol force-pushed the lmm/naive_bayes_getters branch 2 times, most recently from 30086a5 to 06fda75 Compare January 23, 2021 19:39
@VolodymyrOrlov
Copy link
Collaborator

Hi @morenol. Is this PR still a work in progress or I can review it?

@morenol
Copy link
Collaborator Author

morenol commented Jan 26, 2021

Hi @morenol. Is this PR still a work in progress or I can review it?

Hi, @VolodymyrOrlov this is still a work in progress. I'll let you know when this is ready to review

@@ -223,6 +219,30 @@ impl<T: RealNumber, M: Matrix<T>> GaussianNB<T, M> {
pub fn predict(&self, x: &M) -> Result<M::RowVector, Failed> {
self.inner.predict(x)
}

Copy link
Collaborator Author

@morenol morenol Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -266,6 +266,12 @@ impl<T: RealNumber, M: Matrix<T>> BernoulliNB<T, M> {
self.inner.predict(x)
}
}

/// Class labels known to the classifier.
Copy link
Collaborator Author

@morenol morenol Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -240,6 +243,18 @@ impl<T: RealNumber, M: Matrix<T>> MultinomialNB<T, M> {
pub fn predict(&self, x: &M) -> Result<M::RowVector, Failed> {
self.inner.predict(x)
}

Copy link
Collaborator Author

@morenol morenol Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Class labels known to the classifier.
/// Returns a vector of size n_classes.
pub fn classes(&self) -> &Vec<T> {
&self.inner.distribution.class_labels
Copy link
Collaborator Author

@morenol morenol Jan 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morenol morenol force-pushed the lmm/naive_bayes_getters branch 4 times, most recently from b81111d to ed1511c Compare February 1, 2021 00:18
@morenol morenol force-pushed the lmm/naive_bayes_getters branch from ed1511c to ecf2b44 Compare February 15, 2021 01:32
@morenol
Copy link
Collaborator Author

morenol commented Feb 15, 2021

@VolodymyrOrlov Could you kindly review this now? I implemented most of the getters from scikit where we don't need to do extra computations and just access internal data from the structs. For instance, Right now we are storing the class_priors as a probability and in order to get class_log_prior_ we will need to compute the ln of each probability, should we compute that on runtime or store them too in the internal structure? or just ignore those getters for now?

@morenol morenol force-pushed the lmm/naive_bayes_getters branch from 4d0fb24 to ae3e3ee Compare February 15, 2021 02:39
@morenol morenol changed the title [WIP] feat: Add getters for naive bayes structs feat: Add getters for naive bayes structs Feb 15, 2021
VolodymyrOrlov
VolodymyrOrlov previously approved these changes Feb 16, 2021
Copy link
Collaborator

@VolodymyrOrlov VolodymyrOrlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@VolodymyrOrlov
Copy link
Collaborator

@VolodymyrOrlov Could you kindly review this now? I implemented most of the getters from scikit where we don't need to do extra computations and just access internal data from the structs. For instance, Right now we are storing the class_priors as a probability and in order to get class_log_prior_ we will need to compute the ln of each probability, should we compute that on runtime or store them too in the internal structure? or just ignore those getters for now?

Some users might find class_log_prior_ useful but most will likely not need it. We don't have to be 100% compatible with Scikit learn, especially when it comes to a minor convenience methods like the one that returns class probabilities. Besides, we can always add it later if someone requests it.

@morenol morenol merged commit 1b42f8a into smartcorelib:development Feb 25, 2021
@morenol morenol deleted the lmm/naive_bayes_getters branch February 25, 2021 19:45
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

Successfully merging this pull request may close these issues.

3 participants