Fix #225: Improve Display for naive_bayes
Fixes #225
Checklist
- [x] My branch is up-to-date with development branch.
- [x] Everything works and tested on latest stable Rust.
- [x] Coverage and Linting have been applied
Current behaviour
Currently println!("{}", &gnb) prints:
GaussianNB:
inner: BaseNaiveBayes { distribution: GaussianNBDistribution { class_labels: [0, 1, 2], class_count: [50, 50, 50], class_priors: [0.3333333333333333, 0.3333333333333333, 0.3333333333333333], var: [[0.12176398698426993, 0.1422760001411465, 0.0295040034446723, 0.01126400058841702], [0.26110400788880384, 0.09650000076294418, 0.21639999752045114, 0.03832399889564586], [0.3962559386291673, 0.10192399745559833, 0.2984959836425922, 0.07392400431251556]], theta: [[5.006000003814697, 3.41800000667572, 1.4639999961853027, 0.24400000482797624], [5.935999975204468, 2.770000009536743, 4.259999980926514, 1.3259999918937684], [6.588000001907349, 2.9739999914169313, 5.551999988555909, 2.0259999775886537]] }, _phantom_tx: PhantomData, _phantom_ty: PhantomData, _phantom_x: PhantomData, _phantom_y: PhantomData }
New expected behaviour
GaussianNB:
inner: BaseNaiveBayes: {
distribution: GaussianNBDistribution: {
class_labels: [1, 2],
class_count: [3, 3],
class_priors: [0.3, 0.7],
var: [[0.666666666666667, 0.22222222222222232], [0.666666666666667, 0.22222222222222232]],
theta: [[-2.0, -1.3333333333333333], [2.0, 1.3333333333333333]]
}}
Change logs
I'm just starting to learn rust, so I'm sorry if I'm wrong. I implemented it differently from the format presented in https://github.com/smartcorelib/smartcore/issues/225 . Is it better to implement just like the example?
thanks a lot!
could you try to do the same for other structures that implement Display? Could you find a way to avoid printing the _phantom fields?
@Mec-iS I tried. Can you review it?
Good job.
This could be merged but it will fix only the Gaussian, what about the other distributions? Please double check that all of them return well formatted output.
EDIT: Also please test your branch with smartcore-jupyter by using:
:dep smartcore = {git = "https://github.com/m7142yosuke/smartcore.git", , branch = "feature/improve-display-for-naive-bayes", features = ["datasets"]}
at the top of the notebooks. These changes are meant mostly for Jupyter pretty printing so it would be good to have a look how the branch works in the notebooks. For example see this.
Codecov Report
Merging #241 (19e5115) into development (d15ea43) will increase coverage by
0.07%. The diff coverage is81.81%.
:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more
@@ Coverage Diff @@
## development #241 +/- ##
===============================================
+ Coverage 44.50% 44.58% +0.07%
===============================================
Files 85 85
Lines 7226 7234 +8
===============================================
+ Hits 3216 3225 +9
+ Misses 4010 4009 -1
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/naive_bayes/gaussian.rs | 42.30% <81.81%> (+6.89%) |
:arrow_up: |
... and 5 files with indirect coverage changes
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.