Estimating joint density directly from the joint density table requires intensive computation, especially with large dataset.
To implement a Naive Bayes classifier in Matlab, two separate functions could be developed: nb_train and nb_test. The nb_train() function takes in training dataset x and y, with each row of x represents the feature vector of one training instance and the corresponding row in y contains the class label for that instance. The computed conditional probabilities matrices as well as class priors should be put together inside a model struct as the return value. Information retrieved from the model struct is applied on the testing data points to calculate the probability of belonging to each class. The class label is determined as the one with the highest probability. |
Logistic Regression classifier is a linear classifier, roughly of the form P(y|x,w) = sigmoid(x.w) (as compared to sign(x.w) in linear classifier).

where S() - the sigmoid function,theta - current logistic regression parameter,lambda - the regularization term.
The code implementation for this representation is straightforward.

The cost function is defined as follows:

The code implementation for this representation is straightforward.

Based on these helper functions implemented, the training phase could be simplified as:
1. randomly initialize theta
2. call minimize() on the cost function with the initial theta.
3. update theta the finally returned value from minimize()
The prediction function could hence be written as:










