简体   繁体   English

GridSearchCV训练数据给我ValueError,Sci-kit学习

[英]training data with GridSearchCV gives me ValueError, Sci-kit learn

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)

I've created a pipeline for PCA and SVC then split data into training set and testing set. 我已经为PCA和SVC创建了一个管道,然后将数据分为训练集和测试集。

# 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)

When I try to train data using GridSearchCV after going through PCA and SVC it gives me an error that says "ValueError: Invalid parameter svc_C for estimator Pipeline" 当我尝试通过PCA和SVC后使用GridSearchCV训练数据时,它给我一个错误,提示"ValueError: Invalid parameter svc_C for estimator Pipeline"

any tips? 有小费吗?

My bet your parameters should include double undescore like: 我敢打赌,您的参数应该包括double undescore,例如:

param_grid = {'svc__C':[1,5,10,50],
             'svc__gamma':[0.0001, 0.0005, 0.001, 0.005]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM