フィッシャーのアヤメデータセット(2)
名前付き引数: return_X_y
この名前付き引数にTrueを与えると、学習データと教師データのみを得ることができる。戻り値はタプルで返されるのでアンパック代入すること。
code:iris2.py
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
print('X:', type(X), X.shape)
print('y:', type(y), y.shape)
アンパック代入しなかった場合は長さが2のタプルが返されるため、添字を用いて学習データと教師データを取り出す必要がある。
code:アンパック展開しなかった場合.py
from sklearn.datasets import load_iris
data = load_iris(return_X_y=True)
print(type(data), len(data))
X = data0
y = data1
print('X:', type(X), X.shape)
print('y:', type(y), y.shape)
/icons/hr.icon
※ ブラウザのバックボタンで戻る