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


Python GaussianNB.sigma_[0]方法代码示例

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


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

示例1: GaussianNB

# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import sigma_[0] [as 别名]
    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
#42

predictions.to_csv("%s/prediction_concept_matrix.tsv" %results,sep="\t")
开发者ID:poldrack,项目名称:semantic-image-comparison,代码行数:32,代码来源:4.naive_bayes_prediction.py

示例2:

# 需要导入模块: from sklearn.naive_bayes import GaussianNB [as 别名]
# 或者: from sklearn.naive_bayes.GaussianNB import sigma_[0] [as 别名]
            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:
            print "Found %s positive examples!" %numpy.sum(Ytrain)
            predictions_forward.loc[heldout,concept] = 2

# Combining across all voxels and labels, you have a total of #voxels x # processes x 4 parameters

# Results:
# The results of this modified model will serve as a second baseline for further modifications. Thus, I suggest you save the cross-validation test results from this model.

predictions_forward.to_csv("%s/prediction_concept_matrix_forward.tsv" %results,sep="\t")
开发者ID:poldrack,项目名称:semantic-image-comparison,代码行数:33,代码来源:4.naive_bayes_decoding.py


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