GridSearchCV
具体实例:
# -*- coding: utf-8 -*- """ Created on Mon Jun 15 15:30:30 2015 @author: Chaofn """ import numpy as np from sklearn import datasets from sklearn.svm import SVR from sklearn.grid_search import GridSearchCV #Laod sample data iris=datasets.load_boston() #Fit regression model svr=GridSearchCV(SVR(kernel=‘rbf‘,gamma=0.1),cv=5, param_grid={"C":[1e0,1e1,1e2,1e3], "gamma":np.logspace(-2,2,5)}) svr.fit(iris.data,iris.target) #Predict predict_targets=svr.predict(iris.data) #Evalution n_test_samples=len(iris.target) error=np.linalg.norm(predict_targets-iris.target,ord=1)/n_test_samples print("Mean Absolute Error is:%.3f" %(error)) pcc=np.corrcoef(predict_targets,iris.target)[0,1] print ("Pearson Correlation Coefficient: %.4f" %(pcc))
时间: 2024-11-05 14:48:10