Method
fit
(self, X, Y, smoothing=1e-2)
Source from the content-addressed store, hash-verified
| 17 | |
| 18 | class 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) |
Tested by
no test coverage detected