SVM 训练时间太长

问题描述 投票:0回答:1

我有一个包含 41 个特征的数据集,其中 4 个是文本特征。我获得了这四个特征的“词袋”numpy 数组 (npz),我将其与其他数值特征结合起来训练 SVM 模型。总共有 100000 条记录和 41 个特征,其中 4 个特征如前所述进行了矢量化。

这个模型现在已经训练了 45 分钟:)。有没有办法减少训练时间?我预处理数据集的方式(特别是结合 npz 和现有的数值特征)有什么问题吗?我还可以探索其他选择吗?

title_feature = load_npz('train_title_bow.npz')
overview_feature = load_npz('train_overview_bow.npz')
tagline_feature = load_npz('train_tagline_bow.npz')
production_companies_feature = load_npz('train_production_companies_bow.npz')

numerical_features = df_train[df_train.columns.difference(['title', 'overview', 'tagline', 'production_companies', 'rate_category', 'average_rate', 'original_language'])]
text_features = np.hstack([title_feature.toarray(), overview_feature.toarray(), tagline_feature.toarray(), production_companies_feature.toarray()])
svm_X_train = np.hstack([numerical_features, text_features])
svm_y_train = df_train['rate_category']

svm_classifier = SVC(kernel='linear')  # Linear kernel is used, you can choose other kernels too
svm_classifier.fit(svm_X_train, svm_y_train)
python machine-learning svm
1个回答
0
投票

由于您正在学习线性模型,您可能需要使用 sklearn.svm.LinearSVC 来代替,它基于 liblinear 并且可以更快地学习。特别是,您可以设置底层求解器的迭代次数,从而以速度换取准确性。

© www.soinside.com 2019 - 2024. All rights reserved.