如何使多类分类的运行时间更快?
Posted
技术标签:
【中文标题】如何使多类分类的运行时间更快?【英文标题】:How can i make the run time of Multi-Class Classification faster? 【发布时间】:2019-10-24 21:51:18 【问题描述】:我正在尝试为随机森林和逻辑回归训练和运行多类分类器。到目前为止,在我的具有 8GB RAM 和 i5 内核的机器上,尽管数据大小几乎没有 34K 记录,但运行它需要相当长的时间。有什么方法可以通过调整一些参数来加快当前现有的运行时间?
我只是在下面给出一个逻辑回归随机搜索的例子。
X.shape
Out[9]: (34857, 18)
Y.shape
Out[10]: (34857,)
Y.unique()
Out[11]: array([7, 3, 8, 6, 1, 5, 9, 2, 4], dtype=int64)
params_logreg='C':[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0],
'solver':['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'],
'penalty':['l2'],
'max_iter':[100,200,300,400,500],
'multi_class':['multinomial']
folds = 2
n_iter = 2
scoring= 'accuracy'
n_jobs= 1
model_logregression=LogisticRegression()
model_logregression = RandomizedSearchCV(model_logregression,X,Y,params_logreg,folds,n_iter,scoring,n_jobs)
[CV] solver=newton-cg, penalty=l2, multi_class=multinomial, max_iter=100, C=0.9
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[CV] solver=newton-cg, penalty=l2, multi_class=multinomial, max_iter=100, C=0.9, score=0.5663798049340218, total= 2.7min
[CV] solver=newton-cg, penalty=l2, multi_class=multinomial, max_iter=100, C=0.9
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 2.7min remaining: 0.0s
[CV] solver=newton-cg, penalty=l2, multi_class=multinomial, max_iter=100, C=0.9, score=0.5663625408848338, total= 4.2min
[CV] solver=sag, penalty=l2, multi_class=multinomial, max_iter=400, C=0.8
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 7.0min remaining: 0.0s
[CV] solver=sag, penalty=l2, multi_class=multinomial, max_iter=400, C=0.8, score=0.5663798049340218, total= 33.9s
[CV] solver=sag, penalty=l2, multi_class=multinomial, max_iter=400, C=0.8
[CV] solver=sag, penalty=l2, multi_class=multinomial, max_iter=400, C=0.8, score=0.5664773053308085, total= 26.6s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 8.0min finished```
It's taking about 8 mins to run for Logistic Regression. In contrast RandomForestClassifier takes only about 52 seconds.
Is there any way in which I can make this run faster by tweaking the parameters?
【问题讨论】:
【参考方案1】:尝试为逻辑回归模型标准化您的数据。标准化数据将帮助模型快速收敛。 Scikit-learn 对此有多种方法,因此请查看其预处理部分以获取更多信息。
您还使用RandomizedSearchCV
进行回归,这需要时间,因为要创建和计算多个模型并进行比较以获得最佳参数。
【讨论】:
谢谢。这似乎是一个合乎逻辑的解释。还是使用 sklearn Normalizer 是最好的技术,或者我也可以使用 Standard scaler 或 Min Max scaler?上述两种技术是否也可行? 它们都是可用的选项,具体取决于数据和需求。根据您的数据对它们进行试验,以检查最适合的方法。以上是关于如何使多类分类的运行时间更快?的主要内容,如果未能解决你的问题,请参考以下文章