Note that there are some explanatory texts on larger screens.

plurals
  1. POImplement Gaussian Naive Bayes
    primarykey
    data
    text
    <p>I'm trying to implement Gaussian Naive Bayes in C# for classification of points. I have implemented first part ( <a href="http://www.statsoft.com/textbook/naive-bayes-classifier/" rel="noreferrer">http://www.statsoft.com/textbook/naive-bayes-classifier/</a> ) probability part, but i don't understand how to implement Gaussian Naive Bayes algorithm normal model. This is my code:</p> <pre><code>class NaiveBayesClassifier { private List&lt;Point&gt; listTrainPoints = new List&lt;Point&gt;(); private int totalPoints = 0; public NaiveBayesClassifier(List&lt;Point&gt; listTrainPoints) { this.listTrainPoints = listTrainPoints; this.totalPoints = this.listTrainPoints.Count; } private List&lt;Point&gt; vecinityPoints(Point p, double maxDist) { List&lt;Point&gt; listVecinityPoints = new List&lt;Point&gt;(); for (int i = 0; i &lt; listTrainPoints.Count; i++) { if (p.distance(listTrainPoints[i]) &lt;= maxDist) { listVecinityPoints.Add(listTrainPoints[i]); } } return listVecinityPoints; } public double priorProbabilityFor(double currentType) { double countCurrentType = 0; for (int i = 0; i &lt; this.listTrainPoints.Count; i++) { if (this.listTrainPoints[i].Type == currentType) { countCurrentType++; } } return (countCurrentType / this.totalPoints); } public double likelihoodOfXGiven(double currentType, List&lt;Point&gt; listVecinityPoints) { double countCurrentType = 0; for (int i = 0; i &lt; listVecinityPoints.Count; i++) { if (listVecinityPoints[i].Type == currentType) { countCurrentType++; } } return (countCurrentType / this.totalPoints); } public double posteriorProbabilityXBeing(double priorProbabilityFor, double likelihoodOfXGiven) { return (priorProbabilityFor * likelihoodOfXGiven); } public int allegedClass(Point p, double maxDist) { int type1 = 1, type2 = 2; List&lt;Point&gt; listVecinityPoints = this.vecinityPoints(p, maxDist); double priorProbabilityForType1 = this.priorProbabilityFor(type1); double priorProbabilityForType2 = this.priorProbabilityFor(type2); double likelihoodOfXGivenType1 = likelihoodOfXGiven(type1, listVecinityPoints); double likelihoodOfXGivenType2 = likelihoodOfXGiven(type2, listVecinityPoints); double posteriorProbabilityXBeingType1 = posteriorProbabilityXBeing(priorProbabilityForType1, likelihoodOfXGivenType1); double posteriorProbabilityXBeingType2 = posteriorProbabilityXBeing(priorProbabilityForType2, likelihoodOfXGivenType2); if (posteriorProbabilityXBeingType1 &gt; posteriorProbabilityXBeingType2) return type1; else return type2; } } </code></pre> <p>In this pdf file (Problem 5) is the description of what i need to do ( <a href="http://romanager.ro/s.10-701.hw1.sol.pdf" rel="noreferrer">http://romanager.ro/s.10-701.hw1.sol.pdf</a> ). My work is to implement Gaussina Naive Bayes and kNN algorithms and compare the result on a set of data. Please teach me where and how to implement Gaussian Naive Bayes algorithm.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload