如何为SVC绘制训练数据和训练目标

在加载图像并提取其关键点之后,我试图通过绘制数据来形象化我的数据。但是,当我尝试将其散布时,在绘制之前,会出现错误,我的x和y值应为相同大小。

这是我从加载自己的数据集得到的结果:

数据:

[[0.06887255 0.06887255 0.06887255 ... 0.08921569 0.08921569 0.08921569]
 [0.06666667 0.06666667 0.06666667 ... 0.08823529 0.08823529 0.08823529]
 [0.07598039 0.07598039 0.07598039 ... 0.08848039 0.08848039 0.08848039]
 ...
 [0.01568627 0.01568627 0.01568627 ... 0.1129902  0.1129902  0.1129902 ]
 [0.01666667 0.01666667 0.01666667 ... 0.1129902  0.1129902  0.1129902 ]
 [0.01666667 0.01666667 0.01666667 ... 0.1129902  0.1129902  0.1129902 ]]

target: [0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4]

复制代码

 import matplotlib.pyplot as plt
 import numpy as np
 import skimage
 import cv2
 from skimage.io import imread
 from skimage.transform import resize

DATADIR = "C:/Dataset"
CATEGORIES = ["class 1", "class 2", "class 3", "class 4", "class 5"]
def load_image_files(fullpath, dimension=(35, 35)):
    descr = "A image classification dataset"
    flat_data = []
    target = []
    images = []
    dimension=(64, 64)
    for category in CATEGORIES:
        path = os.path.join(DATADIR, category)
        for person in os.listdir(path):
            personfolder = os.path.join(path, person)
            for imgname in os.listdir(personfolder):
                class_num = CATEGORIES.index(category)
                fullpath = os.path.join(personfolder, imgname)
                imageList = skimage.io.imread(fullpath)
                orb = cv2.ORB_create(edgeThreshold=1)
                orb = cv2.ORB_create()
                key_points = [cv2.KeyPoint(65, 9, 10), cv2.KeyPoint(66, 40, 10),cv2.KeyPoint(49, 200, 10), cv2.KeyPoint(76, 187, 10), cv2.KeyPoint(139, 188, 10), cv2.KeyPoint(176, 200, 10)]
                kp, des = orb.compute(imageList, key_points)
                kparray = cv2.drawKeypoints(imageList, kp, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
                img_resized = resize(kparray, dimension, anti_aliasing=True, mode='reflect')
                img_resized = img_resized.flatten()

                flat_data.append(img_resized)
                images.append(flat_data)
                target.append(class_num)

    flat_data = np.array(flat_data)
    target = np.array(target)
    images = np.array(images)
    return Bunch(data=flat_data,
                     target=target,
                     target_names=CATEGORIES,
                     images=images,
                     DESCR=descr)

值得注意的是,在每个班级中,都有一个用于John Doe的文件夹,基本上它位于Class 1 / John Doe,Class 2 / John Doe,Class 3 / John Doe,Class 4 / John Doe,Class 5 / John Doe的文件夹中,每个中的任何图像。

Im loading the images like this: image_dataset = load_image_files("C:\Dataset")

然后我尝试简单地散布和绘制:

plt.scatter(image_dataset.data, image_dataset.target)
plt.show()

收到错误消息,指出x和y的大小应相同。

我想知道如何将数据(x值)调整为类值(y值)