我的数据集是MNIST来自卡格尔
我正在尝试使用image
函数来可视化训练集中的第一个数字。不幸的是我收到以下错误:
>image(1:28, 1:28, im, col=gray((0:255)/255))
Error in image.default(1:28, 1:28, im, col = gray((0:255)/255)) :
'z' must be numeric or logical
添加一些代码:
rawfile<-read.csv("D://Kaggle//MNIST//train.csv",header=T) #Reading the csv file
im<-matrix((rawfile[1,2:ncol(rawfile)]), nrow=28, ncol=28) #For the 1st Image
image(1:28, 1:28, im, col=gray((0:255)/255))
Error in image.default(1:28, 1:28, im, col = gray((0:255)/255)) :
'z' must be numeric or logical
最佳答案
目前你的即时通讯是一个字符矩阵。您需要将其转换为数字矩阵,例如通过发布 im_numbers <- apply(im, 2, as.numeric)
.
然后您可以发出 image(1:28, 1:28, im_numbers, col=gray((0:255)/255))
.
关于R - 图像绘图 MNIST 数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37953644/