請問用python跟tensorflow還有CNN,要如何對一維的數據做資料切割(分train(70%),validation(10%),test(20%))?
查了很多資料還是不會.....
假設你的資料的變數名稱叫做data
#計算資料大小
total_cnt = len(data)
#8:2切割
train_cnt = int(total_cnt*0.8)
test_cnt = total_cnt - train_cnt
#創建訓練資料
trainset = data[:train_cnt]
testset = data[test_cnt:]
sklearn 的 train_test_split切割,一維/二維均可。validation再從train切一次即可。
一維:
import numpy as np
from sklearn.model_selection import train_test_split
X, y = np.arange(10), range(10)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33)
X_train, X_test, y_train, y_test
二維:
import numpy as np
from sklearn.model_selection import train_test_split
X, y = np.arange(10).reshape((5, 2)), range(5)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33)
X_train, X_test, y_train, y_test