zoukankan      html  css  js  c++  java
  • #关于 OneVsRestClassifier(LogisticRegression(太慢了,要用超过的机器)

    #关于 OneVsRestClassifier
    #注意以下代码中,有三个类
    from sklearn import datasets
    X, y = datasets.make_classification(n_samples=10000, n_classes=3)
    from sklearn.tree import DecisionTreeClassifier
    dt = DecisionTreeClassifier()
    dt.fit(X, y)
    print(dt.predict(X))
    print ("Accuracy:	", (y == dt.predict(X)).mean())
    
    #利用 OneVsRestClassifier,进行分类
    #它好像是个外壳,还是利用里面的分类器进行分类
    #只不过加快了速度(并行)
    
    from sklearn.multiclass import OneVsRestClassifier
    from sklearn.linear_model import LogisticRegression
    '''
    Now, we'll override the LogisticRegression classifier.
    Also, notice that we can parallelize this.
    If we think about how OneVsRestClassifier works,
    it's just training separate models and then comparing them.
    So, we can train the data separately at the same time:
    '''
    #LogisticRegression 速度很慢
    mlr = OneVsRestClassifier(LogisticRegression(), n_jobs=2)
    mlr.fit(X, y)
    print(mlr.predict(X))
    print ("Accuracy:	", (y == mlr.predict(X)).mean())
  • 相关阅读:
    如何绕过chrome的弹窗拦截机制
    自我介绍
    注册页面的编写
    Roadmap学习目标
    Position
    poj2506 Tiling
    poj3278 Catch That Cow
    poj3624 Charm Bracelet
    钢条切割问题带你彻底理解动态规划
    poj1328 Radar Installation
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5343587.html
Copyright © 2011-2022 走看看