本文整理汇总了Python中sklearn.naive_bayes.GaussianNB.sigma_[1]方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianNB.sigma_[1]方法的具体用法?Python GaussianNB.sigma_[1]怎么用?Python GaussianNB.sigma_[1]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.naive_bayes.GaussianNB
的用法示例。
在下文中一共展示了GaussianNB.sigma_[1]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GaussianNB
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import sigma_[1] [as 别名]
predictions = pandas.DataFrame(index=Xmat.index,columns=Ymat.columns)
only_positive_examples = 0
for concept in concepts:
print "Predicting images for %s" %concept
for heldout in Xmat.index.tolist():
clf = GaussianNB()
# The encoding model is given by X_{n,:} = Y{n,:} x W + b
Xtrain = X.loc[Xmat.index!=heldout,:]
Ytrain = Ymat.loc[Xtrain.index,concept].tolist()
clf.fit(Xtrain, Ytrain)
# b = average [X_{n,:} - Y{n,:}W]
b = (Xmat - Ymat.dot(W)).mean(axis=0)
# You should fix this to m1_{j, d} = W_{j, d} + b_{j}
if len(clf.theta_)==2:
clf.theta_[1] = W.loc[concept,:] + b
clf.sigma_[1] = numpy.ones(W.shape[1])
# You should fix this to m0_{j, d} = b_{j}
clf.theta_[0] = b
# with no other information, might as well fix this to s1_{j, d} = 1.0
clf.sigma_[0] = numpy.ones(W.shape[1])
Xtest = Xmat.loc[heldout,:]
Yhat = clf.predict(Xtest)[0]
predictions.loc[heldout,concept] = Yhat
# For 42/12,276, the Y vector is all 0s, so let's assign a value of 2,
# we will give no accuracy for this
else:
print "Found %s positive examples!" %numpy.sum(Ytrain)
only_positive_examples +=1
predictions.loc[heldout,concept] = 2
only_positive_examples
示例2: GaussianNB
# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import sigma_[1] [as 别名]
clf = GaussianNB()
Xtrain = Xmat.loc[Xmat.index!=heldout,:]
Ytrain = Ymat.loc[Xtrain.index,concept].tolist()
clf.fit(Xtrain, Ytrain)
# b = average [X_{n,:} - Y{n,:}W]
#b = (Xmat - Ymat.dot(W)).mean(axis=0)
# m1_{j, d}: This is the mean of the Gaussian for voxel = d, and process y_{:, j} =1
# You should fix this to m1_{j, d} = W_{j, d}
if len(clf.theta_)==2:
clf.theta_[1] = W.loc[concept,:]
# s1_{j, d}: This is the variance of the Gaussian for voxel = d, and process y_{:, j} =1
# We compute this as the variance of the error in the forward model.
# Using the training data, set index A = {n | Y[:, j] = 1}
A = Ymat.loc[Ymat[concept]==1,concept].index.tolist()
# Then s1_{j, d} = (X_{A, d} - W_{j, d}).var()
clf.sigma_[1] = (Xmat.loc[A,:] - W.loc[concept]).var()
# m0_{j, d}: This is the mean of the Gaussian for voxel = d, and process y_{:, j} =0
# You should fix this to m0_{j, d} = 0.0
clf.theta_[0] = 0
#s0_{j, d}: This is the variance of the Gaussian for voxel = d, and process y_{:, j} =0
# We compute this as the variance of the error in the forward model.
# Using the training data, set index B = {n | Y[:, j] = 0}
B = Ymat.loc[Ymat[concept]==0,concept].index.tolist()
# Then s0_{j, d} = (X_{B, d}).var()
clf.sigma_[0] = Xmat.loc[B,:].var()
Xtest = Xmat.loc[heldout,:]
Yhat = clf.predict(Xtest)[0]
predictions_forward.loc[heldout,concept] = Yhat
# For 42/12,276, the Y vector is all 0s, so let's assign a value of 2,
# we will give no accuracy for this
else: