zoukankan      html  css  js  c++  java
  • 【Udacity】朴素贝叶斯

    • 机器学习就像酿制葡萄酒——好的葡萄(数据)+好的酿酒方法(机器学习算法)

    • 监督分类 supervised classification

    • Features ——>Labels

    • 保留10%的数据作为测试数据集

    监督学习之朴素贝叶斯 Naive Bayes——寻找决策面
    scikit-learn使用入门

    googlesearch sklearn+Naive Bayes

    关于sklearn版本
    • 视频——基于v0.17
    • 项目——基于v0.18

    sklearn的现在稳定版为0.18,官方文档也升级到了0.18。但是,0.18版并不兼容0.17的代码。如果你安装了0.18版,sklearn.cross_validation, sklearn.grid_search and sklearn.learning_curve 等方法都不能直接调用。

    新的API调用方法是

    from sklearn.model_selection import train_test_split

    计算准确度
    def NB_Accuracy(features_train, labels_train, features_test, labels_test):
        
        ### 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
        ### this is slightly different than the example, 
        ### where we just print the accuracy
        ### you might need to import an sklearn module
    
        ### Method #1:
        accuracy = clf.score(features_test, labels_test)
        return accuracy
        ### Method #2:
        from sklearn.metrics import accuracy_score
        print accuracy_score(pred, labels_test)
    
  • 相关阅读:
    AspNetPager.dll 分页控件使用方法、含有代码示例 [转]
    XmlDocument序列化到Session[转]
    静态构造函数
    错误日志[常用方法]
    Vss 源代码管理中的目录问题
    StopWatch 获得更精确的运行时间
    最近写的一个验证码.
    windowsservice 中的 currentdirectory
    vs2005常用快捷键(转贴)
    一个mapyEasy 图片切割工具 及源码
  • 原文地址:https://www.cnblogs.com/Neo007/p/7594429.html
Copyright © 2011-2022 走看看