Python GridSearchCV的培训数据给了我ValueError,Sci工具包学习

Python GridSearchCV的培训数据给了我ValueError,Sci工具包学习,python,machine-learning,scikit-learn,Python,Machine Learning,Scikit Learn,我已经为PCA和SVC创建了一个管道,然后将数据拆分为训练集和测试集 dataset name = faces faces.data = independent variables faces.target = dependent variable from sklearn.svm import SVC from sklearn.decomposition import PCA from sklearn.pipeline import make_pipeline pca = PCA(n_

我已经为PCA和SVC创建了一个管道,然后将数据拆分为训练集和测试集

dataset name = faces

faces.data = independent variables

faces.target = dependent variable

from sklearn.svm import SVC
from sklearn.decomposition import PCA
from sklearn.pipeline import make_pipeline

pca = PCA(n_components=150, whiten=True, random_state=42)
svc = SVC(kernel="rbf", class_weight="balanced")
model = make_pipeline(pca, svc)

# spliting data from faces dataset. data is x and target is y
from sklearn.model_selection import train_test_split
Xtrain, Xtest, ytrain, ytest = train_test_split(faces.data, faces.target, random_state=42)
在经过PCA和SVC之后,当我尝试使用GridSearchCV训练数据时,它给出了一个错误,上面写着“ValueError:估计器管道的参数SVC_C无效”


有什么建议吗?

我的打赌您的参数应该包括双十一点,如:

# explore combinations of paramters
from sklearn.model_selection import GridSearchCV

param_grid = {'svc_C':[1,5,10,50],
             'svc_gamma':[0.0001, 0.0005, 0.001, 0.005]}
# instantiate grid of GridSearchCV class
# model uses pca to extract meaningful features then svc to find support vector

grid = GridSearchCV(model, param_grid)

grid.fit(Xtrain,ytrain)

你在哪里调用管道的fit函数?@SergeyBushmanov肯定忘记了,对此表示抱歉和感谢。哦。。。我懂了。它使用双下划线,但您能解释为什么吗?某些参数的名称中有下划线。通过添加两个下划线,可以在管道中的步骤名称和它们的参数名称之间进行清晰的分隔
param_grid = {'svc__C':[1,5,10,50],
             'svc__gamma':[0.0001, 0.0005, 0.001, 0.005]}