我正在Coursera中学习一门有关python机器学习的课程,我想在R中重现该练习。
因此,基本上,数据集是64x64猫图像。您可以下载完整的数据集 here。并使用以下代码将其装入R中,并带有“ rhdf5”包:
source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")
library(rhdf5)
mydata_train_x <- h5read("./data_in/train_catvnoncat.h5","train_set_x")
我得到的是一个如下数组:
, , 1, 1
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19]
[1,] 17 22 25 25 27 28 30 31 32 34 35 36 35 34 33 33 32 31 30
[2,] 31 33 35 35 36 38 41 43 47 49 50 51 50 49 48 48 47 46 44
[3,] 56 59 62 62 64 67 69 73 76 79 82 82 81 79 79 79 78 76 75
[,20] [,21] [,22] [,23] [,24] [,25] [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36]
[1,] 29 29 27 27 25 23 21 21 21 20 20 19 18 16 14 12 11
[2,] 44 44 44 42 41 40 41 42 41 40 39 39 38 38 37 37 36
[3,] 75 75 74 73 71 72 73 74 74 73 72 72 71 70 69 68 67
[,37] [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50] [,51] [,52] [,53]
[1,] 9 7 7 4 3 2 2 1 1 1 0 1 1 2 0 1 1
[2,] 36 34 35 36 36 34 34 35 34 34 32 30 30 29 29 29 28
[3,] 66 64 66 69 69 65 65 67 67 66 63 61 62 59 59 59 58
[,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62] [,63] [,64]
[1,] 1 1 1 1 1 0 1 1 1 1 1
[2,] 28 28 28 28 25 25 27 28 28 26 22
[3,] 57 57 57 57 55 55 58 58 57 56 51
, , 2, 1
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19]
[1,] 25 28 30 30 31 33 34 35 35 35 36 38 37 36 36 35 34 33 32
[2,] 36 38 40 39 40 41 44 45 47 48 49 51 51 49 48 48 48 46 45
[3,] 62 64
...
所以我要做的是将这些值转换为图像以进行绘制。我有以25为索引的图像图,根据python中的练习,该图必须如下所示(idx 25):
您能帮我获得这个结果吗?
谢谢。