smartcorelib / smartcore

A comprehensive library for machine learning and numerical computing. The library provides a set of tools for linear algebra, numerical computing, optimization, and enables a generic, powerful yet still efficient approach to machine learning.
https://smartcorelib.org/
Apache License 2.0
695 stars 76 forks source link

Naive Bayes (NB) Classifier #14

Closed VolodymyrOrlov closed 3 years ago

VolodymyrOrlov commented 3 years ago

Implement Base NB classifier that doesn't make any assumptions about the underlying distribution of x.

https://scikit-learn.org/stable/modules/naive_bayes.html

We need something like this (pseudocode):

trait NBDistribution:

    // Fit distribution to some continuous or discrete data
    def fit(x: Matrix<T>) -> NBDistribution

    // prior of class k 
    def prior(k) -> T

    // conditional probability of feature j give class k
    def conditional_probability(k, j)-> T

class BaseNaiveBayes:

    // "Fits" NB. This method validates and remembers parameters
    def fit(distribution: NBDistribution)

    // Calculates likelihood of labels using stored probabilities and X. Returns vector with estimated labels
    def predict(x: Matrix<T>) -> Vector<T>

Once we have BaseNaiveBayes we can implement Gaussian Naive Bayes, Multinomial Naive Bayes and Bernoulli Naive Bayes as concrete implementations of trait NBDistribution

morenol commented 3 years ago

Remaining NB classifiers to implement:

And also a partial_fit() for the cases where it makes sense, right? @VolodymyrOrlov

And also:

VolodymyrOrlov commented 3 years ago

@morenol can I close this issue, or would you like to keep it open until Complement Naive Bayes is implemented?

morenol commented 3 years ago

I think that we should close this when the documentation is already in the code.