質問編集履歴

3

ライブラリの読み込み、MNISTからのデータのダウンロードや読み込みなどの部分を追加しました。

2019/11/21 07:36

投稿

emoemo
emoemo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -14,6 +14,118 @@
14
14
 
15
15
  ```R
16
16
 
17
+ library(ggplot2)
18
+
19
+ library(dplyr)
20
+
21
+ #install.packages("R.utils")
22
+
23
+ library(R.utils) # unzip()を使う
24
+
25
+ library(gclus)
26
+
27
+ library(MASS)
28
+
29
+ #install.packages("recommenderlab")
30
+
31
+ library("recommenderlab")
32
+
33
+
34
+
35
+ #download data from http://yann.lecun.com/exdb/mnist/
36
+
37
+ #download.file("http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz",
38
+
39
+ # "train-images-idx3-ubyte.gz")
40
+
41
+ #download.file("http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz",
42
+
43
+ # "train-labels-idx1-ubyte.gz")
44
+
45
+ #download.file("http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz",
46
+
47
+ # "t10k-images-idx3-ubyte.gz")
48
+
49
+ #download.file("http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz",
50
+
51
+ # "t10k-labels-idx1-ubyte.gz")
52
+
53
+
54
+
55
+ # gunzip the file
56
+
57
+ #R.utils::gunzip("train-images-idx3-ubyte.gz")
58
+
59
+ #R.utils::gunzip("train-labels-idx1-ubyte.gz")
60
+
61
+ #R.utils::gunzip("t10k-images-idx3-ubyte.gz")
62
+
63
+ #R.utils::gunzip("t10k-labels-idx1-ubyte.gz")
64
+
65
+
66
+
67
+ # load image files
68
+
69
+ load_image_file = function(filename) {
70
+
71
+ ret = list()
72
+
73
+ f = file(filename, 'rb')
74
+
75
+ readBin(f, 'integer', n = 1, size = 4, endian = 'big')
76
+
77
+ n = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
78
+
79
+ nrow = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
80
+
81
+ ncol = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
82
+
83
+ x = readBin(f, 'integer', n = n * nrow * ncol, size = 1, signed = FALSE)
84
+
85
+ close(f)
86
+
87
+ data.frame(matrix(x, ncol = nrow * ncol, byrow = TRUE))
88
+
89
+ }
90
+
91
+
92
+
93
+ # load label files
94
+
95
+ load_label_file = function(filename) {
96
+
97
+ f = file(filename, 'rb')
98
+
99
+ readBin(f, 'integer', n = 1, size = 4, endian = 'big')
100
+
101
+ n = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
102
+
103
+ y = readBin(f, 'integer', n = n, size = 1, signed = FALSE)
104
+
105
+ close(f)
106
+
107
+ y
108
+
109
+ }
110
+
111
+
112
+
113
+ # load images
114
+
115
+ train = load_image_file("train-images-idx3-ubyte")
116
+
117
+ test = load_image_file("t10k-images-idx3-ubyte")
118
+
119
+
120
+
121
+ # load labels
122
+
123
+ train$y = as.factor(load_label_file("train-labels-idx1-ubyte"))
124
+
125
+ test$y = as.factor(load_label_file("t10k-labels-idx1-ubyte"))
126
+
127
+
128
+
17
129
  # helper function for visualization
18
130
 
19
131
  show_digit = function(arr784, col = gray(12:1 / 12), ...) {

2

2019/11/21 07:36

投稿

emoemo
emoemo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -224,7 +224,7 @@
224
224
 
225
225
  ```
226
226
 
227
- と試したりしましたが、うまくいきません。
227
+ と試したりしましたが、3と4が混ざったよな画像が出力されるだけで教師なし分類ができません。
228
228
 
229
229
 
230
230
 

1

誤字訂正

2019/11/19 03:40

投稿

emoemo
emoemo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -226,6 +226,8 @@
226
226
 
227
227
  と試したりしましたが、うまくいきません。
228
228
 
229
+
230
+
229
231
  ### 補足情報(FW/ツールのバージョンなど)
230
232
 
231
233