gpt4 book ai didi

python - Scikit-learn 的带有线性内核 svm 的 GridSearchCV 花费的时间太长

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:27 28 4
gpt4 key购买 nike

我从 sklearn 网站上获取了示例代码,它是

tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4], 'C': [1, 10, 100, 1000]},
{'kernel': ['linear'], 'C': [1, 10, 100, 1000]}]

scores = [('f1', f1_score)]

for score_name, score_func in scores:
print "# Tuning hyper-parameters for %s" % score_name
print

clf = GridSearchCV( SVC(), tuned_parameters, score_func=score_func, n_jobs=-1, verbose=2 )
clf.fit(X_train, Y_train)

print "Best parameters set found on development set:"
print
print clf.best_estimator_
print
print "Grid scores on development set:"

print
for params, mean_score, scores in clf.grid_scores_:
print "%0.3f (+/-%0.03f) for %r" % (
mean_score, scores.std() / 2, params)
print

print "Detailed classification report:"
print
print "The model is trained on the full development set."
print "The scores are computed on the full evaluation set."
print
y_true, y_pred = Y_test, clf.predict(X_test)
print cross_validation.classification_report(y_true, y_pred)
print

X_train 是一个大约有 70 行的 pandas DataFrame。

输出是

[GridSearchCV] kernel=rbf, C=1, gamma=0.001 ....................................
[GridSearchCV] kernel=rbf, C=1, gamma=0.001 ....................................
[GridSearchCV] kernel=rbf, C=1, gamma=0.001 ....................................
[GridSearchCV] kernel=rbf, C=1, gamma=0.0001 ...................................
[Parallel(n_jobs=-1)]: Done 1 jobs | elapsed: 0.0s
[GridSearchCV] ........................... kernel=rbf, C=1, gamma=0.001 - 0.0s
[GridSearchCV] ........................... kernel=rbf, C=1, gamma=0.001 - 0.0s
[GridSearchCV] ........................... kernel=rbf, C=1, gamma=0.001 - 0.0s
[GridSearchCV] .......................... kernel=rbf, C=1, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=rbf, C=1, gamma=0.0001 ...................................
[GridSearchCV] kernel=rbf, C=1, gamma=0.0001 ...................................
[GridSearchCV] kernel=rbf, C=10, gamma=0.001 ...................................
[GridSearchCV] kernel=rbf, C=10, gamma=0.001 ...................................
[GridSearchCV] .......................... kernel=rbf, C=1, gamma=0.0001 - 0.0s
[GridSearchCV] .......................... kernel=rbf, C=1, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=rbf, C=10, gamma=0.001 ...................................
[GridSearchCV] .......................... kernel=rbf, C=10, gamma=0.001 - 0.0s
[GridSearchCV] .......................... kernel=rbf, C=10, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=10, gamma=0.0001 ..................................
[GridSearchCV] .......................... kernel=rbf, C=10, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=10, gamma=0.0001 ..................................
[GridSearchCV] kernel=rbf, C=10, gamma=0.0001 ..................................
[GridSearchCV] ......................... kernel=rbf, C=10, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=rbf, C=100, gamma=0.001 ..................................
[GridSearchCV] ......................... kernel=rbf, C=10, gamma=0.0001 - 0.0s
[GridSearchCV] ......................... kernel=rbf, C=10, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=rbf, C=100, gamma=0.001 ..................................
[GridSearchCV] ......................... kernel=rbf, C=100, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=100, gamma=0.001 ..................................
[GridSearchCV] kernel=rbf, C=100, gamma=0.0001 .................................
[GridSearchCV] ......................... kernel=rbf, C=100, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=100, gamma=0.0001 .................................
[GridSearchCV] ......................... kernel=rbf, C=100, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=100, gamma=0.0001 .................................
[GridSearchCV] kernel=rbf, C=1000, gamma=0.001 .................................
[GridSearchCV] ........................ kernel=rbf, C=100, gamma=0.0001 - 0.0s
[GridSearchCV] ........................ kernel=rbf, C=100, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=rbf, C=1000, gamma=0.001 .................................
[GridSearchCV] ........................ kernel=rbf, C=100, gamma=0.0001 - 0.0s
[GridSearchCV] ........................ kernel=rbf, C=1000, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=1000, gamma=0.001 .................................
[GridSearchCV] kernel=rbf, C=1000, gamma=0.0001 ................................
[GridSearchCV] kernel=rbf, C=1000, gamma=0.0001 ................................
[GridSearchCV] ........................ kernel=rbf, C=1000, gamma=0.001 - 0.0s
[GridSearchCV] kernel=rbf, C=1000, gamma=0.0001 ................................
[GridSearchCV] ........................ kernel=rbf, C=1000, gamma=0.001 - 0.0s
[GridSearchCV] ....................... kernel=rbf, C=1000, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=linear, C=1 ..............................................
[GridSearchCV] ....................... kernel=rbf, C=1000, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=linear, C=1 ..............................................
[GridSearchCV] kernel=linear, C=1 ..............................................
[GridSearchCV] ....................... kernel=rbf, C=1000, gamma=0.0001 - 0.0s
[GridSearchCV] kernel=linear, C=10 .............................................

然后它永远不会完成。我用 Lion 在 Mac Book Pro 上运行它。我做错了什么?

最佳答案

通过规范化数据集来修复它,如下所示:normalize-data-in-pandas , 在运行网格搜索之前。

关于python - Scikit-learn 的带有线性内核 svm 的 GridSearchCV 花费的时间太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12616492/

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