MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / predict_proba

Method predict_proba

bayesian_ml/1/nb.py:41–70  ·  view source on GitHub ↗
(self, X)

Source from the content-addressed store, hash-verified

39 self.tinfo.append(tinfo_c)
40
41 def predict_proba(self, X):
42 N, D = X.shape
43 # P = np.zeros(N)
44 # for n in xrange(N):
45 # x = X[n]
46
47 # pyx = []
48 # for c in (0, 1):
49 # pycx = self.pyy[c]
50 # for d in xrange(D):
51 # tinfo_cd = self.tinfo[c][d]
52 # pdf_d = t.pdf(x[d], df=tinfo_cd['df'], loc=tinfo_cd['center'], scale=tinfo_cd['scale'])
53 # pycx *= pdf_d
54 # pyx.append(pycx)
55
56 # py1x = pyx[1] / (pyx[0] + pyx[1])
57 # # print "p(y=1|x):", py1x
58 # P[n] = py1x
59
60 posteriors = np.zeros((N, 2))
61 for c in (0, 1):
62 probability_matrix = np.zeros((N, D))
63 for d in xrange(D):
64 tinfo_cd = self.tinfo[c][d]
65 pdf_d = t.pdf(X[:,d], df=tinfo_cd['df'], loc=tinfo_cd['center'], scale=tinfo_cd['scale'])
66 probability_matrix[:,d] = pdf_d
67 posteriors_c = np.prod(probability_matrix, axis=1)*self.pyy[c]
68 posteriors[:,c] = posteriors_c
69 P = posteriors[:,1] / np.sum(posteriors, axis=1)
70 return P
71
72 def predict(self, X):
73 return np.round(self.predict_proba(X))

Callers 8

predictMethod · 0.95
get_3_most_ambiguousMethod · 0.95
basic_mlp.pyFile · 0.45
sentiment.pyFile · 0.45
mainFunction · 0.45
mainFunction · 0.45
fitMethod · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected