我想用不同的参数给不同的分类器打分。在
对于LogisticRegression
的加速,我使用LogisticRegressionCV
(至少快2倍),并计划将GridSearchCV
用于其他人。在
但问题是它给了我相等的C
参数,而不是AUC ROC
评分。在
我将尝试修复许多参数,如scorer
、random_state
、solver
、max_iter
、tol
。。。
请看示例(真实数据无所谓):
试验数据及公用部分:
from sklearn import datasets
boston = datasets.load_boston()
X = boston.data
y = boston.target
y[y <= y.mean()] = 0; y[y > 0] = 1
import numpy as np
from sklearn.cross_validation import KFold
from sklearn.linear_model import LogisticRegression
from sklearn.grid_search import GridSearchCV
from sklearn.linear_model import LogisticRegressionCV
fold = KFold(len(y), n_folds=5, shuffle=True, random_state=777)
gs.best_score_: 0.939162082194
searchCV = LogisticRegressionCV(
Cs=list(np.power(10.0, np.arange(-10, 10)))
,penalty='l2'
,scoring='roc_auc'
,cv=fold
,random_state=777
,max_iter=10000
,fit_intercept=True
,solver='newton-cg'
,tol=10
)
searchCV.fit(X, y)
print ('Max auc_roc:', searchCV.scores_[1].max())
Max auc_roc: 0.970588235294
解算器newton-cg
仅用于提供固定值,其他人也尝试过。
我忘了什么?在
另外,在这两种情况下,我还收到警告“/usr/lib64/python3.4/site-packages/sklearn/utils”/优化。py:193:UserWarning:行搜索失败 警告。警告('Line Search failed')“我也不明白。如果有人能描述一下它的意思,我会很高兴,但我希望它与我的主要问题无关。在
通过@joeln注释添加max_iter=10000和tol=10个参数。它不改变任何数字的结果,但警告消失了。在
以下是scikit learn issue tracker上的answer by Tom副本:
LogisticRegressionCV.scores_
给出所有折叠的分数。GridSearchCV.best_score_
给出了所有折叠的最佳平均分数。在要获得相同的结果,您需要更改代码:
通过使用默认的
^{pr2}$tol=1e-4
而不是你的tol=10
,我得到:剩下的(小的)差别可能来自于
LogisticRegressionCV
的热启动(这实际上是它比GridSearchCV
更快的原因)。在相关问题 更多 >
编程相关推荐