【问题标题】:how to speed up training process如何加快训练过程
【发布时间】:2016-05-09 22:16:37
【问题描述】:

我正在使用sklearn训练一个分类模型,数据形状和训练管道是:

clf = Pipeline([
    ("imputer", Imputer(missing_values='NaN', strategy="mean", axis=0)),
    ('feature_selection', VarianceThreshold(threshold=(.97 * (1 - .97)))),
    ('scaler', StandardScaler()),
    ('classification', svm.SVC(kernel='linear', C=1))])

print X.shape, y.shape
(59381, 895) (59381,)

我检查了feature_selection 会将特征向量大小从895 减少到124

feature_selection = Pipeline([
    ("imputer", Imputer(missing_values='NaN', strategy="mean", axis=0)),
    ('feature_selection', VarianceThreshold(threshold=(.97 * (1 - .97))))
    ])

feature_selection.fit_transform(X).shape
(59381, 124) (59381,)

然后我尝试如下获得准确性

scores = cross_validation.cross_val_score(clf, X, y)
print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))

但是训练过程很慢,我想知道在这种情况下加快过程?还是124 的特征向量大小对svm 模型来说还是太大了?

【问题讨论】:

    标签: machine-learning scikit-learn svm libsvm


    【解决方案1】:

    尝试使用sklearn.svm.LinearSVC

    假设给出的结果与svm.SVC(kernel='linear') 非常相似,但训练过程会更快(至少在d<m 时,当训练样本的 d 特征维度和 m 大小时)。

    如果你想使用其他内核,比如rbf,你不能使用LinearSVC

    但是,您可以添加内核缓存大小:内核缓存的大小对较大问题的运行时间有很大影响。如果您有足够的可用 RAM,建议将cache_size 设置为高于默认值 200(MB) 的值,例如 500(MB) 或 1000(MB)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      相关资源
      最近更新 更多