2016年8月6日土曜日

「Titanic: Machine Learning from Disaster-Getting Started With Excel」翻訳してみた1(ExcelでTitanicのモデルをつくってKaggleに出してみるまでの流れ編)

訳注:当公式記事(https://www.kaggle.com/c/titanic/details/getting-started-with-excel)を参考にすると、Titanicの訓練データをダウンロードし、Excelを使って簡単に性別での予測モデルを作ってみてKaggleにファイルをアップするまでの流れを確認することができる。Excelのピボットテーブル機能だけで他の環境などは必要ないし、アップするための参考ファイルも、公式サイトからダウンロードしてすぐに使える(Excelで分析しなくても体験ができる)ので、Kaggleをまず簡単に見てみようと思った場合には必読の記事。
下記翻訳部分には、 手元のOffice2010Excel(日本語)で試行した際の画面キャプチャ、自分のアカウントでKaggleに応募した際の画面キャプチャも補足として入れています。


*****

 

Titanic: Machine Learning from Disaster

(タイタニック号沈没:災害の機械学習)

Getting Started With Excel
(Excelを使った入門)

元記事:https://www.kaggle.com/c/titanic/details/getting-started-with-excel

Kaggleのタイタニック号沈没生存グループ予測コンペへの参加入門(Excel編)

大きなデータセットを扱った経験がない人にとっては、Kaggleのウェブサイトからデータを取ってくることに少しひるんでしまうかもしれません。こういったコンペの多くは、6つの形態の賞(←?)やデータが含まれています。ここKaggleでは、主催者としてもコンペへの応募への敷居が高いことを理解しているため、最初のステップとして何をしたら良いのかを「入門」という形で公開しています。

まずはやってみよう

コンペはシンプルです。タイタニックの船客データ(名前、年齢、性別、社会的な地位、その他)を提供するので、誰が生き残り、誰が死ぬだろうかを予測してください。
なんとか終わらせたいのですが、次に何をすればよいですか?
 まず、Kaggleのウェブサイトからデータを取りましょう。2つのファイル(train.csvとtest.csv)が必要です。 このcsvファイルは、すべての値(名前、年齢、性別など)がカンマで区切られていて、行もカンマで区切られています。そのため、Excelに列として読み込むことができます。notepadなどのテキストエディタで開くと、こんな感じです。
CSV in notepad
 Excelで開くと、こんな感じになります。
CSV in Excel
データをダウンロードする場合、「Get The Data(https://www.kaggle.com/c/titanic/data)」をクリックし、データページから取得してください。Download the data
※訳注:実際にデータをダウンロードして中身を見て、中身の説明部分を訳したブログ公開記事はこちら(http://techinfo4dog.blogspot.jp/2016/04/titanic-machine-learning-from_2.html)。

ダウンロードする場合は、青文字の「.csv」部分をクリックしてください。初めてダウンロードする際には、コンペのルールを承認するか聞かれるページが表示されます。データをダウンロードするにはコンペのルールを承認する必要があります。承認すべきコンペのルールとは、


・一日あたりいくつまでコンペの結果を提出できるか
・最大のチームサイズ、
・その他、コンペのルール詳細

です。「I Understand and Accept」をクリックし、ファイル名を再度クリックすることで、ダウンロードできます。
データをダウンロードした後、何をすればよいですか?
2つのファイル(train.csv、test.csv) を見てください。train.csvには、乗船した客891人の詳細データと、彼らが生存したかどうかが含まれています。train.csvのデータを利用して、test.csvにある418人の船客が生き残ったかどうかを予測してください。
データのパターンを見つけなきゃいけないってことは分かったのですが……で、どこからはじめたらよいのですか?
 train.csv をExcelで開いてください。見て分かるとおり、中にはタイタニック号に乗船していた人の詳細データがあります。Pclass、チケットのクラス(1st、 2nd、 3rd)、名前、性別、年齢、Subsp(一緒に乗船した兄弟姉妹、配偶者の数)、Parch(一緒に乗船した親、子供の数)、チケットのタイプ、チケット購入代金、キャビン番号、タイタニック号に乗船した港(QueenstownCherbourgSouthampton)です。また、彼らが生き残ったかどうかを、1 = 生き残った、0 = 残念ながらお亡くなりになった、として表記しています。これは予測モデルを作るための情報です。このcsvファイルに含まれている船客に関する変数と、生き残ったかどうかの関係性を見つけ出してください。
データサイエンスの世界では、勘が予測モデルを作るための重要な開始地点となります。もし映画「タイタニック」を見たことがあるなら、女性と子供を先に助けようとしたことを覚えているでしょうか。それはモデルを考え始めるときの重要な推測となります。Excelには、この種の検討を行うのに良い助けとなる「ピボットテーブル」があります。データのすべてを選択し、「挿入」→「ピボットテーブル」を選択してください。

Insert a Pivot Table!







ドキュメント内に、新しいシートが作られます。右側には選択可能な変数、下に4つのボックスが表示されます。誰が生き残ったかに興味があるので、この変数(survived)が他の変数とどう関係するかを見ていきます。右手側、「survived」をドラッグし、チェックボックスの隣、右側のボックス(訳注:右下のΣ値)に落とします。これで、生存ボックスの合計値が表示されます。

 


男女のどの程度が生き残ったかを知りたいなら、「Sex」変数を「行ラベル」(訳注:右下)にドラッグします。

 


生存したかどうかは1、0(訳注:生き残ったほうが1)で表され、この数の合計は合計生存者数となります。割合を知りたい場合、「survived」変数を再度変数ボックスにドラッグし、下矢印をクリックし、値のフィールド設定を選択し、「Sum」を「count」に変更します。





 


(訳注:SurvivedをΣ値の部分に再度入れた後、右の▼をクリックし、「値フィールドの設定」を選択。フィールドの設定ダイアログが表示されるので、下の「合計」を「データの個数」に変更し、OKボタン。)



これで合計何行あるか(このケースでは何人の船客か)を確認できます。テーブルの横に、「B4 / C4」と入力することで、生き残った女性の割合を知ることができます。

Work out the proportion of survivors
ここまでの操作で、女性の75%は生き残ったことが分かるでしょう。ただ、男性も19%は生き残っています。とはいえ、最初の推論としては頼もしいものでしょう。
自分の予測モデルを作る
女性はかなり生き残るチャンスがあったことから、性別は、生死予測に対して強い要因であることが分かるでしょう。最初の予想はこれをベースにするために、test.csvをExcelで開き、1列目に、ヘッダが「Survived」の列を作ります。Kaggleの予測を出すには、「Survived」という列があることが必須です。(詳しくは、「https://www.kaggle.com/c/titanic/details/submission-instructions」を参照してください。)

女性はすべて生き残ったと入力するのに、Excelの数式「if」を使います。「=if(E2="female",1,0)」と入力します。もしsexがfemaleであれば1、そうでなければ0を入れることを意味します。右隅をクリックして最終行まで伸ばし、数式を最終行まで入れます。ただ、Kaggleに応募するときにこのままの数式では駄目で、0か1かに変える必要があります。列を「値」として別の列にコピーしましょう。そしてPassengerIdと0、1にしたSurvivedの列を、「genderbasedmodel.csv」として、保存します。









A gender based model!
 
(訳注:Titanicのtest.csvとかをダウンロードしたところで「genderbasedmodel.csv」もダウンロードできる。このcsvが応募のフォーマットと同じ。)



予想モデルができました。次にどうしましょう?
最後のステップ:
Kaggleに応募する際、2つの列、PassangerID、Survivedの列だけにする必要があります。PassangerID、Survived以外の列を消去し、2列のみになったcsvを保存します。そしてインターネットのブラウザに戻り、コンペのページで、「Make a submission」をクリックします。(訳注:https://www.kaggle.com/c/titanic/details/getting-started-with-excelの左上。)
 
チームのページに遷移します。ここでチームを設定することができます。(Kaggleでは、一人~20人のチームを作るのが一般的です。) 各チームにはチームリーダーを立てます。チームには後でメンバーを追加することができますが、メンバーをはずすことはできないので、注意して選んでください。他の人に名前を見せたくない場合、名無しでもOKです。
  • 「Continue」をクリックし、「You have 2 (of 2 entries) left today」部分を最初に確認します。不正行為を避けるため、Kaggleは一日に投稿できるモデル数に制限があります。「Click or Drop Submission Here」ボタンをクリックし、投稿するファイル(ここではgenderbasedmodel.csv)を選択し、「Submit」をクリックします。 
 















(訳注:10秒程度でUploadでき、順位、スコアが確認できる。同じデータをUpした人がたくさんいるのか、同じスコアがたくさんいますね。)

The Kaggle Leaderboard!
  • 一度データを送信したら、リーダーボードにスコアとランキングが表示されます。各コンペは異なる評価体系でスコア化され、詳細はEvaluation pagehttps://www.kaggle.com/c/titanic/details/evaluation)に記載があります. このコンペの評価体系はシンプルで、生存・死亡が正しく判定できた人数です。



→訳の続きは後編へ。
http://techinfo4dog.blogspot.jp/2016/08/titanic-machine-learning-from_13.html


****以下、翻訳時点での記事コピー(元記事:https://www.kaggle.com/c/facial-keypoints-detection/details/submission-instructions)*****

Getting Started With Excel

Getting Started with Excel: Kaggle's Titanic Competition

For those who are not experienced with handling large data sets, logging into the Kaggle website for the first time may be slightly daunting. Many of these competitions have a six figure prize and data which can, at times, be extremely involved. Here at Kaggle, we understand that this may seem like an insurmountable barrier to entry, so we have created a "getting started" competition to guide you through the initial steps required to get your first decent submission on the board.

The challenge

The competition is simple: we want you to use the Titanic passenger data (name, age, gender, socio-economic class, etc) to try to predict who will survive and who will die.
I want to compete! What do I do next?
The first thing to do is get the data from the Kaggle website. You will need two files:train.csv and test.csv. The .csv filename stands for comma separated values, where every value (name, age, gender, etc) in a row is separated by a comma. This allows Excel to interpet the data as columns.  If you load the file up in notepad--or your text editor of choice--it would look like this:
CSV in notepad
 However, in Excel it looks like this:
CSV in Excel
To get the data…Click on Get The Data, and this will take you to the Data page:
Download the data
In order to download, click on the blue file extensions (.csv). The first time you do this you will be taken to the rules acceptance page. You must accept the competition rules in order to download the data. These rules govern how many submissions you can make per day, the maximum team size, and other competition specific details. Click "I Understand and Accept" and then re-click the filenames.  You will need both files.
I have the data what do I have to do?!
You have two files, train.csv and test.csv. Train.csv will contain the details of a subset of the passengers on board (891 to be exact) and will tell you their details and whether they survived or not. Using the patterns you find in the train.csv data, you will have to predict whether the other 418 passengers on board (found in test.csv) survived. 
So I need to find patterns in the data… Where do I start?!
Open up train.csv in Excel. As you can see, we have given you the details of a number of passengers on board the Titanic. We have given you the Pclass, the class of their ticket (1st, 2nd or 3rd), their name, their sex, age, Subsp (which is the number of siblings / spouses they had on board with them), Parch (which is the number of parents / children they had on board with them), their ticket type, the fare they paid for their ticket, their cabin number, and Embarcation point (where they got on: Queenstown,Cherbourg or Southampton). We also give you whether they survived or not (1 = yes, 0 = sadly, not). This is the information you are going to use to make your predictions. We want to find if there is a relationship between one of the variables and ultimate survival.
In data science, your intuition is often a great place to start. If you have ever seen the film Titanic, they try to save the women and children first.  This would be a good guess to start! Excel has a helpful tool for this kind of exploration called a pivot table. Highlight the entire set of data and go to 'Insert'--> 'Pivot Tables'.
Insert a Pivot Table!
This should create a new spreadsheet in your document. On the right should be all the variables that you selected and four boxes at the bottom. We are interested in who survived, so you want to see how this value varies as you select other variables. On the right hand side, drag the word 'survived', which has a check box next to it, down to the bottom right hand box. This will show the sum of the survived box. Now, to see how many women and men survived, drag the 'Sex' variable to the 'Row labels'. Since Survived is a 1 or 0, the sum of this is the total number who survived. If you want to find the proportion, drag the Survived variable again into the values box (so now there are two in there) click on the down arrow, select value field settings, and change 'Sum' to 'count'. This will tell you the total number of rows (or passengers in this case). Now, in the cell next to the table you can just type = B4 / C4, which would show the proportion on females that survived.
Work out the proportion of survivors
From this you can see that almost 75% of the females survived! However, only 19% of the males lived to tell about it. This is quite a promising first guess!
Making my predictions
Gender seems to be a strong indicator of survival, with women having a much better chance! To make your first predictions based on this, now open test.csv in Excel and insert a new column in the first column, and give it the header Survived. Your submission to Kaggle MUST have your predictions in a column named 'Survived' (more info here)!
To make a model which states that if the passenger is female then she survives in the first cell write a logical 'if' statement. Type =if(E2="female",1,0) which means if(sex=female, then make this cell = 1, if not then make this cell = 0). Then double click on the bottom right hand corner of this box so it drags down through all rows. You've now created a calculated formula for each row in Excel, but for Kaggle you want a definitive value, 0 or 1. So re-paste the same column onto itself with Paste As > Values.  Save the file as something memorable. I'll use 'genderbasedmodel.csv'. 
A gender based model!
I’ve made my predictions, how well have I done?
One last step:  Kaggle can only accept 2 columns in your submitted answer, PassengerId and Survived. Delete any extra columns, and save (or Save As) this new version of your csv which only has those 2 columns. Now go back to your internet browser and the competition page and click 'Make a submission'.
  • This should bring up your team page. This is where you can set up your team. (On Kaggle you are always a member of a team, whether it is one person or 20 people.) Each team has a team leader. Teams can be added to at a later date, however members cannot be removed, so choose carefully! You can compete anonymously as well, if don’t want people to see your name.
  • Hit 'Continue' and the first thing you may notice is 'You have 2 (of 2 entries) left today'. Kaggle limits the number of submissions you make so you can't use the leaderboard score to gain and unfair advantage with your submissions. Click on the button 'Click or Drop Submission Here' and select the file you would like to submit (here, 'genderbasedmodel.csv') and click 'Submit'.
The Kaggle Leaderboard!
  • Once you have submitted, you will be taken to the leaderboard and shown your score and ranking on the leaderboard. Each competition is scored based on different evaluation metrics, whose details are described on theEvaluation page.  In this competition the metric is simply the fraction of passengers you got correct.

0 件のコメント:

コメントを投稿