2017-10-17 58 views
0

我正在嘗試使用GridCV確定sklearn中GPR的超參數。 不過,我收到以下錯誤:
ValueError異常:連續不支持爲什麼使用高斯過程迴歸對GridCV產生錯誤?

任何見解歡迎。我的代碼如下:

import numpy as np 

from sklearn.gaussian_process import GaussianProcess 
from sklearn.gaussian_process import regression_models as regression 
from sklearn.gaussian_process import correlation_models as correlation 
from sklearn.datasets import make_regression 
from sklearn.utils.testing import assert_greater, assert_true, raises 
from sklearn.model_selection import GridSearchCV 

b, kappa, e = 5., .5, .1 
g = lambda x: b - x[:, 1] - kappa * (x[:, 0] - e) ** 2. 
X = np.array([[-4.61611719, -6.00099547], 
       [4.10469096, 5.32782448], 
       [0.00000000, -0.50000000], 
       [-6.17289014, -4.6984743], 
       [1.3109306, -6.93271427], 
       [-5.03823144, 3.10584743], 
       [-2.87600388, 6.74310541], 
       [5.21301203, 4.26386883]]) 
y = g(X).ravel() 


tuned_parameters = [{'corr':['squared_exponential'], 'theta0': [0.01, 0.2, 0.8, 1.]}, 
        {'corr':['cubic'], 'theta0': [0.01, 0.2, 0.8, 1.]}] 

scores = ['precision', 'recall'] 

xy_line=(0,1200) 


for score in scores: 
    print("# Tuning hyper-parameters for %s" % score) 
    print() 

gp = GridSearchCV(GaussianProcess(normalize=False), tuned_parameters, cv=5, 
        scoring='%s_weighted' % score) 
gp.fit(X, y) 

回答

4

精度和召回率是用於分類而不是迴歸的度量。將scoring='%s_weighted' % score更改爲GridSearchCV中的scoring='r2',您的錯誤消失。

相關問題