11
4

More than 5 years have passed since last update.

Weather Company Data for Advanced Analytics

Posted at

Weather Company Data for Advanced Analytics

先日、日本IBMが気象庁の定める気象予報業務の許可を取得し、企業向けの気象情報提供サービスを開始するというニュースが出ました。

企業向けの気象情報提供サービスを開始
IBMの統計解析ソフトウェアであるSPSS Modelerを利用しているお客様は、追加サービスとしてこれらのデータの取得が可能となります。

今まで、気象情報を分析に利用するには、気象庁などのサイトから細切れの情報をダウンロードしてきて、それを結合、分析ツールで読ませる必要がありました。SPSS Modelerで気象情報の取得ができるのであれば、GUIを使って、直接、気象情報をインポート、加工して自社データと付け合せ、予測分析を行うことができます。面倒なAPIの設定やプログラミングが無いので、業務ユーザでもすぐに気象情報を利用可能できます。気象情報と自社のデータを用いて、「商品の売上予測をしたい」「明日の来客を予想したい」などの用途が考えられます。早速、この機能を試してみます。

IBM SPSS Modelerの準備

Ver18以上が必要です。拡張機能を使います。
RのインストールとR Essentials for SPSS Modeler’pluginのインストールが必要になりますので、以下を参考にセットアップします。

以前投稿した記事:SPSS ModelerとCloudantの接続

SPSS Modelerを起動し、メニューの「拡張機能」>「拡張ハブ」から「Weather関連」の拡張を取得します。検索ボックスに「TWCo」と入力し適用を押すと、「Weather関連」の拡張が抽出されます。
1.png

気象情報の準備

Weather Company Data for Advanced Analyticsには、「Basic」、「Standard」、「Premium」の3種類のライセンスがあり、それぞれの使えるデータ、APIコール数に応じて月額料金が定められています。

Weather Company Data for Advanced Analyticsサービス記述書

30日利用できるTrialの申し込み方法は以下に記載があります。

FAQ

契約もしくは、TrialにてAPIキーを入手します。

SPSS Modelerの「拡張」と「ライセンス」の関係

SPSS Modelerの拡張ハブでは、多くの「拡張」が表示されています。「拡張」と「ライセンス」の関係は以下のとおりです。(「x」が利用可能なものです。)

# 拡張名 Basic Standard Premium 1)概要
2)関連URL
3)データフォーマット
4)コメント
1 TWCo Historical Airport x x x 1)Import historical weather data observations from the nearest government airport for a set of locations and dates.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Historical_Airport
3)https://docs.google.com/document/d/1asVeP3zFjSEYq_HXU4hpXgOcvz3jW1J2Z04guXCSZX0/edit
2 TWCo Currents Airport Past 24 Hour x x x 1)Time Series Observations - Historical weather data from METAR and SYNOP observation sites for specified time range.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Currents_Airport_Past_24_Hour
3)https://docs.google.com/document/d/19mnx4s98nlUo_ugsAbEc5R9NRxhZNSSMzGVsLDA2CJU/edit
3 TWCo Currents Airport x x x 1)Site Based Current Observations - Observed weather data,including associated weather phrase and icon collected from METAR and SYNOP observation sites.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Currents_Airport
3)https://docs.google.com/document/d/19mnx4s98nlUo_ugsAbEc5R9NRxhZNSSMzGVsLDA2CJU/edit
4 TWCo Forecast Hourly x x x 1)Hourly Forecast - Forecast for next 360 hours starting from the current time.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Forecast_Hourly
3)https://docs.google.com/document/d/1AeeMxHxsKBWx6AqVWjaOPKfaeg17zWe0jOKPAqMLaqc/edit
5 TWCo Forecast Daily x x x 1)Daily Forecast - Forecast for 24-hour periods starting today for the next 10 days including daytime and nighttime.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Forecast_Daily
3)https://docs.google.com/document/d/1cOfTD_vP1sIatq1BgwLtXRPSch6K13KRYuL1ny3r2Is/edit
6 TWCo Forecast Intraday x x x 1)Intraday Forecast - Forecast for 6-hour periods starting today for the next 10 days.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Forecast_Intraday
3)https://docs.google.com/document/d/1YZB1OlTr8YENecAy-01uyUA22Dq6OdDVEqZCzqvXlwE/edit
7 TWCo Historical Gridded x x 1)Import high resolution,gridded historical weather observations for a set of locations and dates.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Historical_Gridded
4)この拡張の専用のAPI Keyが必要(※1)
8 TWCo Currents Gridded x x 1)Currents On Demand - High resolution,high temporal current conditions,including associated weather phrase and icon.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Currents_Gridded
3)https://docs.google.com/document/d/1xwdpIEBUNYJIQWdZGmxV1nJ_OPFxoUbsv8X582_1wWs/edit
9 TWCo Forecast Short-Term x x 1)15 Minute Forecast - This API returns weather content consisting of forecasted weather for the next 15 minutes increment time steps out to 7 hours.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Forecast_Short-Term
3)https://docs.google.com/document/d/1o7Gb2eW1bgZ7AXsvTC60mINUCFUNAnnBDhUf0gbgc7o/edit
10 TWCo Forecast Precip Events x x 1)Precipitation Event Forecast - provides a weather forecast for precipitation events(rain,snow,sleet,freezing rain) onset and offset times for 28 time steps over the next 7 hours.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Forecast_Precip_Events
3)https://docs.google.com/document/d/15AGRDXl4YkiPawZrJZ9gP9aCcM5M0uwe0zQkek6V6G0/edit
11 TWCo Historical PWS 7Day Hourly x x 1)PWS Historical Observations - Hourly observations for the past 7 days - Archived data from 200,000+ Weather Underground crowd-sourced sensors from 2000.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Historical_PWS_7Day_Hourly
3)https://docs.google.com/document/d/1emzDjL1fc_cRwQ5wDefkLxnAsPjP4N3NN1wimWwegQA/edit
4)PWSのStation IDをセットする必要がある(※2)
12 TWCo Historical PWS 7Day Daily x x 1)PWS Historical Observations - Daily summaries for the past 7 days - Archived data from 200,000+ Weather Underground crowd-sourced sensors from 2000.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Historical_PWS_7Day_Daily
3)https://docs.google.com/document/d/1OlAIqLb8kSfNV_Uz1_3je2CGqSnynV24qGHHrLWn7O8/edit
4)PWSのStation IDをセットする必要がある(※2)
13 TWCo Historical PWS 1Day Rapid x x 1)PWS Historical Observations - Rapid observations for the past 1 day - Archived data from 200,000+ Weather Underground crowd-sourced sensors from 2000.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Historical_PWS_1Day_Rapid
3)https://docs.google.com/document/d/1wzejRIUONpdGv0P3WypGEqvSmtD5RAsNOOucvdNRi6k/edit
4)PWSのStation IDをセットする必要がある(※2)
14 TWCo Currents PWS x x 1)PWS Current Observations - Current data from 200,000+ Weather Underground crowd-sourced sensors.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Currents_PWS
3)https://docs.google.com/document/d/1j8qp6tT8D1CaOghZfhgCSwSDS8ariPULZbWR_IQX6N0/edit
4)PWSのStation IDをセットする必要がある(※2)
15 TWCo Utility Location x x x 1)Utility API called Location Services that allows a user to convert a set of addresses to Lat/Lons to make it easier to ingest to our existing APIs.
2)https://github.com/IBMPredictiveAnalytics/TWCo_Utility_Location
3)https://docs.google.com/document/d/1b5nWGOGzVrMLLp6aoTTWDebVEbg4UQK951GaW5nXam8/edit
4)日本のPostal codeは未サポート(※3)

(※1)この拡張用にもうひとつ別のAPIキーがThe Weather Companyから送られてきました。
(※2)PWS(=Personal Weather Station)のIDをSPSS Modelerでセットして利用しますが、あまり実用的ではないと感じました。なお、Personal Weather StationのIDは以下で確認ができます。

Weather Underground

(※3)日本のPostal codeは未サポートです。ゆえに、分析用のデータには、「緯度」「経度」の情報が必要です。日本で使う場合に、例えば、顧客マスタに「住所」の項目しかないケースでは、事前に別途、「緯度」「経度」に変換して用意しておくということが必要になります。なお、サポートされているPostal codeはUnited States、United Kingdom、France、Germany、Italyです。

API Common Usage & Style Guide

「basic」では、過去と現在の情報は近くの空港の情報になるので、より細かいグリッドでの情報が欲しい場合には、「Standard」もしくは「Premium」となります。(この二つの違いはAPIコール数の制限および、一部のAPIでの入手できる項目数の違いです。)ただし、TWCo Historical GriddedとTWCo Currents Griddedについては、他のAPIとOutputのフォーマットが全く異なるため、過去の情報からモデルを作成し、将来の予測をぶつけるという形には向いていません。あくまでも、過去の情報の詳細な分析にのみ使えるAPIといえます。

動物園の入園者数を予測する

SPSS ModelerとWeather Company Data for Advanced Analyticsを使って、動物園の入園者数を予測してみます。手順としては以下のとおりです。
①過去の入場者数および関連データから入場者数予測モデルを作成する
②将来の気象予測を①に適用して、入場者数を予測する
サンプルのデータは以下を使わせていただきました。

札幌市円山動物園の入園者数

2012/4/1-2013/3/31のデータです。
1.png

①過去の入場者数および関連データから入場者数予測モデルを作成する
SPSS Modelerのストリームは以下を作成しました。

2.png

過去の天気情報の取得には、TWCo Historical Airportを利用しています。今回、最終的には予測までを行いたいため、TWCo Historical Griddedは利用しませんでした。

3.png

APIKeyには、先に入手をしたAPIキーを入力します。
Unitは「English units -e」のでは華氏やフィートで出力されてしまうので、「Metrix SI units -s」に変更(摂氏、キロメーター)に変更しました。
TWCo Historical Airportは、1回のAPIコールでmax1か月分しかデータを取得できないため、Inputデータは以下のように作成しました。(同じ緯度経度で、違う期間で12回APIコールをしています。)ここで指定する「日付」は日本のローカル時間でかまいません。

4.png

なお、キャッシュを利用する(以下の図の緑のマークが付いている)と1度実行すれば、次回APIコールをせずにキャッシュを読みにいくので、非常に便利です。

5.png
取得されるデータですが、グリニッジ標準時で出てきてしまうので、日本のローカル時間に変換をかけています。

6.png

変換は、以下を参考にしました。

CLEM式で30分後の時間を計算する方法

TWCo Historical Airportとこの後予測で利用するTWCo Forecast Intradayの項目を比べ、両方で使われているものをピックアップ、あまり予測には意味のない項目も削除して以下の3つの項目を利用しました。
・temp(気温)
・rh(湿度)
・wspd(風速)
TWCo Historical Airportは3時間間隔で天候情報を取得します。一方で、入園者数のデータは、日別にしか情報が無いため、TWCo Historical Airportで取得した天候情報は日別に集計をしています。(上記3項目の最大値と最小値を利用しました。)

7.png

過去の天候情報と入園者数のデータを突合させ、できあがった予測モデルは以下のとおり。
9.png

入園者数は、日中の最高温度と休日(土日祝日)に影響がありそうです。最高温度12度というのはひとつキーになっていそうです。

②将来の気象予測を①に適用して、入場者数を予測する
SPSS Modelerのストリームは以下を作成しました。

10.png

型変換などの注意点は、①とほぼ同じです。天候の予測情報については、TWCo Forecast Intradayを利用して取得しています。(今後10日分をとってきています。)

11.png

TWCo Forecast Intradayに関しては、6時間間隔でのデータになっていますので、これも日別に集計をしています。
Inputデータは以下のとおりです。
13.png

①で作成した入園者予測モデルにぶつけてみると、以下のような結果が出ました。(一番右の項目が予測人数です。)

15.png

終わりに

今回、最も簡単な方法で検証を行いましたので、1時間程度で分析を行うことができました。難しいのは、「どの気象情報を予測モデルに含めるか」という点と、「日時のレベルの粒度をどう合わせるのか」という点です。もう少し検証を進めて試行錯誤を繰り返せば、より精度の高いモデルの構築は可能です。
前の記事でも記述しましたが、うまく拡張機能が動かない場合には、Windows FireWallやセキュリティソフトの設定に原因がある場合があります。また、SPSS ModelerのFixpackをあてたらうまく動いたという例もありました。

11
4
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
11
4