如何通过裁剪的svhn数据集来适应感知器scikit学习?

问题描述 投票:0回答:1

我必须使用python的scikit-learn libray上的Perceptron对svhn数据集进行分类,但我不了解如何准备数据以使用perceptron的fit方法;数据集是svhn数据集裁剪的图像格式,我必须通过灰度传递图像

python dataset perceptron
1个回答
0
投票

来自数据集的图像是许多(32,32,3)矩阵,而Perceptron将接受一堆数组。

如果数据形状为(n_images,32,32,3),请使用:

Numpy.mean(data, axis=3)

获得灰度图像的数组,然后:

for i in range(n_images):
    X_train[i] = data[i].flatten()

所以您最终得到(n_images,1024)个大小的矩阵。

您还希望将标签放在n_images-size向量中。

然后您设置感知器:

clf = Perceptron()
clf.fit(X_train, y)
© www.soinside.com 2019 - 2024. All rights reserved.