Help us understand the problem. What is going on with this article?

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

現象

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に今回の組み合わせを指定した場合、スコアの高いパラメータの判定ができないということで、使い方が間違っていたということ?
暇なときにソースを見てみよう。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away