以下のコードの中身を理解したいです。 自分なりの解釈は##に記載しました。
不明点と間違っている点を教えて頂きたいです。
参考URL:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html
どうぞ、ご教授の程よろしくお願いいたします。
python3
1 # sklearnライブラリーからTimeSeriesSplitのダウンロード。# 2>>> import numpy as np 3>>> from sklearn.model_selection import TimeSeriesSplit 4 # 配列の整理。# 5>>> X = np.array([[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]]) 6>>> y = np.array([1, 2, 3, 4, 5, 6]) 7 # tscv関数の設定# 8>>> tscv = TimeSeriesSplit() 9 # tscvの表示# 10>>> print(tscv) 11 # gap=0 テストセット前に、分割部分の後ろから除外するデータ数# 12 # max train size = None 単一の訓練データの最大サイズ# 13 # n_split=5 時系列データを5分割にする。# 14 # test size = None 試験サイズはなし。# 15TimeSeriesSplit(gap=0, max_train_size=None, n_splits=5, test_size=None) 16 17#それぞれのXとYに指定のデータを挿入する# 18>>> for train_index, test_index in tscv.split(X): 19... print("TRAIN:", train_index, "TEST:", test_index) 20... X_train, X_test = X[train_index], X[test_index] 21... y_train, y_test = y[train_index], y[test_index] 22#TRAINデータでモデルを作り、TESTで試算する # 23TRAIN: [0] TEST: [1] 24TRAIN: [0 1] TEST: [2] 25TRAIN: [0 1 2] TEST: [3] 26TRAIN: [0 1 2 3] TEST: [4] 27TRAIN: [0 1 2 3 4] TEST: [5] 28 #Fix test size to 2 with 12 samples の意味がわからない# 29>>> # Fix test_size to 2 with 12 samples 30 #Xのデータをランダムで12分割して、2個取り出すということ?# 31>>> X = np.random.randn(12, 2) 32 #ここの意味がわからない。# 33>>> y = np.random.randint(0, 2, 12) 34 #tscvの中の計算式で、3分割して、試験用データのサイズは2.2のサイズは?2個?# 35>>> tscv = TimeSeriesSplit(n_splits=3, test_size=2) 36#それぞれのXとYに指定のデータを挿入する# 37>>> for train_index, test_index in tscv.split(X): 38... print("TRAIN:", train_index, "TEST:", test_index) 39... X_train, X_test = X[train_index], X[test_index] 40... y_train, y_test = y[train_index], y[test_index] 41TRAIN: [0 1 2 3 4 5] TEST: [6 7] 42TRAIN: [0 1 2 3 4 5 6 7] TEST: [8 9] 43TRAIN: [0 1 2 3 4 5 6 7 8 9] TEST: [10 11] 44>>> # Add in a 2 period gap 45>>> tscv = TimeSeriesSplit(n_splits=3, test_size=2, gap=2) 46>>> for train_index, test_index in tscv.split(X): 47... print("TRAIN:", train_index, "TEST:", test_index) 48... X_train, X_test = X[train_index], X[test_index] 49... y_train, y_test = y[train_index], y[test_index] 50TRAIN: [0 1 2 3] TEST: [6 7] 51TRAIN: [0 1 2 3 4 5] TEST: [8 9] 52TRAIN: [0 1 2 3 4 5 6 7] TEST: [10 11]
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html
を一度読むといいと思います
回答1件
あなたの回答
tips
プレビュー