TensorFlow : Tutorials : 線形モデル・チュートリアル (翻訳/解説)
翻訳 : (株)クラスキャット セールスインフォメーション
作成日時 : 04/05/2017
* 本ページは、TensorFlow の本家サイトの Tutorials – TensorFlow Linear Model Tutorial を翻訳した上で
適宜、補足説明したものです:
https://www.tensorflow.org/tutorials/wide
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。
このチュートリアルでは、TensorFlow の TF.Learn API を使用して二値分類問題を解きます : 年齢、性別、教育と職業 (特徴, features) のような人 (person) に関する人口調査 (census) データが与えられた時に、ある人が年に 50,000 ドル以上稼いでいるか否か (目標ラベル, target label) を推測することに挑戦してみます。ロジスティック回帰モデルをトレーニングして、そして個々の情報が与えられた時に私たちのモデルは 0 と 1 の間の数字を出力します、これは個々が 50,000 ドルの年間収入を持つ確率と解釈できます。
セットアップ
To try the code for this tutorial:
- TensorFlow をインストールします、もしまだならば。
- チュートリアル・コード をダウンロードします。
- pandas データ解析ライブラリをインストールします。tf.learn は pandas を必要としませんが、サポートはします、そしてこのチュートリアルは pandas を使用します。
- このチュートリアルで説明される線形モデルを訓練するために次のコマンドでチュートリアル・コードを実行します :
shell $ python wide_n_deep_tutorial.py --model_type=wide
このコードがどのように線形モデルを構築するかを見つけ出すために読み続けます。
人口調査データを読む
The dataset we’ll be using is the Census Income Dataset. You can download the training data and test data manually or use code like this:
import tempfile import urllib train_file = tempfile.NamedTemporaryFile() test_file = tempfile.NamedTemporaryFile() urllib.urlretrieve("http://mlr.cs.umass.edu/ml/machine-learning-databases/adult/adult.data", train_file.name) urllib.urlretrieve("http://mlr.cs.umass.edu/ml/machine-learning-databases/adult/adult.test", test_file.name)
Once the CSV files are downloaded, let’s read them into Pandas dataframes.
以上