【发布时间】:2020-09-20 12:32:27
【问题描述】:
我正在研究MNIST Sign Language 数据集,以使用Keras 对图像进行分类。数据集中有 24 个不同的类。但问题是类的分布很不一样。
我使用了sklearn.model_selection.train_test_split 到stratify=df['label'],但仍然有一些类有 5%,而另一些有 3% 的全部数据。我怎样才能让他们选择分布在类中的大约 4% 的数据。
我的test_df 有 7172 行和 785 列,其中一个是label 列,其余的784 是灰度像素值(28*28)
test_df = pd.read_csv(TEST_PATH)
# shuffle and split validation,test data
test_df = test_df.sample(frac=1.0,random_state=SEED).iloc[:2000,:] # shuffle the whole data, get first 2000 rows
val_df,test_df = train_test_split(test_df,test_size=0.5,random_state=SEED,stratify=test_df['label'])
# stratify the labels so that distribution of classes is almost same
# extract pixels and labels for both validation,test data
X_val = val_df.drop('label',axis=1).values.reshape((val_df.shape[0],28,28))/255.0 # validation images
y_val = val_df['label'].ravel() # validation label
X_test = test_df.drop('label',axis=1).values.reshape((test_df.shape[0],28,28))/255.0 # test images
y_val = test_df['label'].ravel() # test label
【问题讨论】:
标签: pandas machine-learning keras scikit-learn deep-learning