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


Python MultinomialNB.fit_semi方法代码示例

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


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

示例1: _test_semi

# 需要导入模块: from sklearn.naive_bayes import MultinomialNB [as 别名]
# 或者: from sklearn.naive_bayes.MultinomialNB import fit_semi [as 别名]
def _test_semi(NaiveBayes):


    clf = MultinomialNB(alpha=.01)
    clf.fit(X_train, y_train)
    # clf.fit(X_train[:n], Y_train[:n])
    pred = clf.predict(X_test)
    f1_score = metrics.f1_score(y_test, pred)
    print "Supervised Learning - scikits-learn 0.10"
    # print "Accuracy: %d/%d" % (np.sum(pred == y_test), len(y_test))
    accuracy =  float( np.sum(pred == y_test) )  / float(len(y_test))
    print "Accuracy: %0.4f" % accuracy
    print "F1: %0.4f" % f1_score


    clf = NaiveBayes()
    clf.fit(X_train, y_train)
    # clf.fit(X_train[:n], Y_train[:n])
    pred = clf.predict(X_test)
    f1_score = metrics.f1_score(y_test, pred)
    print "Supervised Learning"
    # print "Accuracy: %d/%d" % (np.sum(pred == y_test), len(y_test))
    accuracy =  float( np.sum(pred == y_test) )  / float(len(y_test))
    print "Accuracy: %0.4f" % accuracy
    print "F1: %0.4f" % f1_score

    clf = NaiveBayes()
    clf.fit_semi(X_train, Y_train, X_unlabel)
    # clf.fit_semi(X_train[:n], Y_train[:n], X_train[n:])
    pred = clf.predict(X_test)
    f1_score = metrics.f1_score(y_test, pred)
    accuracy =  float( np.sum(pred == y_test) )  / float(len(y_test))
    print "Semi-Supervised Learning"
    print "Accuracy: %0.4f" % accuracy
    print "F1: %0.4f" % f1_score
        
    print "-----"
开发者ID:YuanhaoSun,项目名称:PPLearn,代码行数:39,代码来源:18_semiNB_apply.py


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