划分大数据集 python

dividing big dataset python

我的数据集特征形状是 (80102, 2592) 和 label.shape (80102, 2)。我只想考虑几行进行训练,因为训练 CNN 模型需要花费大量时间。如何在 python 中划分数据集并只考虑几行来进行训练和测试。

如果您的数据是数组形式,则令 X 为包含数据的数组,y 为包含标签的数组。您可以使用 sklearn train_test_split 函数根据以下代码创建新的数据样本

from sklearn.model_selection import train_test_split
percent=.1 specify the percentof data you want to use, in this case 10%
X_data, X_dummy, y_labels, y_dummy=train_test_split(X,y,train_size=percent,randon_state=123, shuffle=True)

X_data 将包含 10% 的原始数据并将被打乱 y_labels 将包含 10% 的相应标签。 如果要专门设置样本数,请将 train_size 设置为整数值。如果您需要更多信息,文档位于 here. If you data is a pandas dataframe you can use the pandas function pandas.DataFrame.sample..Documentation for that is here.。假设您的数据框称为数据。下面的代码将生成一个新的数据框,其中包含原始行的指定百分比

percent=.1
new_data=pandas.data.sample(n=None, frac=percent, replace=False, weights=None, random_state=123, axis=0)