Warning: Undefined array key 2 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 15

Warning: Undefined array key 3 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18

Warning: Undefined array key 4 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21

Warning: Undefined array key 2 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 27

Warning: Undefined array key 3 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30

Warning: Undefined array key 4 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33

pythonで競馬のデータをスクレイピング【AIで競馬予測】


Warning: Undefined array key 2 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 15

Warning: Undefined array key 3 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18

Warning: Undefined array key 4 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21

Warning: Undefined array key 2 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 27

Warning: Undefined array key 3 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30

Warning: Undefined array key 4 in /home/semtable/teihenai.com/public_html/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33

 

前回は競馬の予想をするにむけて、csvファイルを読み込んで、簡単なニューラルネットワークのモデルをつくり、馬のデータを打ち込んで予測させました。

結果として、データ数が少なすぎることが分かりました。(僕の独断と偏見で)

なので、競馬の過去データをたくさん用意したいと思います。ウェブサイトを見てエクセルに打ち込んでいく方法では、139件×11特徴のデータを取得するのに1時間ほどかかりました。



今回は、テーブルのデータを取得する方法をつかって、たくさんのデータを用意します。

テーブルのデータを取得するために

以前に書いた、スクレイピングの基本を学ぶ記事。そこで学んだことに、以下のコードを追加するだけでよかった。

html = urlopen("URL")
bsObj = BeautifulSoup(html, "html.parser")
table = bsObj.findAll("table",{"class":"クラスのタグ"})[0]
rows = table.findAll("tr")

加えて、whileを使うと効率よくスクレイピングできた。

おわりに

プログラミングを始めてから10日ほどなので、whileのような簡単な書き方しか分からない。なので、もっといい方法があるかも。

後日、データを増やして競馬の予測をやってみました。

おーわり