【问题标题】:RFECV for feature selection for LogisticRegression, AdaBoostClassifier, RandomForestClassifier is taking too long用于 LogisticRegression、AdaBoostClassifier、RandomForestClassifier 的特征选择的 RFECV 花费的时间太长
【发布时间】:2021-06-14 13:43:49
【问题描述】:

我正在尝试使用 RFECV 来选择不同机器学习算法的特征,但耗时太长。代码运行了几个小时并且没有给出任何输出..

enter image description here

这是我的代码:

# Feature selection by RFECV
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import RandomForestClassifier

estimator = AdaBoostClassifier(random_state=0)
selector = RFECV(estimator, step=1, cv=5)
selector = selector.fit(features, popular)
selector.ranking_

#estimator_LR = LogisticRegression(random_state=0)
estimator_LR = LogisticRegression(C=1.0, tol=0.01, random_state=0, max_iter=10000)
selector_LR = RFECV(estimator_LR, step=1, cv=5)
selector_LR = selector_LR.fit(features, popular)
selector_LR.ranking_

estimator_RF = RandomForestClassifier(random_state=0)
selector_RF = RFECV(estimator_RF, step=1, cv=5)
selector_RF = selector_RF.fit(features, popular)
selector_RF.ranking_

我尝试一次运行 1 行代码,但代码卡在所有三个分类器的 selector.fit 行上。

selector_RF = selector_RF.fit(features, popular)

我的数据集包含近 35000 个实例和 60 个属性。

【问题讨论】:

  • 你说你的代码卡住了,你得到什么样的错误?
  • 我的意思是代码处于运行模式,没有给出任何输出。

标签: python machine-learning scikit-learn


【解决方案1】:

我认为您应该进行这些更改以使 RFECV 更快:

selector = RFECV(estimator, step=1, cv=5, n_jobs = -1)

estimator_RF = RandomForestClassifier(random_state=0, n_jobs = -1)

max_iter = 10000 太过分了,

estimator_LR = LogisticRegression(C=1.0, tol=0.01, random_state=45, max_iter=100)

设置n_jobs = -1 参数会告诉你的模型使用你所有的cpu内核,从而使代码运行得更快。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 2011-12-06
    相关资源
    最近更新 更多