MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / fit

Method fit

supervised_class/nb.py:18–28  ·  view source on GitHub ↗
(self, X, Y, smoothing=1e-2)

Source from the content-addressed store, hash-verified

16
17class NaiveBayes(object):
18 def fit(self, X, Y, smoothing=1e-2):
19 self.gaussians = dict()
20 self.priors = dict()
21 labels = set(Y)
22 for c in labels:
23 current_x = X[Y == c]
24 self.gaussians[c] = {
25 'mean': current_x.mean(axis=0),
26 'var': current_x.var(axis=0) + smoothing,
27 }
28 self.priors[c] = float(len(Y[Y == c])) / len(Y)
29
30 def score(self, X, Y):
31 P = self.predict(X)

Callers 1

nb.pyFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected