0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Notebook Threw Exception] Kaggleのnotebook提出形式の提出時エラーの対処法

Posted at

はじめに

  • この記事は比較的kaggle初心者用です
  • 久しぶりにkaggleのコンテストを参加しようと思ったら、提出すらうまくでいなかったのでそれを解決する方法を示します

どのような提出方式か

私が取り組んでいたコンペは以下です。
https://www.kaggle.com/competitions/csiro-biomass/overview

本コンペの提出方式は、notebook提出型で、playgloundコンペのみしか経験していなかった自分にはじめての形式でした。そのplaygroundでは、csv形式の提出でした。

実際のエラー内容

自分なりにコードを作り、提出した結果発生したエラーの内容は以下です。

Notebook Threw Exception

このエラーは、提出ファイルの形式が間違っているとき(提出ファイルのformat及び行や列の大きさが違う)に出るエラーだそうです。

原因

間違っている原因は二つほどありました。

  • testデータを一部しか読み込めていない
  • 推論結果を正しくcsv化できていない

test dataの読み込みについて

playgroundとの違いは、テストケースのデータ(今回のコンペでいうと画像データ)が隠しデータになっていることです。よって、データが格納されているディレクトリにある画像データをすべて読み込むようにする必要があります。実際のコードは以下のようになります。

test_df = pd.read_csv(data_path + 'test.csv')

for index, row in test_df.iterrows():
        image_path = row['image_path']
        target_name = row['target_name']

つまりは、test.csvに沿ってデータをダウンロードする必要があるということです(どのcsvに沿うかはコンペによる)。

正しくcsv化することについて

結論はcsv化の際にsample_submission.csvを信用してはいけないという点です。隠しテストケースの場合には、sample_submission.csvではなくtest.csvをもとに作成しましょう。

test_df = pd.read_csv(data_path + 'test.csv')

for index, row in test_df.iterrows():
        image_path = row['image_path']
        target_name = row['target_name']
        
        # モデルの実行

        #prediction_valueは予測値
        test_predictions.append(prediction_value)


submission_df = pd.DataFrame({
    'sample_id': test_df['sample_id'],
    'target': test_predictions
})

submission_df['target'] = submission_df['target'].clip(lower=0)

submission_df.to_csv(output_path + 'submission.csv', index=False)

おわりに

ちょっとエラーの内容がわかりずらいときがあるとは思いますが、基本的にはcodeの上位のsample codeを参照するのがいいと思いました!
みんなでkaggle頑張りましょう!

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?