码迷,mamicode.com
首页 > 其他好文 > 详细

grid搜索最优参数

时间:2015-06-15 18:27:57      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

GridSearchCV

详细地址:http://scikit-learn.org/stable/modules/generated/sklearn.grid_search.GridSearchCV.html#examples-using-sklearn-grid-search-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))

 

grid搜索最优参数

标签:

原文地址:http://www.cnblogs.com/chaofn/p/4578635.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!