我的数据集是Kaggle的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/