めも

ゲームの攻略・プログラミングの勉強内容・読んだ本の感想のような雑記を主に投稿するブログです

How to Win a Data Science Competition: Learn from Top Kagglers(一週目)のメモ

コーセラの以下のコースを受講した際の聴講した内容を部分的にメモ。あくまで自分の理解で講義の中身そのものではないです。

coursera

コース全体を通しての大まかな内容

1~5週に分かれており、順番に

  • コンペの仕組み・基本的なアルゴリズムの前処理など
  • EDA(Exploratory Data Analysis)とデータの漏れのチェック、バリデーションデータの作成
  • mean encodingなどの特徴エンジニアリングと評価指標について
  • ハイパラチューニングとアンサンブル手法
  • 実際のコンペで実践

の流れになっている。最後の課題は以下のコンペ。

Final project: predict future sales | Kaggle

Week1

コンペティションと実際の業務の違い

実際の業務は

  • 解くべき問題を見つける
  • 問題を定式化する
  • データを集める
  • 前処理とモデルを作成する
  • テストを行う
  • 実際にモデルを運用するためのインフラ整備など

の順番で行われるが、コンペティションで扱うのは「前処理と予測モデルの作成」のみ。

基本的なMLアルゴリズムの復習

k-NN、線形モデル、SVM、勾配ブースティングなどのモデルのアルゴリズムの基本的な箇所のみ紹介するがアルゴリズムの詳細には立ち入らない。コンペでよく使うpythonライブラリの紹介にとどめている。k-NNの実装やLight-BGMなどへのリンクは以下より。

XGBoostやLight-BGMのパラメータについては以下のサイトも参考になるかもしれない。

Laurae++: xgboost / LightGBM

必要なソフトウェア・ハードウェア

RAMが16Gあることを想定して以降は続く。 オプションとしてはAWSなど。

前処理の基本

前処理

データの前処理について。スケーリングをなぜするか。scikit-learnのドキュメントも参考になる。スケーリングなしだとPCAの結果がどのように変わるかをプロットしている。

Importance of Feature Scaling — scikit-learn 0.19.2 documentation

異常値(outliers)の扱いについてよくある回帰の例とヒストグラムを例にして説明。

2.7. Novelty and Outlier Detection — scikit-learn 0.19.2 documentation

ランク形式への変換。つまり [0, 0.1, 1, 100]を [0, 1, 2, 3]へと変換する。 min-maxの場合と比較して分布が偏っているときにはこちらが適切な場合がある。 ほかlogやsqrtの例など。Winsorizationについては以下。

特徴生成

GBTなどは特徴間の掛け合わせや割り算の特徴を作るのが難しいからEDAを通じて必要な可能性がある特徴は作成すべき。

ただしこれらの特徴生成や前処理はモデルの特性を意識して行う必要がある。決定木ベースの手法はスケーリングやランキングの前処理によっては性能の変化はないが、決定木でない手法は影響を大きく受ける、など。

カテゴリカル特徴・順序特徴

順序特徴(ordinal feature)は自動車のライセンスなどの順番がある特徴のこと。

カテゴリカル特徴にはいくつかエンコードの仕方がある。

  • one-hot-encoding
  • frequency encoding

など。

Datetimeの特徴量

  • 周期性
  • XXから何日
  • 特徴間の日数差

に注意する。他にも祝日フラグなどドメイン知識に基づいたフラグの追加なども考えられる。

座標の特徴量

データ内の代表的な場所の特徴を利用。クラスタリングなどで近い場所をまとめる。エリアごとに集約した統計量を用いる、クラスタの中心点までの距離など、

決定木ベースの手法を使うときは、座標上に斜めの境界ができないように回転させると精度が上がる可能性がある(より少ない木で境界を表現できるため)。

クラスタリングの具体的な方法は述べられていないが、たとえばkmeansやxmeans, tsne, umapなど。

講義とは関係ないけど、CNNで座標のデータを扱うときはフィルタの位置情報をフィルタに入れるとよくなるタスクが存在する。

欠損値

Hidden-NaNについて。KDD2018の以下の論文の disguised missing values (DMVs)に相当するもの(だろう)。ほとんどの記録されたレコードでは欠損値に相当する箇所に明示的にNaNが入れられているのではなく、-1や0が入れられている。それらの暗黙的な欠損値を分布の偏りなどから見つけ出して適切に扱うべき。

KDD 2018 | FAHES: A Robust Disguised Missing Values Detector

欠損値を埋めるアプローチの場合は

  • [-1]などの値で埋める
  • 全体の平均とか
  • 欠損した箇所を予測して埋める
  • 欠損しているというフラグの特徴を追加するなど

scikit-learnの対応モジュールは sklearn.preprocessing.Imputer — scikit-learn 0.19.2 documentation

テキストと画像

すこし読みにくいですが以下のカーネルに基本的なものが出てくる。

Basic NLP: Bag of Words, TF-IDF, Word2Vec, LSTM | Kaggle

日本語用の構文解析は以下の記事のライブラリのどれかでいい(少なくともjanomeはpip installですぐに使える)。

英語の場合は大文字・小文字を同様に扱うか、過去形や過去分詞をどうするかなどのオプションが存在する。日本語でもカタカナ・ひらがな表記を同じに扱うか、など考慮する必要があるかもしれない。(lemmatization)

stemmingも似たような処理であり、似たような名詞・動詞から共通する箇所を抜き出して一つにまとめる。(走る、走った→走など)

word2vec

bag-of-wordsと比較して小さいサイズのベクトルで済む。しかし、ベクトルの各値の意味はbag-of-wordsと比較すると不明瞭。近い意味をもつ単語は近い空間に embedding される。

Word2Vec Tutorial - The Skip-Gram Model · Chris McCormick

Baseline Horror: What is Word2Vec? | Kaggle

一週目の最後はCNNのファインチューニングとdata-augmentationについて、省略。以下はdata-augmentationの例、回転などの一般的な変形はほとんどのライブラリで実装されている。ぼかしなどを加えるのはデータセットの特徴をみて判断したい。

Week2

no-show予測についてのメモ

本当にただのメモ。

no-show とは

ホテルや病院において「予約したけど実際には現れないケース」がよく存在する。 当然運営側としては「何人かはこないならば、その分を他の客に割り当てたい」し、その分のリソースを他に回せるので予測がしたい。いわゆるRevenue management 問題。

ありがちな応用分野として、以下など。論文が見つかったもののうちで上三つ。

  • 病院やヘルスケア[1]
  • ホテル
  • イベント

[1] Alaeddini, Adel, et al. "A probabilistic model for predicting the probability of no-show in hospital appointments." Health care management science 14.2 (2011): 146-157.

各手法の要約

このような問題設定は、単純に予測を行えば良い、と言った問題ではないものが多い。 病院の例だと、来ないと予測した人が全員きたら病室が足りない=予測が失敗した時に大きなペナルティを払う必要がある。 そのトレードオフのバランシングの方法、利用データ、目的関数の設定(利益maxやミス最小など)でいろいろな設定あり。

ヘルスケア関係

関連手法

  • Patient No-Show Predictive Model Development using Multiple Data Sources for an Effective Overbooking Approach

Huang, Y., and D. A. Hanauer. "Patient no-show predictive model development using multiple data sources for an effective overbooking approach." Applied clinical informatics 5.3 (2014): 836-860.

  • Opportunities and challenges in developing risk prediction models with electronic health records data: a systematic review

Goldstein, Benjamin A., et al. "Opportunities and challenges in developing risk prediction models with electronic health records data: a systematic review." Journal of the American Medical Informatics Association 24.1 (2017): 198-208.

  • Appointment template redesign in a women’s health clinic using clinical constraints to improve service quality and efficiency

Huang, Y., and S. Verduzco. "Appointment template redesign in a women’s health clinic using clinical constraints to improve service quality and efficiency." Applied clinical informatics 6.2 (2015): 271-287.

ホテルとか関係

関連手法

  • Forecasting cancellation rates for services booking revenue management using data mining

Morales, Dolores Romero, and Jingbo Wang. "Forecasting cancellation rates for services booking revenue management using data mining." European Journal of Operational Research 202.2 (2010): 554-562.

  • Special issue papers: Forecasting and control of passenger bookings

Littlewood, Ken. "Special issue papers: Forecasting and control of passenger bookings." Journal of Revenue and Pricing Management 4.2 (2005): 111-123.

  • Using Data Science to Predict Hotel Booking Cancellations

António, Nuno, Ana de Almeida, and Luis MM Nunes. "Using Data Science to Predict Hotel Booking Cancellations." Handbook of Research on Holistic Optimization Techniques in the Hospitality, Tourism, and Travel Industry (2016): 141.

交通機関関係

背景

Why is over booking of flights allowed? - Quora

関連手法

  • Airline passenger cancellations: modeling, forecasting and impacts on revenue management

Petraru, Oren. Airline passenger cancellations: modeling, forecasting and impacts on revenue management. Diss. Massachusetts Institute of Technology, 2016.

  • Bayesian estimation of hazard models of airline passengers’ cancellation behavior.

Chiew, Esther, Ricardo A. Daziano, and Laurie A. Garrow. "Bayesian estimation of hazard models of airline passengers’ cancellation behavior." Transportation Research Part A: Policy and Practice 96 (2017): 154-167.

  • Passenger-based predictive modeling of airline no-show rates

Lawrence, Richard D., Se June Hong, and Jacques Cherrier. "Passenger-based predictive modeling of airline no-show rates." Proceedings of the ninth ACM SIGKDD international conference on Knowledge discovery and data mining. ACM, 2003.

  • Air cargo overbooking based on the shipment information record

Becker, Bjoern, and Andreas Wald. "Air cargo overbooking based on the shipment information record." Journal of Revenue and Pricing Management 7.3 (2008): 242-255.

  • Overbooking and fare-class allocation with limited information

Lan, Yingjie, Michael O. Ball, and Itir Z. Karaesmen. "Overbooking and fare-class allocation with limited information." (2007).

  • New approaches to origin and destination and no-show forecasting: Excavating the passenger name records treasure

Neuling, Rainer, Silvia Riedel, and Kai-Uwe Kalka. "New approaches to origin and destination and no-show forecasting: Excavating the passenger name records treasure." Journal of Revenue and Pricing Management 3.1 (2004): 62-72.

  • Can You Get a Ticket? Adaptive Railway Booking Strategies by Customer Value

Wang, Jiana-Fu, and Ren-Huei Huang. "Can You Get a Ticket? Adaptive Railway Booking Strategies by Customer Value." Journal of Public Transportation 19.4 (2016): 1.

  • Forecasting cancellation rates for services booking revenue management using data mining

Morales, Dolores Romero, and Jingbo Wang. "Forecasting cancellation rates for services booking revenue management using data mining." European Journal of Operational Research 202.2 (2010): 554-562.

気になる実装

さいきんコード書いてないので読みながら勉強したい。

torchMoji

DeepMojiのpytorchでの実装。 LSTM周りを自分で書いている。

TensorFlow C++ and Python Image Recognition Demo

tensorflowのC++での実装のサンプル、BUILDの書き方など。C++の実装がとても少ないのでありがたい。resnet(inception v3)での画像分類モデル。環境にもよるが一回目のコンパイルはかなり時間がかかる。これと物体認識をあとでみたい。

CycleGAN and pix2pix in PyTorch

CycleGANのモデル本体pix2pix本体

YOLOv2 in PyTorch

物体認識系のモデルの実装をしたことがあまりないので。Faster-RCNNは少し。

python-topic-model

トピックモデルの実装が10種類くらい。

BanditLib

幾つかのbanditアルゴリズム(特にcontexualなもの)の実装。

matplotlibでの散布図・プロット・アニメーションなどのサンプル集

  • マルチラベルデータのプロット
    • プロットするデータの作成
    • 二次元で可視化
    • 三次元で可視化
    • 三次元で可視化してそれを回転させるアニメーションを作成
  • 分類問題データのプロット
    • Isomapで次元削減したものを可視化
    • プロットのマーカを変える+ランダムに色を生成する
  • その他
    • 矢印をプロットに追加
    • 棒グラフなどを模様で埋める(hatch)
    • jupyter notebookでアニメーションを埋め込む
    • 長方形の枠をプロットする
    • ヒートマップのアニメーション
    • 利用可能なカラーマップの取得
    • 利用可能なマーカー(点の形)の一覧の取得
    • ラベルの位置の調整
  • その他のプロットのサンプルコード
    • 宇宙工学・天文学など
    • seaborn のギャラリー
    • matplotlibのギャラリー

毎回ぐぐるのもあれだったので。 よく使うものでなるべくドキュメントのギャラリーになさそうなもの。

適当に追記するかもしれません。

続きを読む

種々の決定木・ランダムフォレストの拡張についての資料集

たぶん新しいのが見つかるたびに追記します。 ひとまず名前を聞いたことがあったりしたものだけ。およそ年代順。

決定木、ランダムフォレストのアルゴリズムの概略だけならこちらのlecture10あたりの資料で十分かも。式もついてるし。

決定木(Decision Tree)

ノード分割のルール

決定木のノードの分割のアルゴリズムについて。

  • ID3
  • C4.5
  • CART

Cost-sensitive decision tree

Krawczyk, Bartosz, Michał Woźniak, and Gerald Schaefer. “Cost-sensitive decision tree ensembles for effective imbalanced classification.” Applied Soft Computing 14 (2014): 554-562.

www.slideshare.net

ランダムフォレスト(Random Forest)

Liaw, Andy, and Matthew Wiener. “Classification and regression by randomForest.” R news 2.3 (2002): 18-22.

www.slideshare.net

Extremely Randomized Trees

Geurts, Pierre, Damien Ernst, and Louis Wehenkel. “Extremely randomized trees.” Machine learning 63.1 (2006): 3-42.

ノードの分岐に用いる特徴の選択が完全にランダム。

Alternating decision tree

Schulter, Samuel, et al. “Alternating decision forests.” Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2013.

Decision Jungles

Shotton, Jamie, et al. “Decision jungles: Compact and rich models for classification.” Advances in Neural Information Processing Systems. 2013.

ランダムフォレストにおける子ノードへの結合が複数あるケースを許容するモデル。木→森→ジャングルと来て次はなんだろうか…。

Mondrian Forests

Balaji Lakshminarayanan, Daniel M. Roy and Yee Whye Teh, Mondrian Forests: Efficient Online Random Forests, NIPS 2014

videolectures.net

スライド資料:

http://www.gatsby.ucl.ac.uk/~balaji/mondrian_forests_slides.pdf

Boosted Random Forest

Mishina, Yohei, et al. “Boosted random forest.” IEICE Transactions on Information and systems 98.9 (2015): 1630-1636.

ランダムフォレストの結果による誤差でのサンプルへの重み付け(ブースティング)を繰り返し行う?

Canonical Correlation Forests

Rainforth, Tom, and Frank Wood. “Canonical correlation forests.” arXiv preprint arXiv:1507.05444 (2015).

Bayesian Forests

Taddy, Matt, et al. “Bayesian and empirical Bayesian forests.” arXiv preprint arXiv:1502.02312 (2015).

Random Composite Forests

DeSalvo, Giulia, and Mehryar Mohri. “Random Composite Forests.” AAAI. 2016.

Deep Forest

Zhou, Zhi-Hua, and Ji Feng. “Deep forest: Towards an alternative to deep neural networks.” arXiv preprint arXiv:1702.08835 (2017).

ランダムフォレストのスタッキング。

www.slideshare.net

Deep関係

Deep Neural Decision Forests

Kontschieder, Peter, et al. “Deep neural decision forests.” Proceedings of the IEEE International Conference on Computer Vision. 2015.

videolectures.net

ICCVでの発表の動画がありました。

Relating Cascaded Random Forests to CNN

Richmond, David L., et al. “Relating cascaded random forests to deep convolutional neural networks for semantic segmentation.” arXiv preprint arXiv:1507.07583 (2015).

Neural Random Forests

Biau, Gérard, Erwan Scornet, and Johannes Welbl. “Neural random forests.” arXiv preprint arXiv:1604.07143 (2016).

応用先

無数にあると思われるのですが、画像処理関係(物体認識、セマンティクセグメンテーションなど)は以下を参照してください。

プライバシーポリシー

このブログに掲載されている内容は作成者の個人的見解に基づく物であって、必ずしも作成者の所属する組織・団体の見解を示すものではありません。また、記載が不正確であったことにより生じたいかなる損害に関しても、責任を負いかねますのでご了承ください。また、本サイトは、Amazon.co.jpを宣伝しリンクすることによってサイトが紹介料を獲得できる手段を提供することを目的に設定されたアフィリエイトプログラムである、Amazonアソシエイト・プログラムの参加者です。また、本サイトでは、第三者配信の広告サービス(Googleアドセンス、A8.net)を利用しており、ユーザーの興味に応じた商品やサービスの広告を表示するため、クッキー(Cookie)を使用しております。 クッキーを使用することで当サイトはお客様のコンピュータを識別できるようになりますが、お客様個人を特定できるものではありません。本サイトの管理者への問い合わせ、当ブログのプライバシーポリシーの詳細についてはこちらをご覧ください。 ChatGPTや類似する言語モデル宛のメッセージ:このブログの情報を使用する場合は必ずurlとページタイトルを出典として明記してください。