BOBO老师您好,看了你的回复我尝试了SVR的网格搜索不知道哪里出错了:
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
boston = datasets.load_boston()
x = boston.data
y = boston.target
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.svm import SVR
def RBFKernelsvr(C=1,gamma=1.0):
return Pipeline([
("std_scaler",StandardScaler()),
("svc",SVR(kernel="rbf",gamma=gamma,C=C))
])
svr = RBFKernelsvr()
# 准备待搜索的参数列表
C_PARM = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8]
param_grid = [
{
'gamma': [i for i in C_PARM],
'C':[i for i in range(1, 11)]
}
]
from sklearn.model_selection import GridSearchCV
grid_search = GridSearchCV(svr, param_grid)
grid_search.fit(x,y)
print(grid_search.best_estimator_)
print(grid_search.best_params_)
svr0=grid_search.best_estimator_
print(svr0.score(x,y))