码迷,mamicode.com
首页 > 其他好文 > 详细

#关于 OneVsRestClassifier(LogisticRegression(太慢了,要用超过的机器)

时间:2016-04-01 09:06:23      阅读:401      评论:0      收藏:0      [点我收藏+]

标签:

#关于 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:\t", (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:\t", (y == mlr.predict(X)).mean())

 

#关于 OneVsRestClassifier(LogisticRegression(太慢了,要用超过的机器)

标签:

原文地址:http://www.cnblogs.com/qqhfeng/p/5343587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!