简体   繁体   中英

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.

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

any tips?

My bet your parameters should include double undescore like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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