AttributeError: 'SVC' object has no attribute 'best_estimator_'

AttributeError: 'SVC' object has no attribute 'best_estimator_'

我正在尝试将 GridSearchCV 用于 SVM 线性,但出现此错误:

AttributeError: 'SVC' object has no attribute 'best_estimator_'

线性SVM的代码:

classifier = SVC()
classifier = GridSearchCV(classifier, {'C':[0.001, 0.01, 0.1, 1, 10,0.1, 100, 1000]}, cv=3, n_jobs=4)
classifier = SVC(kernel='linear')
classifier.fit(train_vectors, train_labels)
classifier = classifier.best_estimator_

有人可以帮忙吗?

这样做:

classifier = SVC(kernel='linear')
gridsearch = GridSearchCV(classifier, {'C':[0.001, 0.01, 0.1, 1, 10,0.1, 100, 1000]}, cv=3, n_jobs=4)
gridsearch.fit(train_vectors, train_labels)

best_params = gridsearch.best_params_
classifier = gridsearch.best_estimator_