本文整理汇总了Python中sklearn.naive_bayes.MultinomialNB.get_params方法的典型用法代码示例。如果您正苦于以下问题:Python MultinomialNB.get_params方法的具体用法?Python MultinomialNB.get_params怎么用?Python MultinomialNB.get_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.naive_bayes.MultinomialNB
的用法示例。
在下文中一共展示了MultinomialNB.get_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: multinomialNB
# 需要导入模块: from sklearn.naive_bayes import MultinomialNB [as 别名]
# 或者: from sklearn.naive_bayes.MultinomialNB import get_params [as 别名]
def multinomialNB(devMatrix, trainMatrix, devtarget, traintarget):
f = open('MNNB2.log', 'a')
f.write("Making model!!!!!")
print 'Making model!'
clf = MultinomialNB(alpha=1, fit_prior=False)
clf.fit(trainMatrix, traintarget)
f.write("\n")
value = ('Model: multinomial bayes with parameters ',clf.get_params(False))
print (str(value))
f.write(str(value))
f.write("\n")
f.write("MSE for train: %.2f" % np.mean((clf.predict(trainMatrix) - traintarget) ** 2))
score = clf.score(trainMatrix, traintarget)
f.write("\n")
value = ('Score for train %.2f', score)
f.write("\n")
f.write("MSE for dev: %.2f" % np.mean((clf.predict(devMatrix) - devtarget) ** 2))
score = clf.score(devMatrix, devtarget)
value = ('Score for dev %.2f', score)
print(str(value))
f.write("\n")
s = str(value)
f.write(s)
f.write("\n")
f.write('model done')
f.write("\n")
f.write("\n")
f.close()
return score
示例2: len
# 需要导入模块: from sklearn.naive_bayes import MultinomialNB [as 别名]
# 或者: from sklearn.naive_bayes.MultinomialNB import get_params [as 别名]
#check consistency of number of samples
#print len(Xtrain)
#print len(ytrain)
#time.sleep(10)
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
clf.fit(Xtrain, ytrain)
#get the probabilities:
print 'PredictionProbabilities (first 10)'
probas = clf.predict_proba(Xtest)
print probas[0:10,1]
print 'Parameters: '
parametros = clf.get_params()
print parametros
my_prediction = [] # will be zero or one depending on probability
# but, we will change the decision boundary
for k in range(len(ytest)):
if probas[k,0]>0.95:
my_prediction.append(0)
else:
my_prediction.append(1)
#prediction = clf.predict(Xtest) #the prediction of the non-modified Modell
prediction = my_prediction
total = len(prediction)
tn = 0
tp = 0
fp = 0
fn = 0