質問編集履歴
3
ライブラリの読み込み、MNISTからのデータのダウンロードや読み込みなどの部分を追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,6 +6,62 @@
|
|
6
6
|
### 該当のソースコード
|
7
7
|
|
8
8
|
```R
|
9
|
+
library(ggplot2)
|
10
|
+
library(dplyr)
|
11
|
+
#install.packages("R.utils")
|
12
|
+
library(R.utils) # unzip()を使う
|
13
|
+
library(gclus)
|
14
|
+
library(MASS)
|
15
|
+
#install.packages("recommenderlab")
|
16
|
+
library("recommenderlab")
|
17
|
+
|
18
|
+
#download data from http://yann.lecun.com/exdb/mnist/
|
19
|
+
#download.file("http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz",
|
20
|
+
# "train-images-idx3-ubyte.gz")
|
21
|
+
#download.file("http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz",
|
22
|
+
# "train-labels-idx1-ubyte.gz")
|
23
|
+
#download.file("http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz",
|
24
|
+
# "t10k-images-idx3-ubyte.gz")
|
25
|
+
#download.file("http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz",
|
26
|
+
# "t10k-labels-idx1-ubyte.gz")
|
27
|
+
|
28
|
+
# gunzip the file
|
29
|
+
#R.utils::gunzip("train-images-idx3-ubyte.gz")
|
30
|
+
#R.utils::gunzip("train-labels-idx1-ubyte.gz")
|
31
|
+
#R.utils::gunzip("t10k-images-idx3-ubyte.gz")
|
32
|
+
#R.utils::gunzip("t10k-labels-idx1-ubyte.gz")
|
33
|
+
|
34
|
+
# load image files
|
35
|
+
load_image_file = function(filename) {
|
36
|
+
ret = list()
|
37
|
+
f = file(filename, 'rb')
|
38
|
+
readBin(f, 'integer', n = 1, size = 4, endian = 'big')
|
39
|
+
n = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
|
40
|
+
nrow = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
|
41
|
+
ncol = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
|
42
|
+
x = readBin(f, 'integer', n = n * nrow * ncol, size = 1, signed = FALSE)
|
43
|
+
close(f)
|
44
|
+
data.frame(matrix(x, ncol = nrow * ncol, byrow = TRUE))
|
45
|
+
}
|
46
|
+
|
47
|
+
# load label files
|
48
|
+
load_label_file = function(filename) {
|
49
|
+
f = file(filename, 'rb')
|
50
|
+
readBin(f, 'integer', n = 1, size = 4, endian = 'big')
|
51
|
+
n = readBin(f, 'integer', n = 1, size = 4, endian = 'big')
|
52
|
+
y = readBin(f, 'integer', n = n, size = 1, signed = FALSE)
|
53
|
+
close(f)
|
54
|
+
y
|
55
|
+
}
|
56
|
+
|
57
|
+
# load images
|
58
|
+
train = load_image_file("train-images-idx3-ubyte")
|
59
|
+
test = load_image_file("t10k-images-idx3-ubyte")
|
60
|
+
|
61
|
+
# load labels
|
62
|
+
train$y = as.factor(load_label_file("train-labels-idx1-ubyte"))
|
63
|
+
test$y = as.factor(load_label_file("t10k-labels-idx1-ubyte"))
|
64
|
+
|
9
65
|
# helper function for visualization
|
10
66
|
show_digit = function(arr784, col = gray(12:1 / 12), ...) {
|
11
67
|
image(matrix(as.matrix(arr784[-785]), nrow = 28)[, 28:1], col = col, ...)
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -111,7 +111,7 @@
|
|
111
111
|
```
|
112
112
|
X <- train[train$y==3||4,][1:100,-785]
|
113
113
|
```
|
114
|
-
と試したりしましたが、う
|
114
|
+
と試したりしましたが、3と4が混ざったような画像が出力されるだけで教師なし分類ができません。
|
115
115
|
|
116
116
|
### 補足情報(FW/ツールのバージョンなど)
|
117
117
|
|
1
誤字訂正
title
CHANGED
File without changes
|
body
CHANGED
@@ -112,6 +112,7 @@
|
|
112
112
|
X <- train[train$y==3||4,][1:100,-785]
|
113
113
|
```
|
114
114
|
と試したりしましたが、うまくいきません。
|
115
|
+
|
115
116
|
### 補足情報(FW/ツールのバージョンなど)
|
116
117
|
|
117
118
|
kaggleのnotepad上のRエディタを使用しています。
|