*はじめに [#qa786736]
*データ [#fa7b2541]
ここでは、irisデータをサンプルとして用います。
このデータセットは,アヤメの種類(class)を花びらの長さ(sepal length),幅(sepal width),がくの長さ(petal length),幅(petal width)によって分類する問題です. 長さと幅は連続値,種類はIris-setosa, Iris-versicolor, Iris-virginicaのいずれかをとる離散値です.
DeepAnalyticsのフォーマットに倣って、訓練データを train.tsv、テストデータを test_X.tsvとして、タブ区切りのCSVファイルで保存されているものとします。
今回のサンプルファイルはこれです。
-&ref(./train.tsv);
-&ref(./test_X.tsv);
**train.tsv [#gee0ea9e]
|id|sepal lentgh|sepal width|petal length|petal width|class|h
|2|4.9|3|1.4|0.2|Iris-setosa|
|52|6.4|3.2|4.5|1.5|Iris-versicolor|
|101|6.3|3.3|6|2.5|Iris-virginica|
**test_X.tsv [#sa17a203]
|id|sepal length|sepal width|petal length|petal width|h
|1|5.1|3.5|1.4|0.2|
|51|7|3.2|4.7|1.4|
|103|7.1|3|5.9|2.1|
*データの読み込み [#x9791a6c]
pandasのread_csvを使って、タブ区切りのCSVファイルを読み込みます。
タブ区切りなのでdelimiterオプションを、先頭の列がインデックスなのでindex_colオプションを指定します。
#geshi(python){{
import pandas as pd
df_iris_train = pd.read_csv('/Users/tohgoroh/Downloads/train.tsv',
delimiter='\t', index_col=0)
df_iris_test = pd.read_csv('/Users/tohgoroh/Downloads/test_X.tsv',
delimiter='\t', index_col=0)
}}
読み込んだデータは、pandasのDataFrameとなります。
#geshi(python){{
df_iris_train
df_iris_test
}}
* [#r48ab5c2]