【发布时间】:2018-06-08 03:31:35
【问题描述】:
首先,我对 1000x20 数组中的数值数据进行了标准化,然后创建了另一个数组,其中包含标准化数据行索引的随机排列。如何将这个新数组拆分为训练、交叉验证和测试集?
In[150]:
row_indices = np.random.permutation(X_norm.shape[0])
In[151]:
# Create a Training Set - 60 percent of data - 600x20
X_train =
# Create a Cross Validation Set - 20 percent - 200x20
X_crossVal =
# Create a Test Set - 20 percent - 200x20
X_test =
# If you performed the above calculations correctly, then X_train
# should have 600 rows and 20 columns, X_crossVal should have 200 rows
# and 20 columns, and X_test should have 200 rows and 20 columns. You
# can verify this by filling the code below:
In[152]:
# Print the shape of X_train
X_train.shape
# Print the shape of X_crossVal
# Print the shape of X_test
请原谅我在堆栈溢出方面有多糟糕。
【问题讨论】:
-
这是作业吗?您需要拆分洗牌的索引,然后使用每个拆分从
X_norm中选择行...例如拆分后做X_norm[train_indices] -
你可以使用其他库吗?如果是,那么scikit-learn's train_test_split 会非常好用。
标签: numpy partitioning cross-validation indices numpy-ndarray