LoginSignup
0
3

More than 3 years have passed since last update.

GridSearchCVでcvにLeaveOneOut、評価指標にr2を指定した時の話

Last updated at Posted at 2019-08-24

現象

GridSearchCVでcvにLeaveOneOut、評価指標にr2を指定した場合、GridSearchCVのbest_scoreがnanになる。評価指標をneg_mean_squared_errorにすると値が出る。少し悩む。

省略> 
[CV] .................................. n_components=10, total=   0.0s
[CV] n_components=10 .................................................
[CV] .................................. n_components=10, total=   0.0s
[CV] n_components=10 .................................................
[CV] .................................. n_components=10, total=   0.0s
[CV] n_components=10 .................................................
[CV] .................................. n_components=10, total=   0.0s
[CV] n_components=10 .................................................
[CV] .................................. n_components=10, total=   0.0s
[Parallel(n_jobs=1)]: Done 1000 out of 1000 | elapsed:    1.7s finished
Best Param={'n_components': 1}, Best Score=nan

結論というか推測

LeaveOneOutの場合、各分割のテストフォールドは1件のみとなる。
GridSearchCVのスコア計算は、(恐らく)各分割の予測結果に対し評価指標を計算し、全分割の平均をとっている。
相関係数の定義より、1件しかデータがない場合、分母は0になるため計算はできない。
よって各分割の評価指標の計算結果はnanとなり、これらの平均をとってもnanとなる。

要するにGridSearchCVに今回の組み合わせを指定した場合、スコアの高いパラメータの判定ができないということで、使い方が間違っていたということ?
暇なときにソースを見てみよう。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3