How to use Gamma distribution as the kernel of Naive Bayes in MATLAB code?

Technical Source
2 min readMay 19, 2022

--

Here I have a group of data which following the Gamma distribution and now I want to use Naive Bayes method to fit this data. I tried the original function named ‘fitcnb’ and knowing that it providing 4 types of distribution: ‘box’, ‘epanechnikov’, ‘normal’ and ‘triangle’. Now I want to revise this fitcnb function through adding Gamma distribution kernel into its original code. But I’m not sure how to implement that, can anyone give me some hint or example code?

Many thanks for that.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

If your features follow a Gamma distribution you should be fine just using the ‘normal’ smoothing Kernel. To provide some intuition the Kernel prior is using a Kernel smoothing function to approximate the distribution of the features from the discrete data. You can think of it as trying to drop a table-cloth over the histogram to smooth out the jumps the histogram creates.

To illustrate this, let’s sample from a Gamma distribution

dataSamp = gamrnd(9,0.5,1e5,1); % Gamma Samples.
histogram(dataSamp,'Normalization','pdf') % Visualize pdf

Fit a Kernel distribution (tablecloth) with the restriction that the support is positive (as is the case with the Gamma distribution).

dist = fitdist(dataSamp,'kernel','Kernel','normal','Support','positive');

Evaluate the pdf of the distribution and plot on the histogram

xVals = linspace(0,15,1000); % x Values to evaluate the pdf
yFit = pdf(dist,xVals); % pdf values at each xVals
hold on
plot(xVals,yFit,'LineWidth',2) % Plot the fitted pdf.
hold off

This is exactly what is happening in fitcnb when you use the same calls

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet