LoginSignup
2
1

More than 5 years have passed since last update.

さっきひらめいたnumpyを使ったCrossValidationの簡単な書き方

Last updated at Posted at 2018-03-06

tl;dr

# X : ndarray, データ行列とか
# y : ndarray, 教師データ
# cv : int, cv数

n_data = len(y)
m = np.random.permutation(np.arange(n_data) % cv)
for i in range(cv):
    X_train, X_test = X[m != i], X[m == i]
    y_train, y_test = y[m != i], y[m == i]

    # fit & predict

ちなみに

この記事はsklearnを信用できなくなったときにスクラッチで書きたい人のためのものであって、
普通にやるならこういうのつかってかっこよくいきましょう
http://scikit-learn.org/stable/modules/cross_validation.html

2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1