本文整理汇总了Python中sklearn.naive_bayes.GaussianNB.predict_log_proba方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianNB.predict_log_proba方法的具体用法?Python GaussianNB.predict_log_proba怎么用?Python GaussianNB.predict_log_proba使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.naive_bayes.GaussianNB
的用法示例。
在下文中一共展示了GaussianNB.predict_log_proba方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: nb_predict
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
def nb_predict(clf,Xtest,cc):
# Classes returned in order 0,1
#clf.classes_: array([0, 1])
log0,log1 = GaussianNB.predict_log_proba(clf,Xtest)[0]
log_odds = log1 - log0
if log_odds > cc:
return 1
return 0
示例2: __init__
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
class NaiveBayes:
__theta = 0
__sigma = 0
def __init__(self):
pass
#self.__new_data = 0
def learning(self,x_data,y_data):
self.rssi = np.loadtxt(x_data, delimiter=',')
print(self.rssi)
self.position = np.loadtxt(y_data, delimiter=',')
print(self.position)
self.gaussian_nb = GaussianNB()
from sklearn.cross_validation import train_test_split
rssi_train, rssi_test, position_train, position_test = train_test_split(self.rssi, self.position, random_state=0)
self.gaussian_nb.fit(rssi_train,position_train)
print("theta",self.gaussian_nb.theta_)
print("sigma",self.gaussian_nb.sigma_)
predicted = self.gaussian_nb.predict(rssi_test)
print(metrics.accuracy_score(position_test, predicted))
'''
def set_params(self,theta,sigma):
__theta = theta
__sigma = sigma
print __theta
print __sigma
'''
def inference(self,r_data):
self.predicted_class = self.gaussian_nb.predict(r_data)
post_prob = self.gaussian_nb.predict_proba(r_data)
log_prob = self.gaussian_nb.predict_log_proba(r_data)
self.post_prob_float16 = post_prob.astype(np.float16)
#E = 1*self.post_prob_float16[0][0]+2*self.post_prob_float16[0][1]+3*self.post_prob_float16[0][2]
#var = (1*self.post_prob_float16[0][0]+4*self.post_prob_float16[0][1]+9*self.post_prob_float16[0][2])-E**2
#print(self.post_prob_float16)
#print(self.post_prob_float16[0])
#print(var)
print(self.predicted_class)
#print(self.gaussian_nb.class_prior_)
#print(log_prob)
return self.predicted_class
def output(self):
output = graph.Graph()
output.bar_graph(self.post_prob_float16[0])
示例3: test_gnb
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
def test_gnb():
"""
Gaussian Naive Bayes classification.
This checks that GaussianNB implements fit and predict and returns
correct values for a simple toy dataset.
"""
clf = GaussianNB()
y_pred = clf.fit(X, y).predict(X)
assert_array_equal(y_pred, y)
y_pred_proba = clf.predict_proba(X)
y_pred_log_proba = clf.predict_log_proba(X)
assert_array_almost_equal(np.log(y_pred_proba), y_pred_log_proba, 8)
示例4: test_gnb
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
def test_gnb():
# Gaussian Naive Bayes classification.
# This checks that GaussianNB implements fit and predict and returns
# correct values for a simple toy dataset.
clf = GaussianNB()
y_pred = clf.fit(X, y).predict(X)
assert_array_equal(y_pred, y)
y_pred_proba = clf.predict_proba(X)
y_pred_log_proba = clf.predict_log_proba(X)
assert_array_almost_equal(np.log(y_pred_proba), y_pred_log_proba, 8)
# Test whether label mismatch between target y and classes raises
# an Error
# FIXME Remove this test once the more general partial_fit tests are merged
assert_raises(ValueError, GaussianNB().partial_fit, X, y, classes=[0, 1])
示例5: range
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
for i in range(len(scans_testing)):
prediction = nb.predict(scans_testing[i])
if prediction == labels_testing[i]:
correct += 1
#print (correct / len(scans_testing)) * 100, "%"
total_correct += correct
total_scans += len(scans_testing)
else:
# 6: Classify per group
#print "Classifying using test data"
correct = 0
count = 0
sum_p = 0
sum_s = 0
for i in range(len(scans_testing)):
prediction = nb.predict_log_proba(scans_testing[i])
sum_p += prediction[0][0]
sum_s += prediction[0][1]
if i % 10 == 9:
group_prediction = 'P' if sum_p > sum_s else 'S'
sum_p = 0
sum_s = 0
count += 1
if group_prediction == labels_testing[i]:
correct += 1
#print (correct / count) * 100, "%"
total_correct += correct
total_scans += count
示例6: GaussianNB
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
n_samples)
y = np.zeros(3 * n_samples,)
y[n_samples:2 * n_samples] = 1
y[2 * n_samples:3 * n_samples, ] = 2
# Gaussain Naiv Bais
clf = GaussianNB()
clf.fit(X, y)
display_1 = [2, 2]
display_2 = [3, 1]
display_3 = [2.5, 2.5]
values_proba_gnb_1 = np.exp(clf.predict_log_proba(display_1))[0]
values_proba_gnb_2 = np.exp(clf.predict_log_proba(display_2))[0]
values_proba_gnb_3 = np.exp(clf.predict_log_proba(display_3))[0]
ig1_bis = plt.figure()
plot_2d(X, y)
resolution_param = 50 # 500 for nice plotting, 50 for fast version
color_text = '#ff8101'
frontiere(lambda xx: clf.predict(xx), X, step=resolution_param)
plt.annotate(r'' + '(%.2f' % values_proba_gnb_1[0] + ', %.2f'
% values_proba_gnb_1[1] + ', %.2f)' % values_proba_gnb_1[2],
xy=(display_1[0], display_1[1]), xycoords='data',
color =color_text, xytext=(-150, +100),
textcoords='offset points', fontsize=12,
示例7: GaussianNB
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
print "==Predict result by predict=="
print(clf.predict([[-0.8, -1]]))
print "==Predict result by predict_proba=="
print(clf.predict_proba([[-0.8, -1]]))
print "==Predict result by predict_log_proba=="
print(clf.predict_log_proba([[-0.8, -1]]))
示例8: GaussianNB
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import predict_log_proba [as 别名]
import numpy
from sklearn.naive_bayes import GaussianNB
__author__ = 'mkk'
if __name__ == "__main__":
nb = GaussianNB()
ctx1 = numpy.array([1,2,3,4,5,6,7,8,9,100])
ctx2 = numpy.array([1,2,3,4,5,16,7,18,9,100])
obs = numpy.array([0.1,5,5,5,5,15,5,15,5,115])
nb.fit(numpy.array([ctx1, ctx2]), [1,2])
print(nb.predict_log_proba(obs))