2

http://scikit-learn.org/stable/modules/generated/sklearn.grid_search.GridSearchCV.html_passthrough_scorerとはどのようにしてGridsearchCV(sklearn)のScorersを変更できますか?私は次のようにスコアリング関数を指定せずにGridSearchCVを使用した場合(参考)

x = [[2], [1], [3], [1] ... ] # about 1000 data 
grid = GridSearchCV(KernelDensity(), {'bandwidth': np.linspace(0.1, 1.0, 10)}, cv=10) 
grid.fit(x) 

、grid.scorer_の値です。どのような種類の関数_passthrough_scorerについて説明できますか?

さらに、スコアリング関数をmean_squared_errorなどに変更したいと考えています。

grid = GridSearchCV(KernelDensity(), {'bandwidth': np.linspace(0.1, 1.0, 10)}, cv=10, scoring='mean_squared_error') 

しかしライン、grid.fit(x)は、いつも私にこのエラーメッセージが表示できます:私は本当のを知らないので、

TypeError: __call__() missing 1 required positional argument: 'y_true' 

を私は関数にy_trueを与える方法を見つけ出すことはできません分布。スコアリング関数を変更する方法を教えてください。私はあなたの助けに感謝します。

答えて

1

KernelDensityのデフォルトメトリックは、ユークリッドメトリックであるp = 2のminkowskiです。 GridSearchCVは、他のスコアリング方法を割り当てていない場合、スコアリングにKernelDensityメトリックを使用します。

平均二乗誤差の式は、sum((y_true - y_estimated)^ 2)/ nです。あなたはそれを計算するためにy_trueを持つ必要があるので、エラーがあります。ここで

はKernelDensityにGridSearchCVを適用する作らアップの例です。

from sklearn.neighbors import KernelDensity 
from sklearn.grid_search import GridSearchCV 
import numpy as np 

N = 20 
X = np.concatenate((np.random.randint(0, 10, 50), 
        np.random.randint(5, 10, 50)))[:, np.newaxis] 

params = {'bandwidth': np.logspace(-1.0, 1.0, 10)} 
grid = GridSearchCV(KernelDensity(), params) 
grid.fit(X) 
print(grid.grid_scores_) 
print('Best parameter: ',grid.best_params_) 
print('Best score: ',grid.best_score_) 
print('Best estimator: ',grid.best_estimator_) 

、出力は次のようになります。

[mean: -96.94890, std: 100.60046, params: {'bandwidth': 0.10000000000000001}, 


mean: -70.44643, std: 40.44537, params: {'bandwidth': 0.16681005372000587}, 
mean: -71.75293, std: 18.97729, params: {'bandwidth': 0.27825594022071243}, 
mean: -77.83446, std: 11.24102, params: {'bandwidth': 0.46415888336127786}, 
mean: -78.65182, std: 8.72507, params: {'bandwidth': 0.774263682681127}, 
mean: -79.78828, std: 6.98582, params: {'bandwidth': 1.2915496650148841}, 
mean: -81.65532, std: 4.77806, params: {'bandwidth': 2.1544346900318834}, 
mean: -86.27481, std: 2.71635, params: {'bandwidth': 3.5938136638046259}, 
mean: -95.86093, std: 1.84887, params: {'bandwidth': 5.9948425031894086}, 
mean: -109.52306, std: 1.71232, params: {'bandwidth': 10.0}] 
Best parameter: {'bandwidth': 0.16681005372000587} 
Best score: -70.4464315885 
Best estimator: KernelDensity(algorithm='auto', atol=0, bandwidth=0.16681005372000587, 
     breadth_first=True, kernel='gaussian', leaf_size=40, 
     metric='euclidean', metric_params=None, rtol=0) 

GridSeachCVのための有効な採点方法は、通常y_trueを必要としています。あなたのケースでは、グリッド検索がスコアリングのためにそれらを使用するよう(sklearn.metrics.pairwise.pairwise_kernelssklearn.metrics.pairwise.pairwise_distancesへのインスタンスのために)他のメトリックにsklearn.KernelDensityのメトリックを変更することもできます。

+0

あなたの答えをいただき、ありがとうございます。 KernelDensity(http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KernelDensity.html#sklearn.neighbors.KernelDensity)の資料によると、「濃度出力の正規化だけのために正しいですユークリッド距離メトリック "が、結果にどのように影響するかはわかりません。簡単な英語で説明できますか? – Nickel

関連する問題