当前位置: 首页>>代码示例>>Python>>正文


Python GaussianNB.theta_[1]方法代码示例

本文整理汇总了Python中sklearn.naive_bayes.GaussianNB.theta_[1]方法的典型用法代码示例。如果您正苦于以下问题:Python GaussianNB.theta_[1]方法的具体用法?Python GaussianNB.theta_[1]怎么用?Python GaussianNB.theta_[1]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.naive_bayes.GaussianNB的用法示例。


在下文中一共展示了GaussianNB.theta_[1]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GaussianNB

# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import theta_[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
开发者ID:poldrack,项目名称:semantic-image-comparison,代码行数:31,代码来源:4.naive_bayes_prediction.py


注:本文中的sklearn.naive_bayes.GaussianNB.theta_[1]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。