Skip to content

Instantly share code, notes, and snippets.

View lizuyao2010's full-sized avatar

Zuyao Li lizuyao2010

View GitHub Profile
test
#Author: Krishnamurthy Koduvayur Viswanathan
from __future__ import division
import collections
import math
class Model:
def __init__(self, arffFile):
self.trainingFile = arffFile
self.features = {} #all feature names and their possible values (including the class label)
#include <stdio.h>
void do_cal(char str[],int n,int p);
int main()
{
char str[6];
int n,i,t,r[125];
while(scanf("%s%d",str,&n)==2)
{
for(i=0;str[i]!='.';i++);
t=(5-i)*n;
def Classify(self, featureVector): #featureVector is a simple list like the ones that we use to train
probabilityPerLabel = {} #store the final probability for each class label
for label in self.labelCounts:
logProb = 0
for featureValue in featureVector:
logProb += math.log(self.featureCounts[(label, self.featureNameList[featureVector.index(featureValue)], featureValue)]/self.labelCounts[label])
probabilityPerLabel[label] = (self.labelCounts[label]/sum(self.labelCounts.values())) * math.exp(logProb)
print probabilityPerLabel
return max(probabilityPerLabel, key = lambda classLabel: probabilityPerLabel[classLabel])