5 ms·
The actual translation of the formula to Python is about 4 lines. Starting on L30 - L34 of [1]. The rest is just IO plumbing. [1] https://gist.github.com/73141
by freyrs3 15y ago
The actual translation of the formula to Python is about 4 lines. Starting on L30 - L34 of [1]. The rest is just IO plumbing.
[1] https://gist.github.com/731413/7ad1b4c04bc2d6b5033c5811efcb4e92d017d3cf#L30 https://gist.github.com/731413/7ad1b4c04bc2d6b5033c5811efcb4... .
- deleted 15y ago[deleted]
- g___ 15y agoIn fact, first three lines could be written in one, although a longer one logProb = 0 for featureValue in featureVector: logProb += math.log(self.featureCounts[(label, self.featureNameList[featureVector.index(featureValue)], featureValue)]/self.labelCounts[label]) is better written with a comprehension: logProb = sum(math.log(self.featureCounts[(label, self.featureNameList[featureVector.index(featureValue)], featureValue)]/self.labelCounts[label]) for featureValue in featureVector) and split into 2 lines. In general the code is far from being Pythonic: fv[len(fv)-1] instead of fv[-1], with should be used instead of open/close, variable names are too long etc.