gpt4 book ai didi

machine-learning - 如何加快训练过程

转载 作者:行者123 更新时间:2023-11-30 08:54:55 24 4
gpt4 key购买 nike

我正在使用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模型来说仍然太大?

最佳答案

尝试使用sklearn.svm.LinearSVC .

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

如果你想使用其他内核,例如 rbf ,您不能使用LinearSVC .

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

关于machine-learning - 如何加快训练过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35130939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com