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

Method fit

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

Source from the content-addressed store, hash-verified

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

Callers 1

bayes.pyFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected