2012-03-25 35 views
6

Puanların sınıflandırılması için C# 'daki Gaussian Naive Bayes'i uygulamaya çalışıyorum. İlk bölüm (http://www.statsoft.com/textbook/naive-bayes-classifier/) olasılık parçası uygulanan var, ama ben Gaussian Naive Bayes algoritması normal modelinin nasıl uygulanacağını anlamıyorum. Bu benim kodudur: Bu pdf dosyasındaGaussian Naive Bayes'i Uygulayın

class NaiveBayesClassifier 
    { 
     private List<Point> listTrainPoints = new List<Point>(); 
     private int totalPoints = 0; 

     public NaiveBayesClassifier(List<Point> listTrainPoints) 
     { 
      this.listTrainPoints = listTrainPoints; 
      this.totalPoints = this.listTrainPoints.Count; 
     } 

     private List<Point> vecinityPoints(Point p, double maxDist) 
     { 
      List<Point> listVecinityPoints = new List<Point>(); 
      for (int i = 0; i < listTrainPoints.Count; i++) 
      { 
       if (p.distance(listTrainPoints[i]) <= maxDist) 
       { 
        listVecinityPoints.Add(listTrainPoints[i]); 
       } 
      } 
      return listVecinityPoints; 
     } 

     public double priorProbabilityFor(double currentType) 
     { 
      double countCurrentType = 0; 
      for (int i = 0; i < this.listTrainPoints.Count; i++) 
      { 
       if (this.listTrainPoints[i].Type == currentType) 
       { 
        countCurrentType++; 
       } 
      } 

      return (countCurrentType/this.totalPoints); 
     } 

     public double likelihoodOfXGiven(double currentType, List<Point> listVecinityPoints) 
     { 
      double countCurrentType = 0; 
      for (int i = 0; i < 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<Point> 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 > posteriorProbabilityXBeingType2) 
       return type1; 
      else 
       return type2; 
     } 
    } 

(Problem 5) i (http://romanager.ro/s.10-701.hw1.sol.pdf) yapmanız gerekenler açıklamasıdır. Benim çalışmam Gaussina Naive Bayes ve kNN algoritmalarını uygulamak ve sonucu bir dizi veriyle karşılaştırmak. Lütfen bana Gaussian Naive Bayes algoritmasının nerede ve nasıl uygulanacağını öğretin.

Teşekkürler! Burada

+0

kimse bana yardımcı olabilir? :( – Urmelinho

+0

Urmelinho: Bir ödül teklif edin ve birileri, bazı fikirler için :-) –

+0

yardımcı olabilir, bence birinden benden istediğini sanmıyorum ... algoritmanın bu kısmı için tamamen dışarıdayım. Çözüm için verdiğiniz ödülün size verileceğini düşünebilirsiniz. Herhangi bir tavsiyeyi bir çözüm olarak düşüneceğim: D – Urmelinho

cevap