Python Keras,从DataFrameIterator获取相应标签的numpy数组
我和Keras有这个问题, 我的测试集定义如下: 我的测试集 为了很快恢复,我使用Keras的Python Keras,从DataFrameIterator获取相应标签的numpy数组,python,keras,Python,Keras,我和Keras有这个问题, 我的测试集定义如下: 我的测试集 为了很快恢复,我使用Keras的ImageDataGenerator,然后将数据生成器分配给我的测试集 我的数据帧X_test有两列 x_col='image_path' ## The path to my image files y_col='category_id' ## My categorical features - Labels 我需要从测试集中提取y_col中的值,因为 test_set['category_id']
ImageDataGenerator
,然后将数据生成器分配给我的测试集
我的数据帧X_test
有两列
x_col='image_path' ## The path to my image files
y_col='category_id' ## My categorical features - Labels
我需要从测试集中提取y_col中的值,因为
test_set['category_id'] is not in same order neither same shape as X_test['category_id']
X_test['category_id'].shape
(315,)
当我查看测试集类型时,我得到:
type(test_set)
keras_preprocessing.image.dataframe_iterator.DataFrameIterator
原因是:
当我们进行预测时,我们需要在这个“测试集”上进行预测
所以,
当我想显示我的分类报告时,由于格式错误,我不能使用“test\u set”
,也不能使用X\u test['categorical\u id']
,因为真实值的顺序与test\u set不同。
Below an example of classification_report with test_set and the result:
print(classification_report(test_set, predicted,
target_names=df_data['product_cat1'].unique()))
结果我得到一个错误:
ValueError: Found input variables with inconsistent numbers of samples: [10, 315]
记住,我的“X_测试”
形状是:
X_test['category_id'].shape
(315,)
我试图将这个'test\u set'
转换成数组或数据帧的任何东西都不起作用
如果我在我的Classification报告中使用X_测试['category_id']
,它是有效的,但分数是假的
否则,使用Keras进行多类分类很有趣,但毫无用处,如果我们不能确定每个类的准确度和召回分数以及f1_分数准确度模型,我的意思是我们只得到一个全局准确度模型,仅此而已,对竞争有利
欢迎提出任何想法和解决办法。因为它是
测试集
,而且因为您不需要在测试集
上进行训练,所以您不必对其进行洗牌以保持顺序。这样,您将从X_测试['category_id']
中了解标签的顺序(基本事实),并将其用于分类报告
修理
如果您想洗牌测试集
,则可以使用值对其进行种子设定并进行预测。然后使用相同的种子并在数据生成器上迭代并收集标签(地面真相)。使用相同的种子值集,您将获得相同的顺序
ValueError: Found input variables with inconsistent numbers of samples: [10, 315]
X_test['category_id'].shape
(315,)
test_set = test_datagen.flow_from_dataframe(dataframe=X_test,
x_col='image_path',
y_col='category_id',
shuffle=False, ### Do not shuffle
target_size = (64, 64),
batch_size = 32,
class_mode = 'categorical')
y_preds = classifier.predict(test_set)
print(classification_report(test_set, X_test['category_id']))