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

Method fit

unsupervised_class2/gaussian_nb.py:19–29  ·  view source on GitHub ↗
(self, X, Y, smoothing=1e-2)

Source from the content-addressed store, hash-verified

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

Callers 1

gaussian_nb.pyFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected