機械学習の流れについて。
import numpy as np
from sklearn.datasets import load_breast_cancer
data = load_breast_cancer()
X = data.data
y = data.target
from sklearn import linear_model
clf = linear_model.LogisticRegression()
データセットをインポートする。データセットはdata部分とtarget部分に別れている。識別器を選択する。
from sklearn.model_selection import ShuffleSplit
ss = ShuffleSplit(n_splits=1,
train_size=0.5,
test_size=0.5)
train_index, test_index = next(ss.split(X, y))
データセットをtrain用とtest用にシャフルする。
clf.fit(X[train_index], y[train_index]);
clf.score(X[test_index], y[test_index])
train用データセットで識別器に学習させる(clf.fit)。test用データセットで学習結果を評価する(clf.score)。
コメントを残す