Machine Learning机器学习 - Supervised Learning监督学习 - Native Bayes

理论篇 Bayes Theorem

  1. 在维基百科上Bayes Theorem的解释已经很全面,特别是Drug Testing那段挺精彩,是Bayes Theorem理解的核心。
  2. 参考文章数学之美番外篇:平凡而又神奇的贝叶斯方法中文】,有更精彩的描述。
  3. 上篇文章中提到的这篇文章How to Write a Spelling Corrector也很有启发。

实现篇 Python - 调用scikit Native Bayes库函数

def NBAccuracy(features_train, labels_train, features_test, labels_test):
    """ compute the accuracy of your Naive Bayes classifier """
    ### import the sklearn module for GaussianNB
    from sklearn.naive_bayes import GaussianNB

    ### create classifier
    clf = GaussianNB()

    ### fit the classifier on the training features and labels
    clf.fit(features_train, labels_train)

    ### use the trained classifier to predict labels for the test features
    pred = clf.predict(features_test)

    ### calculate and return the accuracy on the test data
    from sklearn.metrics import accuracy_score
    accuracy = accuracy_score(labels_test, pred)
    return accuracy
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值