以下のコードの中身を理解したいです。 自分なりの解釈は##に記載しました。
不明点と間違っている点を教えて頂きたいです。
参考URL:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html
どうぞ、ご教授の程よろしくお願いいたします。
python3
# sklearnライブラリーからTimeSeriesSplitのダウンロード。# >>> import numpy as np >>> from sklearn.model_selection import TimeSeriesSplit # 配列の整理。# >>> X = np.array([[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]]) >>> y = np.array([1, 2, 3, 4, 5, 6]) # tscv関数の設定# >>> tscv = TimeSeriesSplit() # tscvの表示# >>> print(tscv) # gap=0 テストセット前に、分割部分の後ろから除外するデータ数# # max train size = None 単一の訓練データの最大サイズ# # n_split=5 時系列データを5分割にする。# # test size = None 試験サイズはなし。# TimeSeriesSplit(gap=0, max_train_size=None, n_splits=5, test_size=None) #それぞれのXとYに指定のデータを挿入する# >>> for train_index, test_index in tscv.split(X): ... print("TRAIN:", train_index, "TEST:", test_index) ... X_train, X_test = X[train_index], X[test_index] ... y_train, y_test = y[train_index], y[test_index] #TRAINデータでモデルを作り、TESTで試算する # TRAIN: [0] TEST: [1] TRAIN: [0 1] TEST: [2] TRAIN: [0 1 2] TEST: [3] TRAIN: [0 1 2 3] TEST: [4] TRAIN: [0 1 2 3 4] TEST: [5] #Fix test size to 2 with 12 samples の意味がわからない# >>> # Fix test_size to 2 with 12 samples #Xのデータをランダムで12分割して、2個取り出すということ?# >>> X = np.random.randn(12, 2) #ここの意味がわからない。# >>> y = np.random.randint(0, 2, 12) #tscvの中の計算式で、3分割して、試験用データのサイズは2.2のサイズは?2個?# >>> tscv = TimeSeriesSplit(n_splits=3, test_size=2) #それぞれのXとYに指定のデータを挿入する# >>> for train_index, test_index in tscv.split(X): ... print("TRAIN:", train_index, "TEST:", test_index) ... X_train, X_test = X[train_index], X[test_index] ... y_train, y_test = y[train_index], y[test_index] TRAIN: [0 1 2 3 4 5] TEST: [6 7] TRAIN: [0 1 2 3 4 5 6 7] TEST: [8 9] TRAIN: [0 1 2 3 4 5 6 7 8 9] TEST: [10 11] >>> # Add in a 2 period gap >>> tscv = TimeSeriesSplit(n_splits=3, test_size=2, gap=2) >>> for train_index, test_index in tscv.split(X): ... print("TRAIN:", train_index, "TEST:", test_index) ... X_train, X_test = X[train_index], X[test_index] ... y_train, y_test = y[train_index], y[test_index] TRAIN: [0 1 2 3] TEST: [6 7] TRAIN: [0 1 2 3 4 5] TEST: [8 9] TRAIN: [0 1 2 3 4 5 6 7] TEST: [10 11]
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html
を一度読むといいと思います
まだ回答がついていません
会員登録して回答してみよう