我有一个数据集“Digit”。该数据集包含 1797 张小图像(8x8 像素),每张图像都包含一个手写数字(0-9)。每个图像被视为以像素为特征的数据样本。因此,要构建特征表,您必须将每个 8x8 图像转换为一行特征矩阵,其中 64 个特征列代表 64 个像素。如何为其构建特征矩阵和标签向量???
最佳答案
您可以按照有关监督学习的 scikit-learn 教程进行操作,其中他们使用的是 Digit 数据集
http://scikit-learn.org/stable/tutorial/basic/tutorial.html#loading-an-example-dataset
更多详细信息here 。如果按照示例加载数据集,则可以简单地 reshape 图像:
from sklearn import datasets
digits = datasets.load_digits()
# To apply a classifier on this data, we need to flatten the image, to
# turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))
这使得 data
成为一个 2D 矩阵,具有 n_samples
行和任意数量的列,以适应扁平图像。
关于python - 构建特征矩阵和标签向量:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47425356/